Skip to content

Commit

Permalink
chore: fix a few conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Apr 17, 2024
1 parent 0bf879b commit d386d1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,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 {

Check warning on line 399 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L399

Added line #L399 was not covered by tests
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen >= n {
if inBufferLen == n {

Check warning on line 405 in connection_unix.go

View check run for this annotation

Codecov / codecov/patch

connection_unix.go#L405

Added line #L405 was not covered by tests
return c.loop.cache.Bytes(), err
}

Expand Down Expand Up @@ -435,13 +435,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
2 changes: 1 addition & 1 deletion pkg/buffer/elastic/elastic_ring_list_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (mb *Buffer) Peek(n int) ([][]byte, error) {
return nil, io.ErrShortBuffer
}
head, tail := mb.ringBuffer.Peek(n)
if mb.ringBuffer.Buffered() >= n {
if mb.ringBuffer.Buffered() == n {
return [][]byte{head, tail}, nil
}
return mb.listBuffer.PeekWithBytes(n, head, tail)
Expand Down

0 comments on commit d386d1f

Please sign in to comment.