]> git.sesse.net Git - vlc/commitdiff
Use vlc_accept()
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 31 Mar 2010 16:28:41 +0000 (19:28 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 31 Mar 2010 16:28:41 +0000 (19:28 +0300)
This should also fix the accept4() ENOSYS infinite loop in httpd
pointed out by Aurélion Nephtali.

include/vlc_network.h
src/network/httpd.c
src/network/io.c
src/network/tcp.c

index 19502d22761061769dc7116db9e58dca015c3b7e..8f938f6e82fcb15a11248b14f6ebc3cbb4e6e72a 100644 (file)
@@ -83,7 +83,6 @@ extern "C" {
 
 /* Portable networking layer communication */
 int net_Socket (vlc_object_t *obj, int family, int socktype, int proto);
-int net_SetupSocket (int fd);
 
 VLC_EXPORT( int, net_Connect, (vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol) );
 #define net_Connect(a, b, c, d, e) net_Connect(VLC_OBJECT(a), b, c, d, e)
index 8dbdbf5878edecdd480432d46d9c71b2d6e8e0ab..2a92dce44b8545d1c0413a44974793997464a13d 100644 (file)
@@ -33,6 +33,7 @@
 #include <assert.h>
 
 #include <vlc_network.h>
+#include <vlc_fs.h>
 #include <vlc_tls.h>
 #include <vlc_acl.h>
 #include <vlc_strings.h>
@@ -2515,15 +2516,12 @@ static void* httpd_HostThread( void *data )
                 continue;
 
             /* */
-#ifdef HAVE_ACCEPT4
-            fd = accept4 (fd, NULL, NULL, SOCK_CLOEXEC);
-            if (fd == -1 && errno == ENOSYS)
-#endif
-            fd = accept (fd, NULL, NULL);
+            fd = vlc_accept (fd, NULL, NULL, true);
             if (fd == -1)
                 continue;
+            setsockopt (fd, SOL_SOCKET, SO_REUSEADDR,
+                        &(int){ 1 }, sizeof(int));
 
-            net_SetupSocket (fd);
             if( p_tls != NULL )
             {
                 switch( tls_ServerSessionHandshake( p_tls, fd ) )
index 69b1e0bedd23180bf9a324438cab73a665a262c0..fddac63a5b22633c5d2bb3a33f6bbb2479c39f8f 100644 (file)
 extern int rootwrap_bind (int family, int socktype, int protocol,
                           const struct sockaddr *addr, size_t alen);
 
-int net_SetupSocket (int fd)
-{
-#if defined (WIN32) || defined (UNDER_CE)
-    ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
-#else
-    fcntl (fd, F_SETFD, FD_CLOEXEC);
-    fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
-#endif
-
-    setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
-    return 0;
-}
-
-
 int net_Socket (vlc_object_t *p_this, int family, int socktype,
                 int protocol)
 {
index adbd4602f5f80999a9ac52e668627589ff4dedd9..9c35f16600f67da29226970df52a4281ca7a4773 100644 (file)
@@ -43,6 +43,7 @@
 #endif
 
 #include <vlc_network.h>
+#include <vlc_fs.h>
 #if defined (WIN32) || defined (UNDER_CE)
 #   undef EINPROGRESS
 #   define EINPROGRESS WSAEWOULDBLOCK
@@ -244,18 +245,7 @@ next_ai: /* failure */
 
 int net_AcceptSingle (vlc_object_t *obj, int lfd)
 {
-    int fd;
-
-    do
-    {
-#ifdef HAVE_ACCEPT4
-        fd = accept4 (lfd, NULL, NULL, SOCK_CLOEXEC);
-        if (fd == -1 && errno == ENOSYS)
-#endif
-        fd = accept (lfd, NULL, NULL);
-    }
-    while (fd == -1 && errno == EINTR);
-
+    int fd = vlc_accept (lfd, NULL, NULL, true);
     if (fd == -1)
     {
         if (net_errno != EAGAIN && net_errno != EWOULDBLOCK)
@@ -264,7 +254,7 @@ int net_AcceptSingle (vlc_object_t *obj, int lfd)
     }
 
     msg_Dbg (obj, "accepted socket %d (from socket %d)", fd, lfd);
-    net_SetupSocket (fd);
+    setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
     return fd;
 }