Catch exceptions in ntester

This commit is contained in:
Keith Winstein
2011-08-04 13:53:59 -04:00
parent d611ced646
commit bffc099754
+21 -13
View File
@@ -13,27 +13,35 @@ int main( int argc, char *argv[] )
Network::Connection<KeyStroke, KeyStroke> *n; Network::Connection<KeyStroke, KeyStroke> *n;
if ( argc > 1 ) { try {
server = false; if ( argc > 1 ) {
/* client */ server = false;
/* client */
key = argv[ 1 ]; key = argv[ 1 ];
ip = argv[ 2 ]; ip = argv[ 2 ];
port = atoi( argv[ 3 ] ); port = atoi( argv[ 3 ] );
n = new Network::Connection<KeyStroke, KeyStroke>( key, ip, port ); n = new Network::Connection<KeyStroke, KeyStroke>( key, ip, port );
} else { } else {
n = new Network::Connection<KeyStroke, KeyStroke>(); n = new Network::Connection<KeyStroke, KeyStroke>();
}
} catch ( CryptoException e ) {
fprintf( stderr, "Fatal error: %s\n", e.text.c_str() );
exit( 1 );
} }
fprintf( stderr, "Port bound is %d, key is %s\n", n->port(), n->get_key().c_str() ); fprintf( stderr, "Port bound is %d, key is %s\n", n->port(), n->get_key().c_str() );
if ( server ) { if ( server ) {
while ( true ) { while ( true ) {
KeyStroke s = n->recv(); try {
KeyStroke s = n->recv();
printf( "%c", s.letter ); printf( "%c", s.letter );
fflush( NULL ); fflush( NULL );
} catch ( CryptoException e ) {
fprintf( stderr, "Error: %s\n", e.text.c_str() );
}
} }
} else { } else {
struct termios the_termios; struct termios the_termios;