mediacodec: check exceptions after createByCodecName()
[vlc.git] / src / win32 / winsock.c
blob92822ae830c5008b9f4f111617a142cf88eb22a4
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_network.h>
28 #if 0
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))
35 errno = EINVAL;
36 return -1;
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;
44 DWORD sent;
45 if (WSASendTo (s, buf, sizeof (buf) / sizeof (buf[0]), &sent, flags,
46 hdr->msg_name, hdr->msg_namelen, NULL, NULL) == 0)
47 return sent;
48 return -1;
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)
57 errno = EINVAL;
58 return -1;
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;
69 hdr->msg_flags = 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;
75 if (ret == 0)
76 return recvd;
78 #ifdef MSG_TRUNC
79 if (WSAGetLastError() == WSAEMSGSIZE)
81 hdr->msg_flags |= MSG_TRUNC;
82 return recvd;
84 #else
85 # warning Out-of-date Winsock header files!
86 #endif
87 return -1;
89 #endif