[vlc-devel] [PATCH 1/4] os2: thread: improve vlc_poll_os2()

KO Myung-Hun komh78 at gmail.com
Sun Nov 22 04:24:39 CET 2015


From: KO Myung-Hun <komh78 at gmail.com>

If non-sockets, set revents to POLLNVAL. If reguar files, assume that
they are ready for the requested modes.
---
 src/os2/thread.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 76 insertions(+), 12 deletions(-)

diff --git a/src/os2/thread.c b/src/os2/thread.c
index 6407a08..5907176 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -47,6 +47,8 @@
 
 #include <386/builtin.h>
 
+#include <sys/stat.h>
+
 static vlc_threadvar_t thread_key;
 
 struct vlc_thread
@@ -774,6 +776,8 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
 {
     fd_set rdset, wrset, exset;
 
+    int non_sockets = 0;
+
     struct timeval tv = { 0, 0 };
 
     int val = -1;
@@ -784,6 +788,27 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
     for( unsigned i = 0; i < nfds; i++ )
     {
         int fd = fds[ i ].fd;
+        struct stat stbuf;
+
+        fds[ i ].revents = 0;
+
+        if( fstat( fd, &stbuf ) == -1 ||
+            (errno = 0, !S_ISSOCK( stbuf.st_mode )))
+        {
+            if( fd >= 0 )
+            {
+                /* If regular files, assume readiness for requested modes */
+                fds[ i ].revents = ( !errno && S_ISREG( stbuf.st_mode ))
+                                   ? ( fds[ i ].events &
+                                       ( POLLIN | POLLOUT | POLLPRI ))
+                                   : POLLNVAL;
+
+                non_sockets++;
+            }
+
+            continue;
+        }
+
         if( val < fd )
             val = fd;
 
@@ -801,24 +826,63 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
             FD_SET( fd, &exset );
     }
 
-    if( timeout >= 0 )
+    /* Sockets included ? */
+    if( val != -1 )
     {
-        div_t d    = div( timeout, 1000 );
-        tv.tv_sec  = d.quot;
-        tv.tv_usec = d.rem * 1000;
-    }
+        fd_set saved_rdset = rdset;
+        fd_set saved_wrset = wrset;
+        fd_set saved_exset = exset;
 
-    val = vlc_select( val + 1, &rdset, &wrset, &exset,
-                      ( timeout >= 0 ) ? &tv : NULL );
-    if( val == -1 )
-        return -1;
+        /* Check pending sockets */
+        switch( vlc_select( val + 1, &rdset, &wrset, &exset, &tv ))
+        {
+            case -1 :   /* Error */
+                return -1;
+
+            case 0 :    /* Timeout */
+                /* Socket only ? */
+                if( non_sockets == 0 )
+                {
+                    struct timeval *ptv = NULL;
+
+                    if( timeout >= 0 )
+                    {
+                        div_t d    = div( timeout, 1000 );
+                        tv.tv_sec  = d.quot;
+                        tv.tv_usec = d.rem * 1000;
+
+                        ptv = &tv;
+                    }
+
+                    rdset = saved_rdset;
+                    wrset = saved_wrset;
+                    exset = saved_exset;
+
+                    if( vlc_select( val + 1, &rdset, &wrset, &exset, ptv )
+                            == -1 )
+                        return -1;
+                }
+                break;
+
+            default:    /* Ready */
+                break;
+        }
+    }
 
+    val = 0;
     for( unsigned i = 0; i < nfds; i++ )
     {
         int fd = fds[ i ].fd;
-        fds[ i ].revents = ( FD_ISSET( fd, &rdset ) ? POLLIN  : 0 )
-                         | ( FD_ISSET( fd, &wrset ) ? POLLOUT : 0 )
-                         | ( FD_ISSET( fd, &exset ) ? POLLPRI : 0 );
+
+        if( fd >= 0 && fds[ i ].revents == 0 )
+        {
+            fds[ i ].revents = ( FD_ISSET( fd, &rdset ) ? POLLIN  : 0 )
+                             | ( FD_ISSET( fd, &wrset ) ? POLLOUT : 0 )
+                             | ( FD_ISSET( fd, &exset ) ? POLLPRI : 0 );
+        }
+
+        if( fds[ i ].revents != 0 )
+            val++;
     }
 
     return val;
-- 
2.6.0



More information about the vlc-devel mailing list