Improve client shutdown robustness

This commit is contained in:
Keith Winstein
2011-09-30 03:01:14 -04:00
parent 0d85b410fe
commit 31577a1c16
4 changed files with 39 additions and 3 deletions
+20 -2
View File
@@ -227,7 +227,16 @@ void STMClient::main( void )
if ( pollfds[ 3 ].revents & POLLIN ) {
/* shutdown signal */
if ( network->attached() ) {
struct signalfd_siginfo the_siginfo;
ssize_t bytes_read = read( pollfds[ 3 ].fd, &the_siginfo, sizeof( the_siginfo ) );
if ( bytes_read == 0 ) {
break;
} else if ( bytes_read < 0 ) {
perror( "read" );
break;
}
if ( network->attached() && (!network->shutdown_in_progress()) ) {
network->start_shutdown();
} else {
break;
@@ -243,7 +252,11 @@ void STMClient::main( void )
if ( (pollfds[ 1 ].revents)
& (POLLERR | POLLHUP | POLLNVAL) ) {
/* user problem */
network->start_shutdown();
if ( network->attached() && (!network->shutdown_in_progress()) ) {
network->start_shutdown();
} else {
break;
}
}
/* quit if our shutdown has been acknowledged */
@@ -251,6 +264,11 @@ void STMClient::main( void )
break;
}
/* quit after shutdown acknowledgement timeout */
if ( network->shutdown_in_progress() && network->shutdown_ack_timed_out() ) {
break;
}
/* quit if we received and acknowledged a shutdown request */
if ( network->counterparty_shutdown_ack_sent() ) {
break;