diff --git a/connection_unix.go b/connection_unix.go index cfce3a928..3ccac4ab1 100644 --- a/connection_unix.go +++ b/connection_unix.go @@ -325,11 +325,11 @@ func (c *conn) Next(n int) (buf []byte, err error) { } head, tail := c.inboundBuffer.Peek(n) defer c.inboundBuffer.Discard(n) //nolint:errcheck - if len(head) >= n { - return head[:n], err - } c.loop.cache.Reset() c.loop.cache.Write(head) + if len(head) >= n { + return c.loop.cache.Bytes(), err + } c.loop.cache.Write(tail) if inBufferLen >= n { return c.loop.cache.Bytes(), err diff --git a/connection_windows.go b/connection_windows.go index b32675002..745028434 100644 --- a/connection_windows.go +++ b/connection_windows.go @@ -164,11 +164,11 @@ func (c *conn) Next(n int) (buf []byte, err error) { } head, tail := c.inboundBuffer.Peek(n) defer c.inboundBuffer.Discard(n) //nolint:errcheck - if len(head) >= n { - return head[:n], err - } c.loop.cache.Reset() c.loop.cache.Write(head) + if len(head) >= n { + return c.loop.cache.Bytes(), err + } c.loop.cache.Write(tail) if inBufferLen >= n { return c.loop.cache.Bytes(), err