Skip to content

Commit

Permalink
bug: fix the issue of discarding bytes in buffer mistakenly in Conn.R…
Browse files Browse the repository at this point in the history
…ead()

Fixes #355
  • Loading branch information
panjf2000 committed Apr 15, 2022
1 parent 4195bd1 commit 0282025
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,13 @@ func (c *conn) Read(p []byte) (n int, err error) {
return n, nil
}
n, _ = c.inboundBuffer.Read(p)
n += copy(p[n:], c.buffer)
return c.Discard(n)
if n == len(p) {
return
}
m := copy(p[n:], c.buffer)
n += m
c.buffer = c.buffer[m:]
return
}

func (c *conn) Next(n int) (buf []byte, err error) {
Expand Down

0 comments on commit 0282025

Please sign in to comment.