Skip to content

Commit

Permalink
Reset fd sets every time we poll (because network.fd() can now change)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Oct 5, 2012
1 parent 50e75b3 commit d17fb78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/frontend/mosh-server.cc
Expand Up @@ -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 );

Expand All @@ -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" );
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/stmclient.cc
Expand Up @@ -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 {
Expand All @@ -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" );
Expand Down
5 changes: 5 additions & 0 deletions src/util/select.h
Expand Up @@ -93,6 +93,11 @@ class Select {
FD_SET( fd, &all_fds );
}

void clear_fds( void )
{
FD_ZERO( &all_fds );
}

void add_signal( int signum )
{
fatal_assert( signum >= 0 );
Expand Down

0 comments on commit d17fb78

Please sign in to comment.