[vlc-devel] [PATCH 1/4] os2: thread: set POLLNVAL instead of returning -1 if not a socket

KO Myung-Hun komh78 at gmail.com
Mon Sep 7 08:56:39 CEST 2015


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

---
 src/os2/thread.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/os2/thread.c b/src/os2/thread.c
index e221632..7d9673c 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -785,6 +785,7 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
     fd_set rdset, wrset, exset;
 
     struct timeval tv = { 0, 0 };
+    struct timeval *ptv = NULL;
 
     int val = -1;
 
@@ -794,6 +795,16 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
     for( unsigned i = 0; i < nfds; i++ )
     {
         int fd = fds[ i ].fd;
+
+        fds[ i ].revents = 0;
+        if( getsockopt( fd, SOL_SOCKET, SO_TYPE,
+                        &( int ){ 0 }, &( int ){ sizeof( int )}) == -1 &&
+            ( errno == ENOTSOCK || errno == EBADF ))
+        {
+            fds[ i ].revents = POLLNVAL;
+            continue;
+        }
+
         if( val < fd )
             val = fd;
 
@@ -816,19 +827,26 @@ int vlc_poll_os2( struct pollfd *fds, unsigned nfds, int timeout )
         div_t d    = div( timeout, 1000 );
         tv.tv_sec  = d.quot;
         tv.tv_usec = d.rem * 1000;
+
+        ptv = &tv;
     }
 
-    val = vlc_select( val + 1, &rdset, &wrset, &exset,
-                      ( timeout >= 0 ) ? &tv : NULL );
-    if( val == -1 )
+    if( val != -1 && vlc_select( val + 1, &rdset, &wrset, &exset, ptv ) == -1 )
         return -1;
 
+    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( fds[ i ].revents == 0 )
+        {
+            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( fds[ i ].revents != 0 )
+            val++;
     }
 
     return val;
-- 
1.9.5



More information about the vlc-devel mailing list