Commit e0c433dd authored by KO Myung-Hun's avatar KO Myung-Hun Committed by 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's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 9e2c32f8
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment