From 0ebebfa458cf2880589d5033f17491c2cc36e2eb Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 19 Apr 2017 16:29:36 +0200 Subject: [PATCH] cleanup --- app/proxyman/mux/mux.go | 8 +++----- app/proxyman/mux/reader.go | 5 ++--- common/buf/buffer.go | 4 ++-- common/buf/reader.go | 4 +++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index 517fd0d3e..393c12de6 100644 --- a/app/proxyman/mux/mux.go +++ b/app/proxyman/mux/mux.go @@ -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)) diff --git a/app/proxyman/mux/reader.go b/app/proxyman/mux/reader.go index bc1c5d860..8cede0a2b 100644 --- a/app/proxyman/mux/reader.go +++ b/app/proxyman/mux/reader.go @@ -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 diff --git a/common/buf/buffer.go b/common/buf/buffer.go index 52516e847..afc86eb82 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -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 } diff --git a/common/buf/reader.go b/common/buf/reader.go index 6e0fed65e..eed0018bd 100644 --- a/common/buf/reader.go +++ b/common/buf/reader.go @@ -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()) }