Collapse nested conditionals.

This commit is contained in:
John Hood
2016-11-07 00:37:53 -05:00
parent 8ca8a54e11
commit 43785eb820
5 changed files with 59 additions and 75 deletions
+14 -18
View File
@@ -826,12 +826,11 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
fprintf( stderr, "Network idle for %llu seconds.\n", fprintf( stderr, "Network idle for %llu seconds.\n",
static_cast<unsigned long long>( time_since_remote_state / 1000 ) ); static_cast<unsigned long long>( time_since_remote_state / 1000 ) );
} }
if ( sel.signal( SIGUSR1 ) ) { if ( sel.signal( SIGUSR1 )
if ( !network_signaled_timeout_ms || network_signaled_timeout_ms <= time_since_remote_state ) { && ( !network_signaled_timeout_ms || network_signaled_timeout_ms <= time_since_remote_state ) ) {
idle_shutdown = true; idle_shutdown = true;
fprintf( stderr, "Network idle for %llu seconds when SIGUSR1 received\n", fprintf( stderr, "Network idle for %llu seconds when SIGUSR1 received\n",
static_cast<unsigned long long>( time_since_remote_state / 1000 ) ); static_cast<unsigned long long>( time_since_remote_state / 1000 ) );
}
} }
if ( sel.any_signal() || idle_shutdown ) { if ( sel.any_signal() || idle_shutdown ) {
@@ -860,24 +859,21 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
#ifdef HAVE_UTEMPTER #ifdef HAVE_UTEMPTER
/* update utmp if has been more than 30 seconds since heard from client */ /* update utmp if has been more than 30 seconds since heard from client */
if ( connected_utmp ) { if ( connected_utmp
if ( time_since_remote_state > 30000 ) { && time_since_remote_state > 30000 ) {
utempter_remove_record( host_fd ); utempter_remove_record( host_fd );
char tmp[ 64 ]; char tmp[ 64 ];
snprintf( tmp, 64, "mosh [%d]", getpid() ); snprintf( tmp, 64, "mosh [%d]", getpid() );
utempter_add_record( host_fd, tmp ); utempter_add_record( host_fd, tmp );
connected_utmp = false; connected_utmp = false;
}
} }
#endif #endif
if ( terminal.set_echo_ack( now ) ) { if ( terminal.set_echo_ack( now ) && !network.shutdown_in_progress() ) {
/* update client with new echo ack */ /* update client with new echo ack */
if ( !network.shutdown_in_progress() ) { network.set_current_state( terminal );
network.set_current_state( terminal );
}
} }
if ( !network.get_remote_state_num() if ( !network.get_remote_state_num()
+11 -17
View File
@@ -217,11 +217,9 @@ void STMClient::shutdown( void )
"Please verify that UDP port %s is not firewalled and can reach the server.\n\n" "Please verify that UDP port %s is not firewalled and can reach the server.\n\n"
"(By default, mosh uses a UDP port between 60000 and 61000. The -p option\n" "(By default, mosh uses a UDP port between 60000 and 61000. The -p option\n"
"selects a specific UDP port number.)\n", ip.c_str(), port.c_str(), port.c_str() ); "selects a specific UDP port number.)\n", ip.c_str(), port.c_str(), port.c_str() );
} else if ( network ) { } else if ( network && !clean_shutdown ) {
if ( !clean_shutdown ) { fputs( "\n\nmosh did not shut down cleanly. Please note that the\n"
fputs( "\n\nmosh did not shut down cleanly. Please note that the\n" "mosh-server process may still be running on the server.\n", stderr );
"mosh-server process may still be running on the server.\n", stderr );
}
} }
} }
@@ -481,21 +479,17 @@ bool STMClient::main( void )
process_network_input(); process_network_input();
} }
if ( sel.read( STDIN_FILENO ) ) { if ( sel.read( STDIN_FILENO ) && !process_user_input( STDIN_FILENO ) ) { /* input from the user needs to be fed to the network */
/* input from the user needs to be fed to the network */ if ( !network->has_remote_addr() ) {
if ( !process_user_input( STDIN_FILENO ) ) { break;
if ( !network->has_remote_addr() ) { } else if ( !network->shutdown_in_progress() ) {
break; overlays.get_notification_engine().set_notification_string( wstring( L"Exiting..." ), true );
} else if ( !network->shutdown_in_progress() ) { network->start_shutdown();
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting..." ), true );
network->start_shutdown();
}
} }
} }
if ( sel.signal( SIGWINCH ) ) { if ( sel.signal( SIGWINCH ) && !process_resize() ) { /* resize */
/* resize */ return false;
if ( !process_resize() ) { return false; }
} }
if ( sel.signal( SIGCONT ) ) { if ( sel.signal( SIGCONT ) ) {
+28 -31
View File
@@ -552,11 +552,10 @@ void PredictionEngine::cull( const Framebuffer &fb )
} }
/* When predictions come in quickly, slowly take away the glitch trigger. */ /* When predictions come in quickly, slowly take away the glitch trigger. */
if ( (now - j->prediction_time) < GLITCH_THRESHOLD ) { if ( now - j->prediction_time < GLITCH_THRESHOLD
if ( (glitch_trigger > 0) && (now - GLITCH_REPAIR_MININTERVAL >= last_quick_confirmation) ) { && ( glitch_trigger > 0 && now - GLITCH_REPAIR_MININTERVAL >= last_quick_confirmation ) ) {
glitch_trigger--; glitch_trigger--;
last_quick_confirmation = now; last_quick_confirmation = now;
}
} }
/* match rest of row to the actual renditions */ /* match rest of row to the actual renditions */
@@ -594,24 +593,23 @@ void PredictionEngine::cull( const Framebuffer &fb )
} }
/* go through cursor predictions */ /* go through cursor predictions */
if ( !cursors.empty() ) { if ( !cursors.empty()
if ( cursor().get_validity( fb, && cursor().get_validity( fb,
local_frame_acked, local_frame_late_acked ) == IncorrectOrExpired ) { local_frame_acked, local_frame_late_acked ) == IncorrectOrExpired ) {
/* /*
fprintf( stderr, "Sadly, we're predicting (%d,%d) vs. (%d,%d) [tau: %ld, expiration_time=%ld, now=%ld]\n", fprintf( stderr, "Sadly, we're predicting (%d,%d) vs. (%d,%d) [tau: %ld, expiration_time=%ld, now=%ld]\n",
cursor().row, cursor().col, cursor().row, cursor().col,
fb.ds.get_cursor_row(), fb.ds.get_cursor_row(),
fb.ds.get_cursor_col(), fb.ds.get_cursor_col(),
cursor().tentative_until_epoch, cursor().tentative_until_epoch,
cursor().expiration_time, cursor().expiration_time,
now ); now );
*/ */
if ( display_preference == Experimental ) { if ( display_preference == Experimental ) {
cursors.clear(); cursors.clear();
} else { } else {
reset(); reset();
return; return;
}
} }
} }
@@ -635,17 +633,16 @@ ConditionalOverlayRow & PredictionEngine::get_or_make_row( int row_num, int num_
if ( it != overlays.end() ) { if ( it != overlays.end() ) {
return *it; return *it;
} else {
/* make row */
ConditionalOverlayRow r( row_num );
r.overlay_cells.reserve( num_cols );
for ( int i = 0; i < num_cols; i++ ) {
r.overlay_cells.push_back( ConditionalOverlayCell( 0, i, prediction_epoch ) );
assert( r.overlay_cells[ i ].col == i );
}
overlays.push_back( r );
return overlays.back();
} }
/* make row */
ConditionalOverlayRow r( row_num );
r.overlay_cells.reserve( num_cols );
for ( int i = 0; i < num_cols; i++ ) {
r.overlay_cells.push_back( ConditionalOverlayCell( 0, i, prediction_epoch ) );
assert( r.overlay_cells[ i ].col == i );
}
overlays.push_back( r );
return overlays.back();
} }
void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
+3 -5
View File
@@ -173,11 +173,9 @@ Connection::Socket::Socket( int family )
/* request explicit congestion notification on received datagrams */ /* request explicit congestion notification on received datagrams */
#ifdef HAVE_IP_RECVTOS #ifdef HAVE_IP_RECVTOS
int tosflag = true; int tosflag = true;
if ( setsockopt( _fd, IPPROTO_IP, IP_RECVTOS, &tosflag, sizeof tosflag ) < 0 ) { if ( setsockopt( _fd, IPPROTO_IP, IP_RECVTOS, &tosflag, sizeof tosflag ) < 0
/* FreeBSD disallows this option on IPv6 sockets. */ && family == IPPROTO_IP ) { /* FreeBSD disallows this option on IPv6 sockets. */
if ( family == IPPROTO_IP ) { perror( "setsockopt( IP_RECVTOS )" );
perror( "setsockopt( IP_RECVTOS )" );
}
} }
#endif #endif
} }
+3 -4
View File
@@ -109,10 +109,9 @@ void Emulator::print( const Parser::Print *act )
this_cell->set_wide( chwidth == 2 ); /* chwidth had better be 1 or 2 here */ this_cell->set_wide( chwidth == 2 ); /* chwidth had better be 1 or 2 here */
fb.apply_renditions_to_cell( this_cell ); fb.apply_renditions_to_cell( this_cell );
if ( chwidth == 2 ) { /* erase overlapped cell */ if ( chwidth == 2
if ( fb.ds.get_cursor_col() + 1 < fb.ds.get_width() ) { && fb.ds.get_cursor_col() + 1 < fb.ds.get_width() ) { /* erase overlapped cell */
fb.reset_cell( fb.get_mutable_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() + 1 ) ); fb.reset_cell( fb.get_mutable_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() + 1 ) );
}
} }
fb.ds.move_col( chwidth, true, true ); fb.ds.move_col( chwidth, true, true );