1 /*****************************************************************************
2 * winsock.c: POSIX replacements for Winsock
3 *****************************************************************************
4 * Copyright © 2006-2008 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_network.h>
29 ssize_t
vlc_sendmsg (int s
, struct msghdr
*hdr
, int flags
)
31 /* WSASendMsg would be more straightforward, and would support ancilliary
32 * data, but it's not yet in mingw32. */
33 if ((hdr
->msg_iovlen
> 100) || (hdr
->msg_controllen
> 0))
39 WSABUF buf
[hdr
->msg_iovlen
];
40 for (size_t i
= 0; i
< sizeof (buf
) / sizeof (buf
[0]); i
++)
41 buf
[i
].buf
= hdr
->msg_iov
[i
].iov_base
,
42 buf
[i
].len
= hdr
->msg_iov
[i
].iov_len
;
45 if (WSASendTo (s
, buf
, sizeof (buf
) / sizeof (buf
[0]), &sent
, flags
,
46 hdr
->msg_name
, hdr
->msg_namelen
, NULL
, NULL
) == 0)
51 ssize_t
vlc_recvmsg (int s
, struct msghdr
*hdr
, int flags
)
53 /* WSARecvMsg would be more straightforward, and would support ancilliary
54 * data, but it's not yet in mingw32. */
55 if (hdr
->msg_iovlen
> 100)
61 WSABUF buf
[hdr
->msg_iovlen
];
62 for (size_t i
= 0; i
< sizeof (buf
) / sizeof (buf
[0]); i
++)
63 buf
[i
].buf
= hdr
->msg_iov
[i
].iov_base
,
64 buf
[i
].len
= hdr
->msg_iov
[i
].iov_len
;
66 DWORD recvd
, dwFlags
= flags
;
67 INT fromlen
= hdr
->msg_namelen
;
68 hdr
->msg_controllen
= 0;
71 int ret
= WSARecvFrom (s
, buf
, sizeof (buf
) / sizeof (buf
[0]), &recvd
,
72 &dwFlags
, hdr
->msg_name
, &fromlen
, NULL
, NULL
);
73 hdr
->msg_namelen
= fromlen
;
74 hdr
->msg_flags
= dwFlags
;
79 if (WSAGetLastError() == WSAEMSGSIZE
)
81 hdr
->msg_flags
|= MSG_TRUNC
;
85 # warning Out-of-date Winsock header files!