mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
gnrc_sock: adapt for *_recv_buf() API change
This commit is contained in:
parent
58685af8a6
commit
d934579817
@ -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)
|
||||
{
|
||||
|
@ -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,
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
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_udp_recv_buf(sock_udp_t *sock, void **data, void **buf_ctx,
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user