Skip to content

Conversation

@astro
Copy link
Contributor

@astro astro commented Apr 9, 2018

I've studied the code for a while and wondered why there is a check for capacity > 0 at this location. capacity doesn't change. I believe self.length was actually intended here.

In the RawSocket use by #186 that's needed otherwise PacketBuffer tends to get a stuck payload_ring (length=0 but read_at near capacity).

@astro astro mentioned this pull request Apr 9, 2018
Copy link
Collaborator

@dlrobertson dlrobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of the check for capacity > 0 was to ensure we didn't cause a divide by zero when a zero size buffer was given (which often occurs in tests). Why were the test strings changed?

@astro
Copy link
Contributor Author

astro commented Apr 10, 2018

The test strings were changed to make the CI pass.

I didn't encounter any division by zero errors. Should I try to solve my problem in a different way?

@whitequark
Copy link
Contributor

whitequark commented Apr 10, 2018 via email

@astro
Copy link
Contributor Author

astro commented Apr 10, 2018

I'm not 100% certain that this is the right approach. With the optimization, the buffer will be rewritten from start if it was empty after the previous dequeue_many_with(), hence the spec changes.

@whitequark
Copy link
Contributor

It seems we have two separate things at work here:

  1. A possible bug: "I've studied the code for a while and wondered why there is a check for capacity > 0 at this location. capacity doesn't change. I believe self.length was actually intended here."
  2. An optimization (?): "In the RawSocket use by DHCPv4 client #186 that's needed otherwise PacketBuffer tends to get a stuck payload_ring (length=0 but read_at near capacity)."

@astro, can you please provide separate test cases for (1) and (2)? If the check is genuinely dead, then let's first remove it, and then separately examine the optimization (2); I don't fully understand why it is necessary yet.

@astro
Copy link
Contributor Author

astro commented Apr 12, 2018

Ok, I reordered this PR with the updated tests first and had CI trigger on them.

Now I've put the optimization into enqueue_many_with() which is the method that benefits from this. Subsequently I had to fundamentally touch test_buffer_wraparound_tx() to trigger the intended check.

@astro astro changed the title Make the RingBuffer contiguous memory optimization work. RingBuffer contiguous memory optimization Apr 13, 2018
@astro astro mentioned this pull request Apr 19, 2018
Copy link
Contributor

@whitequark whitequark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change looks good to me but the change to the TCP test_buffer_wraparound_tx seems wrong.

assert_eq!(s.send_slice(b"abc"), Ok(3));
s.tx_buffer = SocketBuffer::new(vec![b'.'; 9]);
assert_eq!(s.tx_buffer.enqueue_many(6).len(), 6);
assert_eq!(s.tx_buffer.dequeue_many(3).len(), 3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you manipulating the buffer directly in this test and not via the socket API? This defeats the purpose of testing the socket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is just preparing the buffer. Anyway, fixed it.

astro added 5 commits April 23, 2018 22:37
… instead of comparing the buffer.

Fixtures have been shortened to work with the outstanding contiguous
buffer optimization.
This is still testing the same case which would be masked away by the
upcoming contiguous space optimization (which is important for
PacketBuffers and still helpful to TcpSockets).
assert_eq!(s.send_slice(b"abc"), Ok(3));
s.tx_buffer = SocketBuffer::new(vec![b'.'; 9]);
assert_eq!(s.send_slice(b"xxxyyy"), Ok(6));
assert_eq!(s.tx_buffer.dequeue_many(3), &b"xxx"[..]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not any better...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why touch the internal tx_buffer you ask? The read_at pointer must be initialized so that the check still makes sense when the optimization is merged.

@whitequark whitequark merged commit 908ef8d into smoltcp-rs:master May 24, 2018
@whitequark
Copy link
Contributor

@astro Thanks, and sorry for taking so much time to merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants