diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2002-01-19 16:11:00 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2002-01-19 16:11:00 +0000 |
commit | 7d6be0d616cebf7de81ba721d2d0899aa03be0f4 (patch) | |
tree | 57b0be870c22375c7f55f77ec4190f46e9555dec /winsup/cygwin/net.cc | |
parent | 2d3dab2ea54fac1476c585e5083367059f0203d6 (diff) | |
download | newlib-7d6be0d616cebf7de81ba721d2d0899aa03be0f4.zip newlib-7d6be0d616cebf7de81ba721d2d0899aa03be0f4.tar.gz newlib-7d6be0d616cebf7de81ba721d2d0899aa03be0f4.tar.bz2 |
* cygwin.din: Add recvmsg and sendmsg.
* net.cc: Add cygwin_recvmsg and cygwin_sendmsg.
* /usr/include/sys/socket.h: Add recvmsg and sendmsg.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index c73a5af..790b099 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -34,6 +34,7 @@ details. */ #include "sigproc.h" #include "pinfo.h" #include "registry.h" +#include <sys/uio.h> extern "C" { int h_errno; @@ -2519,3 +2520,63 @@ extern "C" void endhostent (void) { } + +/* exported as recvmsg: standards? */ +extern "C" int +cygwin_recvmsg(int s, struct msghdr *msg, int flags) +{ + int ret, nb; + size_t tot = 0; + int i; + char *buf, *p; + struct iovec *iov = msg->msg_iov; + + for(i = 0; i < msg->msg_iovlen; ++i) + tot += iov[i].iov_len; + buf = (char *) malloc(tot); + if (tot != 0 && buf == NULL) { + errno = ENOMEM; + return -1; + } + nb = ret = cygwin_recvfrom (s, buf, tot, flags, + (struct sockaddr *) msg->msg_name, (int *) &msg->msg_namelen); + p = buf; + while (nb > 0) { + ssize_t cnt = min(nb, iov->iov_len); + + memcpy (iov->iov_base, p, cnt); + p += cnt; + nb -= cnt; + ++iov; + } + free(buf); + return ret; +} + +/* exported as sendmsg: standards? */ +extern "C" int +cygwin_sendmsg(int s, const struct msghdr *msg, int flags) +{ + int ret; + size_t tot = 0; + int i; + char *buf, *p; + struct iovec *iov = msg->msg_iov; + + for(i = 0; i < msg->msg_iovlen; ++i) + tot += iov[i].iov_len; + buf = (char *) malloc(tot); + if (tot != 0 && buf == NULL) { + errno = ENOMEM; + return -1; + } + p = buf; + for (i = 0; i < msg->msg_iovlen; ++i) { + memcpy (p, iov[i].iov_base, iov[i].iov_len); + p += iov[i].iov_len; + } + ret = cygwin_sendto (s, buf, tot, flags, + (struct sockaddr *) msg->msg_name, msg->msg_namelen); + free (buf); + return ret; +}
\ No newline at end of file |