Skip to content

Commit

Permalink
chore: improve the length check for conn.Discard
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Nov 16, 2024
1 parent adcbdd2 commit b610595
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,9 @@ func (c *conn) Discard(n int) (int, error) {
}

inBufferLen := c.inboundBuffer.Buffered()
tempBufferLen := len(c.buffer)
if inBufferLen+tempBufferLen < n || n <= 0 {
if totalLen := inBufferLen + len(c.buffer); n >= totalLen || n <= 0 {
c.resetBuffer()
return inBufferLen + tempBufferLen, nil
return totalLen, nil
}

if c.inboundBuffer.IsEmpty() {
Expand Down

0 comments on commit b610595

Please sign in to comment.