Make mosh-server exit if there's no connection within 60 seconds

Fixes #30 github issue.
This commit is contained in:
Keegan McAllister
2012-03-06 01:43:46 -08:00
parent 69b7c5cf44
commit b59f0f1482
+14 -1
View File
@@ -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 ) );