Make mosh-server exit if there's no connection within 60 seconds
Fixes #30 github issue.
This commit is contained in:
@@ -247,7 +247,13 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
||||
try {
|
||||
uint64_t now = Network::timestamp();
|
||||
|
||||
int active_fds = poll( pollfds, 3, min( network.wait_time(), terminal.wait_time( now ) ) );
|
||||
const int timeout_if_no_client = 60000;
|
||||
int poll_timeout = min( network.wait_time(), terminal.wait_time( now ) );
|
||||
if ( !network.has_remote_addr() ) {
|
||||
poll_timeout = min( poll_timeout, timeout_if_no_client );
|
||||
}
|
||||
|
||||
int active_fds = poll( pollfds, 3, poll_timeout );
|
||||
if ( active_fds < 0 ) {
|
||||
perror( "poll" );
|
||||
break;
|
||||
@@ -411,6 +417,13 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
|
||||
}
|
||||
}
|
||||
|
||||
if ( !network.has_remote_addr()
|
||||
&& time_since_remote_state >= uint64_t( timeout_if_no_client ) ) {
|
||||
fprintf( stderr, "No connection within %d seconds.\n",
|
||||
timeout_if_no_client / 1000 );
|
||||
break;
|
||||
}
|
||||
|
||||
network.tick();
|
||||
} catch ( Network::NetworkException e ) {
|
||||
fprintf( stderr, "%s: %s\n", e.function.c_str(), strerror( e.the_errno ) );
|
||||
|
||||
Reference in New Issue
Block a user