Skip to content

Commit

Permalink
gnrc_sock: adapt for *_recv_buf() API change
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 1, 2020
1 parent 58685af commit d934579
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
7 changes: 0 additions & 7 deletions sys/net/gnrc/sock/gnrc_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ static void _callback_put(void *arg)
}
#endif

void sock_recv_buf_free(void *buf_ctx)
{
if (buf_ctx) {
gnrc_pktbuf_release(buf_ctx);
}
}

#ifdef SOCK_HAS_ASYNC
static void _netapi_cb(uint16_t cmd, gnrc_pktsnip_t *pkt, void *ctx)
{
Expand Down
25 changes: 16 additions & 9 deletions sys/net/gnrc/sock/ip/gnrc_sock_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,21 @@ ssize_t sock_ip_recv(sock_ip_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_ip_ep_t *remote)
{
void *pkt = NULL, *ctx = NULL;
ssize_t res;
uint8_t *ptr = data;
ssize_t res, ret = 0;
bool nobufs = false;

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

ssize_t sock_ip_recv_buf(sock_ip_t *sock, void **data, void **buf_ctx,
Expand All @@ -114,6 +115,12 @@ ssize_t sock_ip_recv_buf(sock_ip_t *sock, void **data, void **buf_ctx,
int res;

assert((sock != NULL) && (data != NULL) && (buf_ctx != NULL));
if (*buf_ctx != NULL) {
*data = NULL;
gnrc_pktbuf_release(*buf_ctx);
*buf_ctx = NULL;
return 0;
}
if (sock->local.family == 0) {
return -EADDRNOTAVAIL;
}
Expand Down
25 changes: 16 additions & 9 deletions sys/net/gnrc/sock/udp/gnrc_sock_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,21 @@ ssize_t sock_udp_recv(sock_udp_t *sock, void *data, size_t max_len,
uint32_t timeout, sock_udp_ep_t *remote)
{
void *pkt = NULL, *ctx = NULL;
ssize_t res;
uint8_t *ptr = data;
ssize_t res, ret = 0;
bool nobufs = false;

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

ssize_t sock_udp_recv_buf(sock_udp_t *sock, void **data, void **buf_ctx,
Expand All @@ -202,6 +203,12 @@ ssize_t sock_udp_recv_buf(sock_udp_t *sock, void **data, void **buf_ctx,
int res;

assert((sock != NULL) && (data != NULL) && (buf_ctx != NULL));
if (*buf_ctx != NULL) {
*data = NULL;
gnrc_pktbuf_release(*buf_ctx);
*buf_ctx = NULL;
return 0;
}
if (sock->local.family == AF_UNSPEC) {
return -EADDRNOTAVAIL;
}
Expand Down

0 comments on commit d934579

Please sign in to comment.