From 403faf2314bcd9317ce1ac3622a23496ddc367bd Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser <kaspar@schleiser.de> Date: Thu, 18 Jan 2018 14:52:38 +0100 Subject: [PATCH] pkg/lwip: update to use iolists --- pkg/lwip/contrib/netdev/lwip_netdev.c | 25 +++++++++++++++++-------- tests/lwip_sock_ip/stack.c | 8 ++++---- tests/lwip_sock_udp/stack.c | 8 ++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/pkg/lwip/contrib/netdev/lwip_netdev.c b/pkg/lwip/contrib/netdev/lwip_netdev.c index ffc8638441..cb9246aa8a 100644 --- a/pkg/lwip/contrib/netdev/lwip_netdev.c +++ b/pkg/lwip/contrib/netdev/lwip_netdev.c @@ -185,15 +185,24 @@ static err_t _eth_link_output(struct netif *netif, struct pbuf *p) pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ #endif LL_COUNT(p, q, count); - struct iovec pkt[count]; + iolist_t iolist[count]; + + /* make last point to the last entry of iolist[] */ + iolist_t *last = &iolist[count]; + last--; + for (q = p, count = 0; q != NULL; q = q->next, count++) { - pkt[count].iov_base = q->payload; - pkt[count].iov_len = (size_t)q->len; + iolist_t *iol = &iolist[count]; + + iol->iol_next = (iol == last) ? NULL : &iolist[count + 1]; + + iol->iol_base = q->payload; + iol->iol_len = (size_t)q->len; } #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif - return (netdev->driver->send(netdev, pkt, count) > 0) ? ERR_OK : ERR_BUF; + return (netdev->driver->send(netdev, iolist) > 0) ? ERR_OK : ERR_BUF; } #endif @@ -202,12 +211,12 @@ static err_t _ieee802154_link_output(struct netif *netif, struct pbuf *p) { LWIP_ASSERT("p->next == NULL", p->next == NULL); netdev_t *netdev = (netdev_t *)netif->state; - struct iovec pkt = { - .iov_base = p->payload, - .iov_len = (p->len - IEEE802154_FCS_LEN), /* FCS is written by driver */ + iolist_t pkt = { + .iol_base = p->payload, + .iol_len = (p->len - IEEE802154_FCS_LEN), /* FCS is written by driver */ }; - return (netdev->driver->send(netdev, &pkt, 1) > 0) ? ERR_OK : ERR_BUF; + return (netdev->driver->send(netdev, &pkt) > 0) ? ERR_OK : ERR_BUF; } #endif diff --git a/tests/lwip_sock_ip/stack.c b/tests/lwip_sock_ip/stack.c index 52e58a3f52..23ee9cabf9 100644 --- a/tests/lwip_sock_ip/stack.c +++ b/tests/lwip_sock_ip/stack.c @@ -141,16 +141,16 @@ static int _netdev_recv(netdev_t *dev, char *buf, int len, void *info) return res; } -static int _netdev_send(netdev_t *dev, const struct iovec *vector, int count) +static int _netdev_send(netdev_t *dev, const iolist_t *iolist) { msg_t done = { .type = _SEND_DONE }; unsigned offset = 0; (void)dev; mutex_lock(&_netdev_buffer_mutex); - for (int i = 0; i < count; i++) { - memcpy(&_netdev_buffer[offset], vector[i].iov_base, vector[i].iov_len); - offset += vector[i].iov_len; + for (; iolist; iolist = iolist->iol_next) { + memcpy(&_netdev_buffer[offset], iolist->iol_base, iolist->iol_len); + offset += iolist->iol_len; if (offset > sizeof(_netdev_buffer)) { mutex_unlock(&_netdev_buffer_mutex); return -ENOBUFS; diff --git a/tests/lwip_sock_udp/stack.c b/tests/lwip_sock_udp/stack.c index 45539cb478..cdde693b29 100644 --- a/tests/lwip_sock_udp/stack.c +++ b/tests/lwip_sock_udp/stack.c @@ -143,16 +143,16 @@ static int _netdev_recv(netdev_t *dev, char *buf, int len, void *info) return res; } -static int _netdev_send(netdev_t *dev, const struct iovec *vector, int count) +static int _netdev_send(netdev_t *dev, const iolist_t *iolist) { msg_t done = { .type = _SEND_DONE }; unsigned offset = 0; (void)dev; mutex_lock(&_netdev_buffer_mutex); - for (int i = 0; i < count; i++) { - memcpy(&_netdev_buffer[offset], vector[i].iov_base, vector[i].iov_len); - offset += vector[i].iov_len; + for (; iolist; iolist = iolist->iol_next) { + memcpy(&_netdev_buffer[offset], iolist->iol_base, iolist->iol_len); + offset += iolist->iol_len; if (offset > sizeof(_netdev_buffer)) { mutex_unlock(&_netdev_buffer_mutex); return -ENOBUFS; -- GitLab