]> git.sesse.net Git - vlc/blobdiff - src/network/io.c
Use poll() always and fix terrible bug due to #ifdefs
[vlc] / src / network / io.c
index 7e6fdc2ceecabb8361f54653bd3136a8c91472b9..b66ddc6b1f2626a2f4a36ec4098b0a986e1597d1 100644 (file)
@@ -49,7 +49,7 @@
 #   include <poll.h>
 #endif
 
-#include "network.h"
+#include <vlc_network.h>
 
 #ifndef INADDR_ANY
 #   define INADDR_ANY  0x00000000
@@ -123,7 +123,6 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
     memset (&hints, 0, sizeof( hints ));
     hints.ai_family = family;
     hints.ai_socktype = socktype;
-    hints.ai_protocol = protocol;
     hints.ai_flags = AI_PASSIVE;
 
     msg_Dbg (p_this, "net: listening to %s port %d", psz_host, i_port);
@@ -142,7 +141,7 @@ int *net_Listen (vlc_object_t *p_this, const char *psz_host,
     for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
-                             ptr->ai_protocol);
+                             protocol ?: ptr->ai_protocol);
         if (fd == -1)
         {
             msg_Dbg (p_this, "socket error: %s", net_strerror (net_errno));
@@ -178,7 +177,7 @@ 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, ptr->ai_socktype,
-                                ptr->ai_protocol, ptr->ai_addr,
+                                protocol ?: ptr->ai_protocol, ptr->ai_addr,
                                 ptr->ai_addrlen);
             if (fd != -1)
             {
@@ -245,7 +244,7 @@ int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
 
     for (unsigned i = 1; fdv[i] != -1; i++)
     {
-        msg_Warn (obj, "A socket has been dropped!");
+        msg_Warn (obj, "Multiple sockets opened. Dropping extra ones!");
         net_Close (fdv[i]);
     }
 
@@ -287,12 +286,7 @@ net_ReadInner( vlc_object_t *restrict p_this, unsigned fdc, const int *fdv,
     {
         unsigned i;
         ssize_t n;
-#ifdef HAVE_POLL
         struct pollfd ufd[fdc];
-#else
-        int maxfd = -1;
-        fd_set set;
-#endif
 
         int delay_ms = 500;
         if ((wait_ms != -1) && (wait_ms < 500))
@@ -304,7 +298,6 @@ net_ReadInner( vlc_object_t *restrict p_this, unsigned fdc, const int *fdv,
             goto error;
         }
 
-#ifdef HAVE_POLL
         memset (ufd, 0, sizeof (ufd));
 
         for( i = 0; i < fdc; i++ )
@@ -314,28 +307,6 @@ net_ReadInner( vlc_object_t *restrict p_this, unsigned fdc, const int *fdv,
         }
 
         n = poll( ufd, fdc, delay_ms );
-#else
-        FD_ZERO (&set);
-
-        for( i = 0; i < fdc; i++ )
-        {
-#if !defined(WIN32) && !defined(UNDER_CE)
-            if( fdv[i] >= FD_SETSIZE )
-            {
-                /* We don't want to overflow select() fd_set */
-                msg_Err( p_this, "select set overflow" );
-                return -1;
-            }
-#endif
-            FD_SET( fdv[i], &set );
-            if( fdv[i] > maxfd )
-                maxfd = fdv[i];
-        }
-
-        n = select( maxfd + 1, &set, NULL, NULL,
-                    (wait_ms == -1) ? NULL
-                                  : &(struct timeval){ 0, delay_ms * 1000 } );
-#endif
         if( n == -1 )
             goto error;
 
@@ -346,15 +317,12 @@ net_ReadInner( vlc_object_t *restrict p_this, unsigned fdc, const int *fdv,
 
         for (i = 0;; i++)
         {
-#ifdef HAVE_POLL
             if ((i_total > 0) && (ufd[i].revents & POLLERR))
                 return i_total; // error will be dequeued on next run
 
             if ((ufd[i].revents & POLLIN) == 0)
-#else
-            if (!FD_ISSET (fdv[i], &set))
                 continue;
-#endif
+
             fdc = 1;
             fdv += i;
             vsv += i;
@@ -465,20 +433,13 @@ int __net_ReadNonBlock( vlc_object_t *restrict p_this, int fd,
  * that has some.
  *****************************************************************************/
 int __net_Select( vlc_object_t *restrict p_this, const int *restrict pi_fd,
-                  const v_socket_t *const *restrict pp_vs,
                   int i_fd, uint8_t *restrict p_data, int i_data,
                   mtime_t i_wait )
 {
-    if( pp_vs == NULL )
-    {
-        const v_socket_t *vsv[i_fd];
-        memset( vsv, 0, sizeof (vsv) );
-
-        return net_ReadInner( p_this, i_fd, pi_fd, vsv, p_data, i_data,
-                              i_wait / 1000, VLC_FALSE );
-    }
+    const v_socket_t *vsv[i_fd];
+    memset( vsv, 0, sizeof (vsv) );
 
-    return net_ReadInner( p_this, i_fd, pi_fd, pp_vs, p_data, i_data,
+    return net_ReadInner( p_this, i_fd, pi_fd, vsv, p_data, i_data,
                           i_wait / 1000, VLC_FALSE );
 }