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
+5 -9
View File
@@ -826,13 +826,12 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
fprintf( stderr, "Network idle for %llu seconds.\n",
static_cast<unsigned long long>( time_since_remote_state / 1000 ) );
}
if ( sel.signal( SIGUSR1 ) ) {
if ( !network_signaled_timeout_ms || network_signaled_timeout_ms <= time_since_remote_state ) {
if ( sel.signal( SIGUSR1 )
&& ( !network_signaled_timeout_ms || network_signaled_timeout_ms <= time_since_remote_state ) ) {
idle_shutdown = true;
fprintf( stderr, "Network idle for %llu seconds when SIGUSR1 received\n",
static_cast<unsigned long long>( time_since_remote_state / 1000 ) );
}
}
if ( sel.any_signal() || idle_shutdown ) {
/* shutdown signal */
@@ -860,8 +859,8 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
#ifdef HAVE_UTEMPTER
/* update utmp if has been more than 30 seconds since heard from client */
if ( connected_utmp ) {
if ( time_since_remote_state > 30000 ) {
if ( connected_utmp
&& time_since_remote_state > 30000 ) {
utempter_remove_record( host_fd );
char tmp[ 64 ];
@@ -870,15 +869,12 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &
connected_utmp = false;
}
}
#endif
if ( terminal.set_echo_ack( now ) ) {
if ( terminal.set_echo_ack( now ) && !network.shutdown_in_progress() ) {
/* update client with new echo ack */
if ( !network.shutdown_in_progress() ) {
network.set_current_state( terminal );
}
}
if ( !network.get_remote_state_num()
&& time_since_remote_state >= timeout_if_no_client ) {
+4 -10
View File
@@ -217,13 +217,11 @@ void STMClient::shutdown( void )
"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"
"selects a specific UDP port number.)\n", ip.c_str(), port.c_str(), port.c_str() );
} else if ( network ) {
if ( !clean_shutdown ) {
} else if ( network && !clean_shutdown ) {
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 );
}
}
}
void STMClient::main_init( void )
{
@@ -481,9 +479,7 @@ bool STMClient::main( void )
process_network_input();
}
if ( sel.read( STDIN_FILENO ) ) {
/* input from the user needs to be fed to the network */
if ( !process_user_input( STDIN_FILENO ) ) {
if ( sel.read( STDIN_FILENO ) && !process_user_input( STDIN_FILENO ) ) { /* input from the user needs to be fed to the network */
if ( !network->has_remote_addr() ) {
break;
} else if ( !network->shutdown_in_progress() ) {
@@ -491,11 +487,9 @@ bool STMClient::main( void )
network->start_shutdown();
}
}
}
if ( sel.signal( SIGWINCH ) ) {
/* resize */
if ( !process_resize() ) { return false; }
if ( sel.signal( SIGWINCH ) && !process_resize() ) { /* resize */
return false;
}
if ( sel.signal( SIGCONT ) ) {
+5 -8
View File
@@ -552,12 +552,11 @@ void PredictionEngine::cull( const Framebuffer &fb )
}
/* When predictions come in quickly, slowly take away the glitch trigger. */
if ( (now - j->prediction_time) < GLITCH_THRESHOLD ) {
if ( (glitch_trigger > 0) && (now - GLITCH_REPAIR_MININTERVAL >= last_quick_confirmation) ) {
if ( now - j->prediction_time < GLITCH_THRESHOLD
&& ( glitch_trigger > 0 && now - GLITCH_REPAIR_MININTERVAL >= last_quick_confirmation ) ) {
glitch_trigger--;
last_quick_confirmation = now;
}
}
/* match rest of row to the actual renditions */
{
@@ -594,8 +593,8 @@ void PredictionEngine::cull( const Framebuffer &fb )
}
/* go through cursor predictions */
if ( !cursors.empty() ) {
if ( cursor().get_validity( fb,
if ( !cursors.empty()
&& cursor().get_validity( fb,
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",
@@ -613,7 +612,6 @@ void PredictionEngine::cull( const Framebuffer &fb )
return;
}
}
}
/* NB: switching from list to another STL container could break this code.
So we don't use the cursors_type typedef. */
@@ -635,7 +633,7 @@ ConditionalOverlayRow & PredictionEngine::get_or_make_row( int row_num, int num_
if ( it != overlays.end() ) {
return *it;
} else {
}
/* make row */
ConditionalOverlayRow r( row_num );
r.overlay_cells.reserve( num_cols );
@@ -646,7 +644,6 @@ ConditionalOverlayRow & PredictionEngine::get_or_make_row( int row_num, int num_
overlays.push_back( r );
return overlays.back();
}
}
void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb )
{
+2 -4
View File
@@ -173,12 +173,10 @@ Connection::Socket::Socket( int family )
/* request explicit congestion notification on received datagrams */
#ifdef HAVE_IP_RECVTOS
int tosflag = true;
if ( setsockopt( _fd, IPPROTO_IP, IP_RECVTOS, &tosflag, sizeof tosflag ) < 0 ) {
/* FreeBSD disallows this option on IPv6 sockets. */
if ( family == IPPROTO_IP ) {
if ( setsockopt( _fd, IPPROTO_IP, IP_RECVTOS, &tosflag, sizeof tosflag ) < 0
&& family == IPPROTO_IP ) { /* FreeBSD disallows this option on IPv6 sockets. */
perror( "setsockopt( IP_RECVTOS )" );
}
}
#endif
}
+2 -3
View File
@@ -109,11 +109,10 @@ void Emulator::print( const Parser::Print *act )
this_cell->set_wide( chwidth == 2 ); /* chwidth had better be 1 or 2 here */
fb.apply_renditions_to_cell( this_cell );
if ( chwidth == 2 ) { /* erase overlapped cell */
if ( fb.ds.get_cursor_col() + 1 < fb.ds.get_width() ) {
if ( chwidth == 2
&& 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.ds.move_col( chwidth, true, true );