Remove a Network::Exception that isn't one.
Code smell pointed out by Coverity.
This commit is contained in:
@@ -539,15 +539,16 @@ bool STMClient::main( void )
|
|||||||
|
|
||||||
network->tick();
|
network->tick();
|
||||||
|
|
||||||
const Network::NetworkException *exn = network->get_send_exception();
|
string & send_error = network->get_send_error();
|
||||||
if ( exn ) {
|
if ( !send_error.empty() ) {
|
||||||
overlays.get_notification_engine().set_network_exception( *exn );
|
overlays.get_notification_engine().set_network_error( send_error );
|
||||||
|
send_error.clear();
|
||||||
} else {
|
} else {
|
||||||
overlays.get_notification_engine().clear_network_exception();
|
overlays.get_notification_engine().clear_network_error();
|
||||||
}
|
}
|
||||||
} catch ( const Network::NetworkException &e ) {
|
} catch ( const Network::NetworkException &e ) {
|
||||||
if ( !network->shutdown_in_progress() ) {
|
if ( !network->shutdown_in_progress() ) {
|
||||||
overlays.get_notification_engine().set_network_exception( e );
|
overlays.get_notification_engine().set_network_error( e.what() );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec req;
|
struct timespec req;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ NotificationEngine::NotificationEngine()
|
|||||||
last_acked_state( timestamp() ),
|
last_acked_state( timestamp() ),
|
||||||
escape_key_string(),
|
escape_key_string(),
|
||||||
message(),
|
message(),
|
||||||
message_is_network_exception( false ),
|
message_is_network_error( false ),
|
||||||
message_expiration( -1 ),
|
message_expiration( -1 ),
|
||||||
show_quit_keystroke( true )
|
show_quit_keystroke( true )
|
||||||
{}
|
{}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
namespace Overlay {
|
namespace Overlay {
|
||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
@@ -147,7 +146,7 @@ namespace Overlay {
|
|||||||
uint64_t last_acked_state;
|
uint64_t last_acked_state;
|
||||||
string escape_key_string;
|
string escape_key_string;
|
||||||
wstring message;
|
wstring message;
|
||||||
bool message_is_network_exception;
|
bool message_is_network_error;
|
||||||
uint64_t message_expiration;
|
uint64_t message_expiration;
|
||||||
bool show_quit_keystroke;
|
bool show_quit_keystroke;
|
||||||
|
|
||||||
@@ -171,7 +170,7 @@ namespace Overlay {
|
|||||||
} else {
|
} else {
|
||||||
message_expiration = timestamp() + 1000;
|
message_expiration = timestamp() + 1000;
|
||||||
}
|
}
|
||||||
message_is_network_exception = false;
|
message_is_network_error = false;
|
||||||
show_quit_keystroke = s_show_quit_keystroke;
|
show_quit_keystroke = s_show_quit_keystroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,19 +181,19 @@ namespace Overlay {
|
|||||||
escape_key_string = tmp;
|
escape_key_string = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_network_exception( const std::exception &e )
|
void set_network_error( const std::string &s )
|
||||||
{
|
{
|
||||||
wchar_t tmp[ 128 ];
|
wchar_t tmp[ 128 ];
|
||||||
swprintf( tmp, 128, L"%s", e.what() );
|
swprintf( tmp, 128, L"%s", s.c_str() );
|
||||||
|
|
||||||
message = tmp;
|
message = tmp;
|
||||||
message_is_network_exception = true;
|
message_is_network_error = true;
|
||||||
message_expiration = timestamp() + Network::ACK_INTERVAL + 100;
|
message_expiration = timestamp() + Network::ACK_INTERVAL + 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_network_exception()
|
void clear_network_error()
|
||||||
{
|
{
|
||||||
if ( message_is_network_exception ) {
|
if ( message_is_network_error ) {
|
||||||
message_expiration = std::min( message_expiration, timestamp() + 1000 );
|
message_expiration = std::min( message_expiration, timestamp() + 1000 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-12
@@ -249,8 +249,7 @@ Connection::Connection( const char *desired_ip, const char *desired_port ) /* se
|
|||||||
RTT_hit( false ),
|
RTT_hit( false ),
|
||||||
SRTT( 1000 ),
|
SRTT( 1000 ),
|
||||||
RTTVAR( 500 ),
|
RTTVAR( 500 ),
|
||||||
have_send_exception( false ),
|
send_error()
|
||||||
send_exception()
|
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
@@ -369,8 +368,7 @@ Connection::Connection( const char *key_str, const char *ip, const char *port )
|
|||||||
RTT_hit( false ),
|
RTT_hit( false ),
|
||||||
SRTT( 1000 ),
|
SRTT( 1000 ),
|
||||||
RTTVAR( 500 ),
|
RTTVAR( 500 ),
|
||||||
have_send_exception( false ),
|
send_error()
|
||||||
send_exception()
|
|
||||||
{
|
{
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
@@ -405,14 +403,10 @@ void Connection::send( const string & s )
|
|||||||
ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT,
|
ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT,
|
||||||
&remote_addr.sa, remote_addr_len );
|
&remote_addr.sa, remote_addr_len );
|
||||||
|
|
||||||
if ( bytes_sent == static_cast<ssize_t>( p.size() ) ) {
|
if ( bytes_sent != static_cast<ssize_t>( p.size() ) ) {
|
||||||
have_send_exception = false;
|
/* Make sendto() failure available to the frontend. */
|
||||||
} else {
|
send_error = "sendto: ";
|
||||||
/* Notify the frontend on sendto() failure, but don't alter control flow.
|
send_error += strerror( errno );
|
||||||
sendto() success is not very meaningful because packets can be lost in
|
|
||||||
flight anyway. */
|
|
||||||
have_send_exception = true;
|
|
||||||
send_exception = NetworkException( "sendto", errno );
|
|
||||||
|
|
||||||
if ( errno == EMSGSIZE ) {
|
if ( errno == EMSGSIZE ) {
|
||||||
MTU = DEFAULT_SEND_MTU; /* payload MTU of last resort */
|
MTU = DEFAULT_SEND_MTU; /* payload MTU of last resort */
|
||||||
|
|||||||
@@ -187,10 +187,8 @@ namespace Network {
|
|||||||
double SRTT;
|
double SRTT;
|
||||||
double RTTVAR;
|
double RTTVAR;
|
||||||
|
|
||||||
/* Exception from send(), to be delivered if the frontend asks for it,
|
/* Error from send()/sendto(). */
|
||||||
without altering control flow. */
|
string send_error;
|
||||||
bool have_send_exception;
|
|
||||||
NetworkException send_exception;
|
|
||||||
|
|
||||||
Packet new_packet( const string &s_payload );
|
Packet new_packet( const string &s_payload );
|
||||||
|
|
||||||
@@ -226,9 +224,9 @@ namespace Network {
|
|||||||
const Addr &get_remote_addr( void ) const { return remote_addr; }
|
const Addr &get_remote_addr( void ) const { return remote_addr; }
|
||||||
socklen_t get_remote_addr_len( void ) const { return remote_addr_len; }
|
socklen_t get_remote_addr_len( void ) const { return remote_addr_len; }
|
||||||
|
|
||||||
const NetworkException *get_send_exception( void ) const
|
string &get_send_error( void )
|
||||||
{
|
{
|
||||||
return have_send_exception ? &send_exception : NULL;
|
return send_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_last_roundtrip_success( uint64_t s_success ) { last_roundtrip_success = s_success; }
|
void set_last_roundtrip_success( uint64_t s_success ) { last_roundtrip_success = s_success; }
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ namespace Network {
|
|||||||
const Addr &get_remote_addr( void ) const { return connection.get_remote_addr(); }
|
const Addr &get_remote_addr( void ) const { return connection.get_remote_addr(); }
|
||||||
socklen_t get_remote_addr_len( void ) const { return connection.get_remote_addr_len(); }
|
socklen_t get_remote_addr_len( void ) const { return connection.get_remote_addr_len(); }
|
||||||
|
|
||||||
const NetworkException *get_send_exception( void ) const { return connection.get_send_exception(); }
|
std::string &get_send_error( void ) { return connection.get_send_error(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user