From 119bbcaced5e14b1223a383c1552fe26cd1c790c Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Mon, 16 Apr 2012 02:31:27 -0400 Subject: [PATCH] Add nicer message and 15s timeout if server can't be reached on UDP. (Closes #152) --- src/frontend/stmclient.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index 7df8cf6..672d3a3 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -104,6 +104,12 @@ void STMClient::shutdown( void ) perror( "tcsetattr" ); exit( 1 ); } + + if ( still_connecting() ) { + fprintf( stderr, "mosh did not make a successful connection to %s:%d.\n", ip.c_str(), port ); + fprintf( stderr, "Please verify that UDP port %d is not firewalled and can reach the server.\n\n", port ); + fprintf( stderr, "(By default, mosh uses a UDP port between 60000 and 61000. The -p option\nselects a specific UDP port number.)\n" ); + } } void STMClient::main_init( void ) @@ -378,10 +384,19 @@ void STMClient::main( void ) break; } - static const wstring connecting_notification( L"Connecting..." ); + /* write diagnostic message if can't reach server */ + wchar_t tmp[ 128 ]; + swprintf( tmp, 128, L"Nothing received from server on UDP port %d.", port ); + wstring connecting_notification( tmp ); + if ( still_connecting() && (!network->shutdown_in_progress()) && (timestamp() - network->get_latest_remote_state().timestamp > 250) ) { + if ( timestamp() - network->get_latest_remote_state().timestamp > 15000 ) { + if ( !network->shutdown_in_progress() ) { + network->start_shutdown(); + } + } overlays.get_notification_engine().set_notification_string( connecting_notification ); } else if ( (network->get_remote_state_num() != 0) && (overlays.get_notification_engine().get_notification_string()