1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -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))
data, _ := s.input.ReadTimeout(time.Millisecond * 500)
if data != nil {
if err := writer.Write(data); err != nil {
log.Trace(newError("failed to write first payload").Base(err))
return
}
if err := writer.Write(data); err != nil {
log.Trace(newError("failed to write first payload").Base(err))
return
}
if err := buf.Copy(signal.BackgroundTimer(), s.input, writer); err != nil {
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) {
r.buffer.Clear()
if err := r.buffer.AppendSupplier(buf.ReadFullFrom(r.reader, 2)); err != nil {
if err := r.buffer.Reset(buf.ReadFullFrom(r.reader, 2)); err != nil {
return nil, err
}
dataLen := int(serial.BytesToUint16(r.buffer.Bytes()))
mb := buf.NewMultiBuffer()
for dataLen > 0 {
b := buf.New()
readLen := buf.Size
if dataLen < readLen {
readLen = dataLen
}
b := buf.New()
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, readLen)); err != nil {
mb.Release()
return nil, err

View File

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

View File

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