Remove usage of exceptional fdsets with select().

This commit is contained in:
John Hood
2015-12-28 06:07:28 -05:00
parent 19f214e46d
commit ca21788c96
6 changed files with 3 additions and 49 deletions
+3 -16
View File
@@ -62,12 +62,10 @@ private:
here to appease -Weffc++. */
, all_fds( dummy_fd_set )
, read_fds( dummy_fd_set )
, error_fds( dummy_fd_set )
, empty_sigset( dummy_sigset )
{
FD_ZERO( &all_fds );
FD_ZERO( &read_fds );
FD_ZERO( &error_fds );
clear_got_signal();
fatal_assert( 0 == sigemptyset( &empty_sigset ) );
@@ -120,7 +118,6 @@ public:
int select( int timeout )
{
memcpy( &read_fds, &all_fds, sizeof( read_fds ) );
memcpy( &error_fds, &all_fds, sizeof( error_fds ) );
clear_got_signal();
#ifdef HAVE_PSELECT
@@ -133,7 +130,7 @@ public:
tsp = &ts;
}
int ret = ::pselect( max_fd + 1, &read_fds, NULL, &error_fds, tsp, &empty_sigset );
int ret = ::pselect( max_fd + 1, &read_fds, NULL, NULL, tsp, &empty_sigset );
#else
struct timeval tv;
struct timeval *tvp = NULL;
@@ -147,7 +144,7 @@ public:
int ret = sigprocmask( SIG_SETMASK, &empty_sigset, &old_sigset );
if ( ret != -1 ) {
ret = ::select( max_fd + 1, &read_fds, NULL, &error_fds, tvp );
ret = ::select( max_fd + 1, &read_fds, NULL, NULL, tvp );
sigprocmask( SIG_SETMASK, &old_sigset, NULL );
}
#endif
@@ -155,7 +152,6 @@ public:
if ( ( ret == -1 ) && ( errno == EINTR ) ) {
/* The user should process events as usual. */
FD_ZERO( &read_fds );
FD_ZERO( &error_fds );
ret = 0;
}
@@ -173,15 +169,6 @@ public:
return FD_ISSET( fd, &read_fds );
}
bool error( int fd )
#if FD_ISSET_IS_CONST
const
#endif
{
assert( FD_ISSET( fd, &all_fds ) );
return FD_ISSET( fd, &error_fds );
}
/* This method consumes a signal notification. */
bool signal( int signum )
{
@@ -214,7 +201,7 @@ private:
concurrent signal handlers. */
int got_signal[ MAX_SIGNAL_NUMBER + 1 ];
fd_set all_fds, read_fds, error_fds;
fd_set all_fds, read_fds;
sigset_t empty_sigset;