1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-03 07:56:42 -05:00
This commit is contained in:
Darien Raymond 2017-04-19 16:29:36 +02:00
parent a624e50ffe
commit 0ebebfa458
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 10 additions and 11 deletions

View File

@ -148,11 +148,9 @@ func fetchInput(ctx context.Context, s *Session, output buf.Writer) {
log.Trace(newError("dispatching request to ", dest)) log.Trace(newError("dispatching request to ", dest))
data, _ := s.input.ReadTimeout(time.Millisecond * 500) data, _ := s.input.ReadTimeout(time.Millisecond * 500)
if data != nil { if err := writer.Write(data); err != nil {
if err := writer.Write(data); err != nil { log.Trace(newError("failed to write first payload").Base(err))
log.Trace(newError("failed to write first payload").Base(err)) return
return
}
} }
if err := buf.Copy(signal.BackgroundTimer(), s.input, writer); err != nil { if err := buf.Copy(signal.BackgroundTimer(), s.input, writer); err != nil {
log.Trace(newError("failed to fetch all input").Base(err)) log.Trace(newError("failed to fetch all input").Base(err))

View File

@ -38,19 +38,18 @@ func (r *Reader) ReadMetadata() (*FrameMetadata, error) {
} }
func (r *Reader) Read() (buf.MultiBuffer, error) { func (r *Reader) Read() (buf.MultiBuffer, error) {
r.buffer.Clear() if err := r.buffer.Reset(buf.ReadFullFrom(r.reader, 2)); err != nil {
if err := r.buffer.AppendSupplier(buf.ReadFullFrom(r.reader, 2)); err != nil {
return nil, err return nil, err
} }
dataLen := int(serial.BytesToUint16(r.buffer.Bytes())) dataLen := int(serial.BytesToUint16(r.buffer.Bytes()))
mb := buf.NewMultiBuffer() mb := buf.NewMultiBuffer()
for dataLen > 0 { for dataLen > 0 {
b := buf.New()
readLen := buf.Size readLen := buf.Size
if dataLen < readLen { if dataLen < readLen {
readLen = dataLen readLen = dataLen
} }
b := buf.New()
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, readLen)); err != nil { if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, readLen)); err != nil {
mb.Release() mb.Release()
return nil, err return nil, err

View File

@ -77,8 +77,8 @@ func (b *Buffer) Bytes() []byte {
// Reset resets the content of the Buffer with a supplier. // Reset resets the content of the Buffer with a supplier.
func (b *Buffer) Reset(writer Supplier) error { func (b *Buffer) Reset(writer Supplier) error {
b.start = 0 b.start = 0
nBytes, err := writer(b.v[b.start:]) nBytes, err := writer(b.v)
b.end = b.start + nBytes b.end = nBytes
return err return err
} }

View File

@ -76,7 +76,9 @@ func (r *bufferToBytesReader) writeToInternal(writer io.Writer) (int64, error) {
mbWriter := NewWriter(writer) mbWriter := NewWriter(writer)
totalBytes := int64(0) totalBytes := int64(0)
if r.leftOver != nil { if r.leftOver != nil {
mbWriter.Write(r.leftOver) if err := mbWriter.Write(r.leftOver); err != nil {
return 0, err
}
totalBytes += int64(r.leftOver.Len()) totalBytes += int64(r.leftOver.Len())
} }