Reset fd sets every time we poll (because network.fd() can now change)

This commit is contained in:
Keith Winstein
2012-10-05 00:06:37 -04:00
parent 50e75b3127
commit d17fb7824b
3 changed files with 16 additions and 4 deletions
+5 -2
View File
@@ -510,8 +510,6 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
{
/* prepare to poll for events */
Select &sel = Select::get_instance();
sel.add_fd( network.fd() );
sel.add_fd( host_fd );
sel.add_signal( SIGTERM );
sel.add_signal( SIGINT );
@@ -534,6 +532,11 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
timeout = min( timeout, timeout_if_no_client );
}
/* poll for events */
sel.clear_fds();
sel.add_fd( network.fd() );
sel.add_fd( host_fd );
int active_fds = sel.select( timeout );
if ( active_fds < 0 ) {
perror( "select" );
+6 -2
View File
@@ -309,8 +309,6 @@ void STMClient::main( void )
/* prepare to poll for events */
Select &sel = Select::get_instance();
sel.add_fd( network->fd() );
sel.add_fd( STDIN_FILENO );
while ( 1 ) {
try {
@@ -323,6 +321,12 @@ void STMClient::main( void )
wait_time = min( 250, wait_time );
}
/* poll for events */
/* network->fd() can in theory change over time */
sel.clear_fds();
sel.add_fd( network->fd() );
sel.add_fd( STDIN_FILENO );
int active_fds = sel.select( wait_time );
if ( active_fds < 0 ) {
perror( "select" );
+5
View File
@@ -93,6 +93,11 @@ public:
FD_SET( fd, &all_fds );
}
void clear_fds( void )
{
FD_ZERO( &all_fds );
}
void add_signal( int signum )
{
fatal_assert( signum >= 0 );