[vlc-devel] commit: Provide sendmsg and recvmsg replacements ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat May 3 22:06:06 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | 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;
+}
More information about the vlc-devel
mailing list