]> git.sesse.net Git - vlc/commitdiff
Set non-blocking mode on accepted sockets
authorRémi Denis-Courmont <rem@videolan.org>
Mon, 21 Jan 2008 17:12:41 +0000 (17:12 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Mon, 21 Jan 2008 17:12:41 +0000 (17:12 +0000)
include/vlc_network.h
modules/control/telnet.c
src/network/httpd.c
src/network/tcp.c

index d03a9243d4f74cc63b3acffe6e1d96ce874daa93..1e4d8f73c060b4da04e7fb0e1b75714aea98111a 100644 (file)
@@ -86,6 +86,9 @@ static inline int __net_ConnectTCP (vlc_object_t *obj, const char *host, int por
     return __net_Connect (obj, host, port, SOCK_STREAM, IPPROTO_TCP);
 }
 
+
+VLC_EXPORT( int, net_AcceptSingle, (vlc_object_t *obj, int lfd) );
+
 #define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
 VLC_EXPORT( int, __net_Accept, ( vlc_object_t *, int *, mtime_t ) );
 
index e53e8e5eec2664d2aa4a7ebda2f5ea680d1d914c..31fe2e466b92616bb0e4b8b3b77e9f0c96d0141f 100644 (file)
@@ -490,7 +490,7 @@ static void Run( intf_thread_t *p_intf )
             if (ufd[ncli + i].revents == 0)
                 continue;
 
-            fd = accept (ufd[ncli + i].fd, NULL, NULL);
+            fd = net_AcceptSingle (VLC_OBJECT(p_intf), ufd[ncli + i].fd);
             if (fd == -1)
                 continue;
 
index 5504b3b76a4ea1c564f69ef7041e7df505eb241f..9d7d57406c62e0390591eb9383c6a81b02ecd2a0 100644 (file)
@@ -2509,17 +2509,19 @@ static void httpd_HostThread( httpd_host_t *host )
         {
             httpd_client_t *cl;
             int i_state = -1;
+            int fd = ufd[nfd].fd;
 
-            assert (ufd[nfd].fd == host->fds[nfd]);
+            assert (fd == host->fds[nfd]);
 
             if( ufd[nfd].revents == 0 )
                 continue;
 
             /* */
-            int fd = accept (ufd[nfd].fd, NULL, NULL);
+            fd = accept (fd, NULL, NULL);
             if (fd == -1)
                 continue;
 
+            net_SetupSocket (fd);
             if( p_tls != NULL )
             {
                 switch( tls_ServerSessionHandshake( p_tls, fd ) )
index c7766f9575f0caaeb0ef3643304ddb7314b709d2..2f851555f7dc95dceda14daed68f1d4a900f17bb 100644 (file)
@@ -258,6 +258,22 @@ next_ai: /* failure */
 }
 
 
+int net_AcceptSingle (vlc_object_t *obj, int lfd)
+{
+    int fd = accept (lfd, NULL, NULL);
+    if (fd == -1)
+    {
+        if (net_errno != EAGAIN)
+            msg_Err (obj, "accept failed (from socket %d): %m", lfd);
+        return -1;
+    }
+
+    msg_Dbg (obj, "accepted socket %d (from socket %d)", fd, lfd);
+    net_SetupSocket (fd);
+    return 0;
+}
+
+
 /*****************************************************************************
  * __net_Accept:
  *****************************************************************************
@@ -312,13 +328,9 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
                 continue;
 
             int sfd = ufd[i].fd;
-            int fd = accept (sfd, NULL, NULL);
+            int fd = net_AcceptSingle (p_this, sfd);
             if (fd == -1)
-            {
-                msg_Err (p_this, "accept failed (%m)");
                 continue;
-            }
-            net_SetupSocket (fd);
 
             /*
              * Move listening socket to the end to let the others in the
@@ -327,7 +339,6 @@ int __net_Accept( vlc_object_t *p_this, int *pi_fd, mtime_t i_wait )
             memmove (pi_fd + i, pi_fd + i + 1, n - (i + 1));
             pi_fd[n - 1] = sfd;
             vlc_object_unlock (p_this);
-            msg_Dbg (p_this, "accepted socket %d (from socket %d)", fd, sfd);
             return fd;
         }
     }