Restore asserts and error handling

A couple of them got improved out of existence.
This commit is contained in:
John Hood
2017-08-13 00:27:23 -04:00
parent 790b479f8a
commit b11d524bb7
6 changed files with 27 additions and 22 deletions
+2 -1
View File
@@ -298,8 +298,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const
}
break;
case -1: /* unprintable character */
default: /* Bogus width, ignore. */
break;
default:
assert( !"unexpected character width from wcwidth()" );
}
}
}
+14 -17
View File
@@ -335,23 +335,20 @@ bool Connection::try_bind( const char *addr, int port_low, int port_high )
if ( bind( sock(), &local_addr.sa, local_addr_len ) == 0 ) {
set_MTU( local_addr.sa.sa_family );
return true;
} else if ( i == search_high ) { /* last port to search */
int saved_errno = errno;
socks.pop_back();
char host[ NI_MAXHOST ], serv[ NI_MAXSERV ];
int errcode = getnameinfo( &local_addr.sa, local_addr_len,
host, sizeof( host ), serv, sizeof( serv ),
NI_DGRAM | NI_NUMERICHOST | NI_NUMERICSERV );
if ( errcode != 0 ) {
throw NetworkException( std::string( "bind: getnameinfo: " ) + gai_strerror( errcode ), 0 );
}
fprintf( stderr, "Failed binding to %s:%s\n",
host, serv );
throw NetworkException( "bind", saved_errno );
}
} // else fallthrough to below code, on last iteration.
}
return false;
int saved_errno = errno;
socks.pop_back();
char host[ NI_MAXHOST ], serv[ NI_MAXSERV ];
int errcode = getnameinfo( &local_addr.sa, local_addr_len,
host, sizeof( host ), serv, sizeof( serv ),
NI_DGRAM | NI_NUMERICHOST | NI_NUMERICSERV );
if ( errcode != 0 ) {
throw NetworkException( std::string( "bind: getnameinfo: " ) + gai_strerror( errcode ), 0 );
}
fprintf( stderr, "Failed binding to %s:%s\n",
host, serv );
throw NetworkException( "bind", saved_errno );
}
Connection::Connection( const char *key_str, const char *ip, const char *port ) /* client */
@@ -456,7 +453,7 @@ string Connection::recv( void )
prune_sockets();
return payload;
}
return "";
throw NetworkException( "No packet received" );
}
string Connection::recv_one( int sock_to_recv, bool nonblocking )
+2
View File
@@ -95,6 +95,7 @@ string UserStream::diff_from( const UserStream &existing ) const
}
break;
default:
assert( !"unexpected event type" );
break;
}
@@ -130,6 +131,7 @@ const Parser::Action &UserStream::get_action( unsigned int i ) const
case ResizeType:
return actions[ i ].resize;
default:
assert( !"unexpected action type" );
static const Parser::Ignore nothing = Parser::Ignore();
return nothing;
}
+1 -1
View File
@@ -85,7 +85,7 @@ namespace Network {
/* interface for Network::Transport */
void subtract( const UserStream *prefix );
string diff_from( const UserStream &existing ) const;
string init_diff( void ) const { return string(); };
string init_diff( void ) const { return diff_from( UserStream() ); };
void apply_string( const string &diff );
bool operator==( const UserStream &x ) const { return actions == x.actions; }
+3 -1
View File
@@ -140,7 +140,9 @@ void Emulator::print( const Parser::Print *act )
}
break;
case -1: /* unprintable character */
default: /* bogus width, ignore */
break;
default:
assert( !"unexpected character width from wcwidth()" );
break;
}
}
+5 -2
View File
@@ -46,6 +46,9 @@ string UserInput::input( const Parser::UserByte *act,
/* We need to look ahead one byte in the SS3 state to see if
the next byte will be A, B, C, or D (cursor control keys). */
/* This doesn't handle the 8-bit SS3 C1 control, which would be
two octets in UTF-8. Fortunately nobody seems to send this. */
switch ( state ) {
case Ground:
if ( act->c == 0x1b ) { /* ESC */
@@ -74,8 +77,8 @@ string UserInput::input( const Parser::UserByte *act,
}
default:
/* This doesn't handle the 8-bit SS3 C1 control, which would be
two octets in UTF-8. Fortunately nobody seems to send this. */
assert( !"unexpected state" );
state = Ground;
return string();
}
}