Skip to content

Commit

Permalink
bug: fix Conn.Next and Conn.Peek panic on Unix (#616)
Browse files Browse the repository at this point in the history
Co-authored-by: wangjian <wangjian@test.com>
  • Loading branch information
serious-snow and wangjian committed Jun 22, 2024
1 parent 5346527 commit 36df9ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ 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 {
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen == n {
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
}

Expand All @@ -352,13 +352,13 @@ func (c *conn) Peek(n int) (buf []byte, err error) {
return c.buffer[:n], err
}
head, tail := c.inboundBuffer.Peek(n)
if len(head) == n {
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen == n {
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
}

Expand Down

0 comments on commit 36df9ef

Please sign in to comment.