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

sys/posix/socket: implement MSG_PEEK for recvfrom #16850

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! check assertion for second chunk
  • Loading branch information
HendrikVE committed May 30, 2023
commit 9dd2aa09e9629ba606bca598c999d2d5c827b168
12 changes: 12 additions & 0 deletions pkg/lwip/contrib/sock/ip/lwip_sock_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,21 @@ ssize_t sock_ip_recv_aux(sock_ip_t *sock, void *data, size_t max_len,
}

assert((sock != NULL) && (data != NULL) && (max_len > 0));
const void *old_ctx = ctx;
while ((res = sock_ip_recv_buf_aux(sock, &pkt, (void **)&ctx, timeout,
remote, aux)) > 0) {

/* sock_udp_recv_buf() is supposed to return multiple packet fragments
* when called multiple times with the same context.
* In practise, this is not implemented and it will always return a pointer
* to the whole packet on the first call and NULL on the second call, which
* releases the packet.
* This assertion will trigger should the behavior change in the future.
*/
if (old_ctx) {
assert(res == 0 && ctx == NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

args so @miri64 pointed out that it's actually LWIP that makes use of that and that comment is wrong 😬

}

if (peek) {
/* SOCK_AUX_PEEK was unset in previous call of sock_ip_recv_buf_aux */
aux->flags |= SOCK_AUX_PEEK;
Expand Down
12 changes: 12 additions & 0 deletions pkg/lwip/contrib/sock/udp/lwip_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,21 @@ ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
}

assert((sock != NULL) && (data != NULL) && (max_len > 0));
const void *old_ctx = ctx;
while ((res = sock_udp_recv_buf_aux(sock, &pkt, (void**)&ctx, timeout,
remote, aux)) > 0) {

/* sock_udp_recv_buf() is supposed to return multiple packet fragments
* when called multiple times with the same context.
* In practise, this is not implemented and it will always return a pointer
* to the whole packet on the first call and NULL on the second call, which
* releases the packet.
* This assertion will trigger should the behavior change in the future.
*/
if (old_ctx) {
assert(res == 0 && ctx == NULL);
}

if (peek) {
/* SOCK_AUX_PEEK was unset in previous call of sock_udp_recv_buf_aux */
aux->flags |= SOCK_AUX_PEEK;
Expand Down