]> git.sesse.net Git - vlc/blobdiff - src/network/io.c
Fix compilation under MinGW/MSYS on WinXP Remove an error about a missing symbol...
[vlc] / src / network / io.c
index ed069b3d19666c7ea2957dafcf53a8392deec516..ef07124f740e2ec781a404c72b0b2f80b1550d03 100644 (file)
@@ -96,15 +96,29 @@ int net_SetupSocket (int fd)
 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
     /*
@@ -219,8 +233,8 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
             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);
@@ -281,7 +295,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
 /*****************************************************************************
  * __net_Read:
  *****************************************************************************
- * Reads from a network socket.
+ * Reads from a network socket. Cancellation point.
  * If waitall is true, then we repeat until we have read the right amount of
  * data; in that case, a short count means EOF has been reached or the VLC
  * object has been signaled.
@@ -343,7 +357,9 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
         ssize_t n;
         if (vs != NULL)
         {
+            int canc = vlc_savecancel ();
             n = vs->pf_recv (vs->p_sys, p_buf, i_buflen);
+            vlc_restorecancel (canc);
         }
         else
         {
@@ -377,6 +393,9 @@ __net_Read (vlc_object_t *restrict p_this, int fd, const v_socket_t *vs,
             switch (errno)
             {
                 case EAGAIN: /* spurious wakeup or no TLS data */
+#if (EAGAIN != EWOULDBLOCK)
+                case EWOULDBLOCK:
+#endif
                 case EINTR:  /* asynchronous signal */
                     continue;
             }
@@ -503,7 +522,7 @@ char *__net_Gets( vlc_object_t *p_this, int fd, const v_socket_t *p_vs )
         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;
         }
 
@@ -559,18 +578,3 @@ ssize_t __net_vaPrintf( vlc_object_t *p_this, int fd, const v_socket_t *p_vs,
 
     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 */
-