Commit 976b9f6d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Provide sendmsg and recvmsg replacements

parent 832088e4
...@@ -41,6 +41,27 @@ ...@@ -41,6 +41,27 @@
# define ENETUNREACH WSAENETUNREACH # define ENETUNREACH WSAENETUNREACH
# define net_errno (WSAGetLastError()) # define net_errno (WSAGetLastError())
extern const char *net_strerror( int val ); 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 # ifndef IPV6_V6ONLY
# define IPV6_V6ONLY 27 # define IPV6_V6ONLY 27
# endif # endif
......
...@@ -147,3 +147,60 @@ const char *net_strerror( int value ) ...@@ -147,3 +147,60 @@ const char *net_strerror( int value )
/* Remember to update src/misc/messages.c if you change this one */ /* Remember to update src/misc/messages.c if you change this one */
return "Unknown network stack error"; 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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment