mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-09 02:46:35 -05:00
read size to multi buffer
This commit is contained in:
parent
5af3580bcf
commit
03512a6a9b
@ -30,6 +30,26 @@ func ReadAllToMultiBuffer(reader io.Reader) (MultiBuffer, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// ReadSizeToMultiBuffer reads specific number of bytes from reader into a MultiBuffer.
|
||||
func ReadSizeToMultiBuffer(reader io.Reader, size int32) (MultiBuffer, error) {
|
||||
mb := NewMultiBufferCap(32)
|
||||
|
||||
for size > 0 {
|
||||
bSize := size
|
||||
if bSize > Size {
|
||||
bSize = Size
|
||||
}
|
||||
b := NewSize(uint32(bSize))
|
||||
if err := b.Reset(ReadFullFrom(reader, int(bSize))); err != nil {
|
||||
mb.Release()
|
||||
return nil, err
|
||||
}
|
||||
size -= bSize
|
||||
mb.Append(b)
|
||||
}
|
||||
return mb, nil
|
||||
}
|
||||
|
||||
// ReadAllToBytes reads all content from the reader into a byte array, until EOF.
|
||||
func ReadAllToBytes(reader io.Reader) ([]byte, error) {
|
||||
mb, err := ReadAllToMultiBuffer(reader)
|
||||
|
@ -173,11 +173,11 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
|
||||
}
|
||||
|
||||
if reader.Buffered() > 0 {
|
||||
payload := buf.NewSize(uint32(reader.Buffered()))
|
||||
common.Must(payload.Reset(func(b []byte) (int, error) {
|
||||
return reader.Read(b[:reader.Buffered()])
|
||||
}))
|
||||
if err := ray.InboundInput().WriteMultiBuffer(buf.NewMultiBufferValue(payload)); err != nil {
|
||||
payload, err := buf.ReadSizeToMultiBuffer(reader, int32(reader.Buffered()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ray.InboundInput().WriteMultiBuffer(payload); err != nil {
|
||||
return err
|
||||
}
|
||||
reader = nil
|
||||
|
Loading…
Reference in New Issue
Block a user