Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in Bytes() #2

Merged
merged 1 commit into from Mar 31, 2020
Merged

Fix a bug in Bytes() #2

merged 1 commit into from Mar 31, 2020

Conversation

panjf2000
Copy link
Contributor

@panjf2000 panjf2000 commented Mar 31, 2020

调用 ringbuffer.Bytes() 的时候,如果 buffer 是满的,也就是 r.w == r.r,copy r.buf 的顺序不应该是 0 -> r.size,因为 r.r 和 r.w 此时未必等于 0,所以 copy 的范围应该是先 r.r -> r.size,然后 0 -> r.w,否则的话返回的数据的顺序是乱的。

@panjf2000
Copy link
Contributor Author

验证通过:

=== RUN   TestRingBuffer_interface
--- PASS: TestRingBuffer_interface (0.00s)
=== RUN   TestRingBuffer_Write
--- PASS: TestRingBuffer_Write (0.00s)
=== RUN   TestRingBuffer_Read
--- PASS: TestRingBuffer_Read (0.00s)
=== RUN   TestRingBuffer_ByteInterface
--- PASS: TestRingBuffer_ByteInterface (0.00s)
=== RUN   ExampleRingBuffer
--- PASS: ExampleRingBuffer (0.00s)
PASS
ok  	github.com/panjf2000/ringbuffer	0.008s

@smallnest smallnest merged commit 3a38e80 into smallnest:master Mar 31, 2020
@panjf2000 panjf2000 deleted the patch-1 branch March 31, 2020 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants