From f7abe353df088e958949f7dd2b405671dcff80bc Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 3 Nov 2019 17:37:44 +0800 Subject: [PATCH] fix ReadBuffer() --- common/buf/reader.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/common/buf/reader.go b/common/buf/reader.go index d28316545..8e09c5b14 100644 --- a/common/buf/reader.go +++ b/common/buf/reader.go @@ -24,20 +24,14 @@ func readOneUDP(r io.Reader) (*Buffer, error) { return nil, newError("Reader returns too many empty payloads.") } -// ReadBuffer reads a Buffer from the given reader, without allocating large buffer in advance. +// ReadBuffer reads a Buffer from the given reader. func ReadBuffer(r io.Reader) (*Buffer, error) { - // Use an one-byte buffer to wait for incoming payload. - var firstByte [1]byte - nBytes, err := r.Read(firstByte[:]) + b := New() + _, err := b.ReadFrom(r) if err != nil { + b.Release() return nil, err } - - b := New() - if nBytes > 0 { - common.Must(b.WriteByte(firstByte[0])) - } - b.ReadFrom(r) return b, nil }