[vlc-commits] os2: thread: improve vlc_poll_os2()

KO Myung-Hun git at videolan.org
Thu Nov 26 17:32:18 CET 2015


vlc | branch: master | KO Myung-Hun <komh78 at gmail.com> | Sun Nov 22 12:24:39 2015 +0900| [e0c433dd35f1f6ef8fb768a4b5b03c6402314973] | committer: Jean-Baptiste Kempf

os2: thread: improve vlc_poll_os2()

If non-sockets, set revents to POLLNVAL. If regular files, assume that
they are ready for the requested modes.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e0c433dd35f1f6ef8fb768a4b5b03c6402314973
---

 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;



More information about the vlc-commits mailing list