[vlc-devel] [PATCH v2 1/3] os2: thread: improve vlc_poll_os2()
KO Myung-Hun
komh78 at gmail.com
Sun Oct 25 14:01:34 CET 2015
From: KO Myung-Hun <komh78 at gmail.com>
If non-sockets, set revents to POLLNVAL;
---
src/os2/thread.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 68 insertions(+), 12 deletions(-)
diff --git a/src/os2/thread.c b/src/os2/thread.c
index 6407a08..2f2ec48 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -774,6 +774,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 +786,21 @@ 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 ))
+ {
+ if (fd >= 0)
+ {
+ fds[ i ].revents = POLLNVAL;
+ non_sockets++;
+ }
+
+ continue;
+ }
+
if( val < fd )
val = fd;
@@ -801,24 +818,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