From 445eef2b0e04bfa3b490e41631c261001a74d812 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Sun, 10 Sep 2017 22:37:40 -0500 Subject: [PATCH] sockets: add readv() implementation (task #14610) Adds an implementation of readv() that calls recvmsg() See http://pubs.opengroup.org/onlinepubs/009695399/functions/readv.html --- CHANGELOG | 3 +++ src/api/sockets.c | 17 +++++++++++++++++ src/include/lwip/sockets.h | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c434f233..b126f30e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,9 @@ HISTORY ++ New features: + 2017-09-10: Joel Cunningham + * sockets: add readv() implementation (task #14610) + 2017-08-04: Simon Goldschmidt * Clean up DHCP a bit: no need keep msg_out and msg_in as members in struct dhcp - they are used in a call stack only (p_out and options_out_len as well) diff --git a/src/api/sockets.c b/src/api/sockets.c index a23c7978..684c3820 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -1204,6 +1204,23 @@ lwip_read(int s, void *mem, size_t len) return lwip_recvfrom(s, mem, len, 0, NULL, NULL); } +ssize_t +lwip_readv(int s, const struct iovec *iov, int iovcnt) +{ + struct msghdr msg; + + msg.msg_name = NULL; + msg.msg_namelen = 0; + /* Hack: we have to cast via number to cast from 'const' pointer to non-const. + Blame the opengroup standard for this inconsistency. */ + msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); + msg.msg_iovlen = iovcnt; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + return lwip_recvmsg(s, &msg, 0); +} + ssize_t lwip_recv(int s, void *mem, size_t len, int flags) { diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 164f12b7..d51cfb61 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -529,6 +529,7 @@ void lwip_socket_thread_cleanup(void); /* LWIP_NETCONN_SEM_PER_THREAD==1: destro #if LWIP_POSIX_SOCKETS_IO_NAMES #define lwip_read read +#define lwip_readv readv #define lwip_write write #define lwip_writev writev #undef lwip_close @@ -551,6 +552,7 @@ int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); int lwip_listen(int s, int backlog); ssize_t lwip_recv(int s, void *mem, size_t len, int flags); ssize_t lwip_read(int s, void *mem, size_t len); +ssize_t lwip_readv(int s, const struct iovec *iov, int iovcnt); ssize_t lwip_recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); ssize_t lwip_recvmsg(int s, struct msghdr *message, int flags); @@ -619,6 +621,8 @@ int lwip_inet_pton(int af, const char *src, void *dst); /** @ingroup socket */ #define read(s,mem,len) lwip_read(s,mem,len) /** @ingroup socket */ +#define readv(s,iov,iovcnt) lwip_readv(s,iov,iovcnt) +/** @ingroup socket */ #define write(s,dataptr,len) lwip_write(s,dataptr,len) /** @ingroup socket */ #define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)