-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sock: amend with zero-copy receive functions #13616
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
Conversation
@kaspar030 ping? |
I suppose you want to make sure the API is sound before adding the implementation? |
Not just sound, but also under rough consensus. Also, since it is not just "the implementation" but several, I think its best to put those in separate PRs as we usually do with |
From a first glance the parameters look fine. |
Why? Asynchronous receive is just one use case for which these functions are needed for (see use-cases above). Also, the name should rather reflect the functionality (provide the buffer with the receive), not the use case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Ok, I see some difficulty: As is, the application might not free the buffer. That means the stack is forced to allocate this somewhere where it is not blocking the rest of the stack, or block itself until the buffer is freed. In gnrc, everything is allocated anyways, so this makes sense and removes the need for another copy of the payload. In a hypothetical single-RX-buffer stack, this is more difficult. It would probably move the allocation to within the stack. Would it make sense to limit this to sock_async, and make the returned buffer only valid within the async callback? That would also simplify the API, as |
I don't think so. As the event handling for |
Then for those stacks zero-copy would not be possible? |
This would be faulty usage anyway. |
Well, not freeing at all would probably be faulty. But freeing at an arbitrary time would be valid, as proposed. |
True. Ok, let's go with it. |
I think in the very limited stacks that fit only one packet, it is acceptable to just consider the RX buffer full as long as the application blocks it. The alternative is to have full memory, which has the same effect in practice (dropped packets). |
ACK from my side, but I think @leandrolanzieri has a point. |
BTW in case anybody is wondering, why there is no TCP equivalent: As TCP needs a buffer to fill anyway, I think it makes little sense to provide this functionality for this protocol. |
a471343
to
1454e60
Compare
Addressed @leandrolanzieri and squashed directly. I also piggy-backed some long overdue doc fixes ;-). |
1454e60
to
50d3ac2
Compare
Oops, removed wrong error doc and forgot to remove it for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Last build passed. Since then only doc was changed. There are only function declarations introduced here, but no implementations. So I think we can skip the compile tests. |
This change amends the `sock` API by a set of functions to `sock` that allow provisioning of stack-internal buffers to the caller on receive. This allows to cover two use-cases 1. Zero-copy systems: if the stacks supported the buffer space provided by these functions can be the same that was filled in the link-layer 2. asynchronous receive within a wrapping sock layer (e.g. `sock_dtls` wrapping `sock_udp`): to receive packets of the lower level protocol asynchronously, the wrapping implementation layer would currently need to allocate its own buffer space, introducing a third buffer space in addition to the one of the application and the network stack. For a wrapping layer this is undesirable. While there are security considerations exposing stack internal memory space to the caller, I believe they are minor, as in the end the application developer is the person in control of the node.
50d3ac2
to
2ed7a73
Compare
Found yet another doc error and squashed directly |
Travis succeeded, but it isn't showed in GitHub somehow. Let's merge this so I can go ahead with the implementation part. |
Contribution description
This change amends the
sock
API by a set of functions tosock
that allow provisioning of stack-internal buffers to the caller on receive.This allows to cover two use-cases:
sock_dtls
wrappingsock_udp
): to receive packets of the lower level protocol asynchronously, the wrapping implementation layer would currently need to allocate its own buffer space, introducing a third buffer space in addition to the one of the application and the network stack. For a wrapping layer this is undesirable.While there are security considerations exposing stack internal memory space to the caller, I believe they are minor, as in the end the application developer is the person in control of the node.
This change only amends the
sock
API and does not change it, so even though it is an API change, it should only require one ACK.Testing procedure
Only API amendments here, no functional implementation (yet). So just check if
succeeds. All
sock
tests should still compile (Murdock can do that).Issues/PRs references
See #12907 (comment)