Add writev function

This commit adds compatibility with POSIX writev according to the Open
Group specification:
http://pubs.opengroup.org/onlinepubs/009695399/functions/writev.html

Implementation maps to sendmsg in the same manner that write() maps to
send()
This commit is contained in:
Joel Cunningham 2015-09-22 08:36:27 -05:00
parent db76671d4d
commit cc4d09423a
2 changed files with 18 additions and 0 deletions

View File

@ -1271,6 +1271,21 @@ lwip_write(int s, const void *data, size_t size)
return lwip_send(s, data, size, 0);
}
int
lwip_writev(int s, const struct iovec *iov, int iovcnt)
{
struct msghdr msg;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = iovcnt;
msg.msg_control = NULL;
msg.msg_controllen = 0;
msg.msg_flags = 0;
return lwip_sendmsg(s, &msg, 0);
}
/**
* Go through the readset and writeset lists and see which socket of the sockets
* set in the sets has events. On return, readset, writeset and exceptset have

View File

@ -470,6 +470,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_write write
#define lwip_writev writev
#undef lwip_close
#define lwip_close close
#define closesocket(s) close(s)
@ -498,6 +499,7 @@ int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
const struct sockaddr *to, socklen_t tolen);
int lwip_socket(int domain, int type, int protocol);
int lwip_write(int s, const void *dataptr, size_t size);
int lwip_writev(int s, const struct iovec *iov, int iovcnt);
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp);
@ -527,6 +529,7 @@ int lwip_fcntl(int s, int cmd, int val);
#if LWIP_POSIX_SOCKETS_IO_NAMES
#define read(s,mem,len) lwip_read(s,mem,len)
#define write(s,dataptr,len) lwip_write(s,dataptr,len)
#define writev(s,iov,iovcnt) lwip_writev(s,iov,iovcnt)
#define close(s) lwip_close(s)
#define fcntl(s,cmd,val) lwip_fcntl(s,cmd,val)
#define ioctl(s,cmd,argp) lwip_ioctl(s,cmd,argp)