Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: git version control <git <at> videolan.org>
Subject: =?utf-8?q?commit=3A_Provide_sendmsg_and_recvmsg_repla?= =?utf-8?q?cements_=28_R=C3=A9mi_Denis-Courmont_=29?=
Newsgroups: gmane.comp.video.videolan.vlc.devel
Date: Saturday 3rd May 2008 20:06:06 UTC (over 9 years ago)
vlc | branch: master | RĂ©mi Denis-Courmont  | Sat May  3
21:13:55 2008 +0300| [976b9f6dc9259e4532a01502d00aa91c95f455e8]

Provide sendmsg and recvmsg replacements

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=976b9f6dc9259e4532a01502d00aa91c95f455e8
---

 include/vlc_network.h |   21 ++++++++++++++++++
 src/network/winsock.c |   57
+++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/include/vlc_network.h b/include/vlc_network.h
index 260634e..643b4eb 100644
--- a/include/vlc_network.h
+++ b/include/vlc_network.h
@@ -41,6 +41,27 @@
 #   define ENETUNREACH WSAENETUNREACH
 #   define net_errno (WSAGetLastError())
 extern const char *net_strerror( int val );
+
+struct iovec
+{
+    void  *iov_base;
+    size_t iov_len;
+};
+
+struct msghdr
+{
+    void         *msg_name;
+    size_t        msg_namelen;
+    struct iovec *msg_iov;
+    size_t        msg_iovlen;
+    void         *msg_control;
+    size_t        msg_controllen;
+    int           msg_flags;
+};
+
+VLC_EXPORT( ssize_t, sendmsg, ( int, struct msghdr *, int ) );
+VLC_EXPORT( ssize_t, recvmsg, ( int, struct msghdr *, int ) );
+
 #   ifndef IPV6_V6ONLY
 #       define IPV6_V6ONLY 27
 #   endif
diff --git a/src/network/winsock.c b/src/network/winsock.c
index e3b66ea..fecd3fd 100644
--- a/src/network/winsock.c
+++ b/src/network/winsock.c
@@ -147,3 +147,60 @@ const char *net_strerror( int value )
     /* Remember to update src/misc/messages.c if you change this one */
     return "Unknown network stack error";
 }
+
+ssize_t sendmsg (int s, struct msghdr *hdr, int flags)
+{
+    /* WSASendMsg would be more straightforward, and would support
ancilliary
+     * data, but it's not yet in mingw32. */
+    if ((hdr->msg_iovlen > 100) || (hdr->msg_controllen > 0))
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    WSABUF buf[hdr->msg_iovlen];
+    for (size_t i = 0; i < sizeof (buf) / sizeof (buf[0]); i++)
+        buf[i].buf = hdr->msg_iov[i].iov_base,
+        buf[i].len = hdr->msg_iov[i].iov_len;
+
+    DWORD sent;
+    if (WSASendTo (s, buf, sizeof (buf) / sizeof (buf[0]), &sent, flags,
+                   hdr->msg_name, hdr->msg_namelen, NULL, NULL) == 0)
+        return sent;
+    return -1;
+}
+
+ssize_t recvmsg (int s, struct msghdr *hdr, int flags)
+{
+    /* WSARecvMsg would be more straightforward, and would support
ancilliary
+     * data, but it's not yet in mingw32. */
+    if (hdr->msg_iovlen > 100)
+    {
+        errno = EINVAL;
+        return -1;
+    }
+
+    WSABUF buf[hdr->msg_iovlen];
+    for (size_t i = 0; i < sizeof (buf) / sizeof (buf[0]); i++)
+        buf[i].buf = hdr->msg_iov[i].iov_base,
+        buf[i].len = hdr->msg_iov[i].iov_len;
+
+    DWORD recvd;
+    hdr->msg_controllen = 0;
+    hdr->msg_flags = 0;
+
+    if (WSARecvFrom (s, buf, sizeof (buf) / sizeof (buf[0]), &recvd,
flags,
+                     hdr->msg_name, hdr->msg_namelen, NULL, NULL) == 0)
+        return recvd;
+
+#ifdef MSG_TRUNC
+    if (WSAGetLastError() == WSAEMSGSIZE)
+    {
+        hdr->msg_flags |= MSG_TRUNC;
+        return recvd;
+    }
+#else
+# warning Out-of-date Winsock header files!
+#endif
+    return -1;
+}

_______________________________________________
vlc-devel mailing list
To unsubscribe or modify your subscription options:
http://mailman.videolan.org/listinfo/vlc-devel
 
CD: 3ms