int net_Socket (vlc_object_t *p_this, int family, int socktype,
int protocol)
{
- int fd = socket (family, socktype, protocol);
- if (fd == -1)
+ int fd;
+
+#ifdef SOCK_CLOEXEC
+ fd = socket (family, socktype | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
+ if (fd == -1 && errno == EINVAL)
+#endif
{
- if (net_errno != EAFNOSUPPORT)
- msg_Err (p_this, "cannot create socket: %m");
- return -1;
+ fd = socket (family, socktype, protocol);
+ if (fd == -1)
+ {
+ if (net_errno != EAFNOSUPPORT)
+ msg_Err (p_this, "cannot create socket: %m");
+ return -1;
+ }
+#ifndef WIN32
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
+ fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+#else
+ ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
+#endif
}
- net_SetupSocket (fd);
+ setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
#ifdef IPV6_V6ONLY
/*
net_Close (fd);
#if !defined(WIN32) && !defined(UNDER_CE)
fd = rootwrap_bind (ptr->ai_family, socktype,
- protocol ?: ptr->ai_protocol, ptr->ai_addr,
- ptr->ai_addrlen);
+ protocol ? protocol : ptr->ai_protocol,
+ ptr->ai_addr, ptr->ai_addrlen);
if (fd != -1)
{
msg_Dbg (p_this, "got socket %d from rootwrap", fd);
{
int canc = vlc_savecancel ();
n = vs->pf_recv (vs->p_sys, p_buf, i_buflen);
- canc = vlc_restorecancel (canc);
+ vlc_restorecancel (canc);
}
else
{
switch (errno)
{
case EAGAIN: /* spurious wakeup or no TLS data */
+#if (EAGAIN != EWOULDBLOCK)
+ case EWOULDBLOCK:
+#endif
case EINTR: /* asynchronous signal */
continue;
}
if( i_line == i_max )
{
i_max += 1024;
- psz_line = realloc( psz_line, i_max );
+ psz_line = xrealloc( psz_line, i_max );
ptr = psz_line + i_line;
}
return i_ret;
}
-
-#ifdef WIN32
- /* vlc_sendmsg, vlc_recvmsg Defined in winsock.c */
-#else /* !WIN32 */
-ssize_t vlc_sendmsg (int s, struct msghdr *hdr, int flags)
-{
- return sendmsg (s, hdr, flags);
-}
-
-ssize_t vlc_recvmsg (int s, struct msghdr *hdr, int flags)
-{
- return recvmsg (s, hdr, flags);
-}
-#endif /* WIN32 */
-