]> git.sesse.net Git - vlc/commitdiff
- Use poll() instead of select() so we don't depend on FD_SETSIZE
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 13:55:07 +0000 (13:55 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 13:55:07 +0000 (13:55 +0000)
- Clean up

modules/access/file.c

index c55e0ba7709e422418865e3bbc39af57e6442e75..6e28d127946aeafe8104f5dc928d976bc4185398 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * file.c: file input (file: access plug-in)
  *****************************************************************************
- * Copyright (C) 2001-2004 the VideoLAN team
+ * Copyright (C) 2001-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
+ *          Rémi Denis-Courmont <rem # videolan # org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -33,9 +34,6 @@
 #ifdef HAVE_SYS_TYPES_H
 #   include <sys/types.h>
 #endif
-#ifdef HAVE_SYS_TIME_H
-#   include <sys/time.h>
-#endif
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 #endif
@@ -45,6 +43,7 @@
 
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
+#   include <poll.h>
 #elif defined( WIN32 ) && !defined( UNDER_CE )
 #   include <io.h>
 #endif
@@ -374,35 +373,30 @@ static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
         if( !p_sys->b_kfir )
         {
             /* Find if some data is available. This won't work under Windows. */
-            struct timeval  timeout;
-            fd_set          fds;
-
-            /* Initialize file descriptor set */
-            FD_ZERO( &fds );
-            FD_SET( p_sys->fd, &fds );
-
-            /* We'll wait 0.5 second if nothing happens */
-            timeout.tv_sec = 0;
-            timeout.tv_usec = 500000;
-
-            /* Find if some data is available */
-            while( (i_ret = select( p_sys->fd + 1, &fds, NULL, NULL, &timeout )) == 0
-                    || (i_ret < 0 && errno == EINTR) )
+            do
             {
-                FD_ZERO( &fds );
-                FD_SET( p_sys->fd, &fds );
-                timeout.tv_sec = 0;
-                timeout.tv_usec = 500000;
+                struct pollfd ufd;
 
                 if( p_access->b_die )
                     return 0;
-            }
 
-            if( i_ret < 0 )
-            {
-                msg_Err( p_access, "select error (%s)", strerror(errno) );
-                return -1;
+                memset (&ufd, 0, sizeof (ufd));
+                ufd.fd = p_sys->fd;
+                ufd.events = POLLIN;
+
+                i_ret = poll( &ufd, 1, 500 );
+                if( i_ret == -1 )
+                {
+                    if( errno != EINTR )
+                    {
+                        msg_Err( p_access, "poll error: %s",
+                                 strerror( errno ) );
+                        return -1;
+                    }
+                    i_ret = 0;
+                }
             }
+            while( i_ret == 0 );
 
             i_ret = read( p_sys->fd, p_buffer, i_len );
         }
@@ -627,16 +621,6 @@ static int _OpenFile( access_t * p_access, const char * psz_name )
     p_sys->fd = open( psz_localname, O_NONBLOCK /*| O_LARGEFILE*/ );
     LocaleFree( psz_localname );
 
-#ifndef WIN32
-    if( p_sys->fd >= FD_SETSIZE )
-    {
-        // Avoid overflowing fd_set
-        close( p_sys->fd );
-        p_sys->fd = -1;
-        errno = EMFILE;
-    }
-#endif
-
     if ( p_sys->fd == -1 )
     {
         msg_Err( p_access, "cannot open file %s (%s)", psz_name,