]> git.sesse.net Git - vlc/blobdiff - src/network/tcp.c
Typos
[vlc] / src / network / tcp.c
index 8045563c6c7c446c45e3743e44955af66ad33484..537c4f919bf96281458d6e3f28962963d9f1f73f 100644 (file)
 #if defined (WIN32) || defined (UNDER_CE)
 #   undef EINPROGRESS
 #   define EINPROGRESS WSAEWOULDBLOCK
+#   undef EWOULDBLOCK
+#   define EWOULDBLOCK WSAEWOULDBLOCK
 #   undef EINTR
 #   define EINTR WSAEINTR
 #   undef ETIMEDOUT
 #   define ETIMEDOUT WSAETIMEDOUT
 #endif
 
+#include "libvlc.h" /* vlc_object_waitpipe */
+
 static int SocksNegotiate( vlc_object_t *, int fd, int i_socks_version,
                            const char *psz_user, const char *psz_passwd );
 static int SocksHandshakeTCP( vlc_object_t *,
@@ -149,8 +153,9 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
 
     for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
     {
-        int fd = net_Socket( p_this, ptr->ai_family, type ?: ptr->ai_socktype,
-                             proto ?: ptr->ai_protocol );
+        int fd = net_Socket( p_this, ptr->ai_family,
+                             type ? type : ptr->ai_socktype,
+                             proto ? proto : ptr->ai_protocol );
         if( fd == -1 )
         {
             msg_Dbg( p_this, "socket error: %m" );
@@ -161,7 +166,7 @@ int __net_Connect( vlc_object_t *p_this, const char *psz_host, int i_port,
         {
             int timeout, val;
 
-            if( net_errno != EINPROGRESS )
+            if( net_errno != EINPROGRESS && net_errno != EINTR )
             {
                 msg_Err( p_this, "connection failed: %m" );
                 goto next_ai;
@@ -249,10 +254,14 @@ next_ai: /* failure */
 
 int net_AcceptSingle (vlc_object_t *obj, int lfd)
 {
-    int fd = accept (lfd, NULL, NULL);
+    int fd;
+    do
+        fd = accept (lfd, NULL, NULL);
+    while (fd == -1 && errno == EINTR);
+
     if (fd == -1)
     {
-        if (net_errno != EAGAIN)
+        if (net_errno != EAGAIN && net_errno != EWOULDBLOCK)
             msg_Err (obj, "accept failed (from socket %d): %m", lfd);
         return -1;
     }
@@ -273,9 +282,6 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
     int timeout = (i_wait < 0) ? -1 : i_wait / 1000;
     int evfd = vlc_object_waitpipe (p_this);
 
-    if (evfd == -1)
-        return -1;
-
     assert( pi_fd != NULL );
 
     for (;;)
@@ -292,16 +298,17 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
             ufd[i].events = POLLIN;
             ufd[i].revents = 0;
         }
-        if (evfd == -1)
-            n--; /* avoid EBADF */
 
-        switch (poll (ufd, n, timeout))
+        switch (poll (ufd, n + (evfd != -1), timeout))
         {
             case -1:
-                if (net_errno != EINTR)
-                    msg_Err (p_this, "poll error: %m");
+                if (net_errno == EINTR)
+                    continue;
+                msg_Err (p_this, "poll error: %m");
+                return -1;
             case 0:
-                return -1; /* NOTE: p_this already unlocked */
+                errno = ETIMEDOUT;
+                return -1;
         }
 
         if (ufd[n].revents)
@@ -415,7 +422,7 @@ static int SocksNegotiate( vlc_object_t *p_obj,
             msg_Err( p_obj, "socks: unsupported authentication method %x",
                      buffer[0] );
         else
-            msg_Err( p_obj, "socks: authentification needed" );
+            msg_Err( p_obj, "socks: authentication needed" );
         return VLC_EGENERIC;
     }
 
@@ -505,7 +512,7 @@ static int SocksHandshakeTCP( vlc_object_t *p_obj,
 
         if( buffer[1] != 0x00 )
         {
-            msg_Err( p_obj, "socks: CONNECT request failed\n" );
+            msg_Err( p_obj, "socks: CONNECT request failed" );
             return VLC_EGENERIC;
         }