Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 0 additions & 28 deletions pkg/lwip/contrib/sock/udp/lwip_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,6 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep)
0)) ? -ENOTCONN : 0;
}

ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
{
void *pkt = NULL;
void *ctx = NULL;
uint8_t *ptr = data;
ssize_t res, ret = 0;
bool nobufs = false;

assert((sock != NULL) && (data != NULL) && (max_len > 0));
while ((res = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout,
remote, aux)) > 0) {
struct netbuf *buf = ctx;
if (buf->p->tot_len > (ssize_t)max_len) {
nobufs = true;
/* progress context to last element */
while (netbuf_next(ctx) == 0) {}
continue;
}
memcpy(ptr, pkt, res);
ptr += res;
ret += res;
}

return (nobufs) ? -ENOBUFS : ((res < 0) ? res : ret);
}

ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **ctx,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
Expand Down
34 changes: 0 additions & 34 deletions pkg/openwsn/sock/openwsn_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,40 +377,6 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep)
return 0;
}

ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
{
void *pkt = NULL, *ctx = NULL;
ssize_t res;

assert((sock != NULL) && (data != NULL) && (max_len > 0));
res = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote, aux);
/* set data to copy, check if enough buffer space */
if (res >= 0) {
ssize_t tmp;
if ((ssize_t)max_len >= res) {
memset(data, 0, max_len);
if (res > 0) {
/* copy received data */
memcpy(data, pkt, res);
/* free packet */
tmp = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote,
aux);
assert(tmp == 0);
}
(void) tmp;
}
else {
res = -ENOBUFS;
/* free packet */
tmp = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote, aux);
assert(tmp == 0);
}
}
return res;
}

ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
Expand Down
1 change: 1 addition & 0 deletions sys/include/net/sock/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep);
* @return -ENOBUFS, if buffer space is not large enough to store received
* data.
* @return -ENOMEM, if no memory was available to receive @p data.
* The first @p max_len bytes of the packet are stored in @p data.
* @return -EPROTO, if source address of received packet did not equal
* the remote of @p sock.
* @return -ETIMEDOUT, if @p timeout expired.
Expand Down
23 changes: 0 additions & 23 deletions sys/net/gnrc/sock/udp/gnrc_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,6 @@ int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *remote)
return 0;
}

ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
{
void *pkt = NULL, *ctx = NULL;
uint8_t *ptr = data;
ssize_t res, ret = 0;
bool nobufs = false;

assert((sock != NULL) && (data != NULL) && (max_len > 0));
while ((res = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote,
aux)) > 0) {
if (res > (ssize_t)max_len) {
nobufs = true;
continue;
}
memcpy(ptr, pkt, res);
ptr += res;
ret += res;
}
return (nobufs) ? -ENOBUFS : ((res < 0) ? res : ret);
}

static bool _accept_remote(const sock_udp_t *sock, const udp_hdr_t *hdr,
const sock_ip_ep_t *remote)
{
Expand Down
26 changes: 26 additions & 0 deletions sys/net/sock/sock_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,29 @@ int sock_dtls_establish_session(sock_udp_t *sock_udp, sock_dtls_t *sock_dtls,
return res;
}
#endif

#if defined(MODULE_SOCK_UDP)
ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_udp_ep_t *remote,
sock_udp_aux_rx_t *aux)
{
void *pkt = NULL, *ctx = NULL;
uint8_t *ptr = data;
ssize_t res, ret = 0;
bool nobufs = false;

assert((sock != NULL) && (data != NULL) && (max_len > 0));
while ((res = sock_udp_recv_buf_aux(sock, &pkt, &ctx, timeout, remote,
aux)) > 0) {
if (res > (ssize_t)max_len) {
nobufs = true;
res = max_len;
}
memcpy(ptr, pkt, res);
ptr += res;
ret += res;
max_len -= res;
}
return (nobufs) ? -ENOBUFS : ((res < 0) ? res : ret);
}
#endif