Remove a Network::Exception that isn't one.

Code smell pointed out by Coverity.
This commit is contained in:
John Hood
2016-11-19 20:59:49 -05:00
parent 4fe706a4d3
commit 24eb5a7544
6 changed files with 25 additions and 33 deletions
+6 -5
View File
@@ -539,15 +539,16 @@ bool STMClient::main( void )
network->tick();
const Network::NetworkException *exn = network->get_send_exception();
if ( exn ) {
overlays.get_notification_engine().set_network_exception( *exn );
string & send_error = network->get_send_error();
if ( !send_error.empty() ) {
overlays.get_notification_engine().set_network_error( send_error );
send_error.clear();
} else {
overlays.get_notification_engine().clear_network_exception();
overlays.get_notification_engine().clear_network_error();
}
} catch ( const Network::NetworkException &e ) {
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;
+1 -1
View File
@@ -168,7 +168,7 @@ NotificationEngine::NotificationEngine()
last_acked_state( timestamp() ),
escape_key_string(),
message(),
message_is_network_exception( false ),
message_is_network_error( false ),
message_expiration( -1 ),
show_quit_keystroke( true )
{}
+7 -8
View File
@@ -40,7 +40,6 @@
#include <vector>
#include <limits.h>
#include <exception>
namespace Overlay {
using namespace Terminal;
@@ -147,7 +146,7 @@ namespace Overlay {
uint64_t last_acked_state;
string escape_key_string;
wstring message;
bool message_is_network_exception;
bool message_is_network_error;
uint64_t message_expiration;
bool show_quit_keystroke;
@@ -171,7 +170,7 @@ namespace Overlay {
} else {
message_expiration = timestamp() + 1000;
}
message_is_network_exception = false;
message_is_network_error = false;
show_quit_keystroke = s_show_quit_keystroke;
}
@@ -182,19 +181,19 @@ namespace Overlay {
escape_key_string = tmp;
}
void set_network_exception( const std::exception &e )
void set_network_error( const std::string &s )
{
wchar_t tmp[ 128 ];
swprintf( tmp, 128, L"%s", e.what() );
swprintf( tmp, 128, L"%s", s.c_str() );
message = tmp;
message_is_network_exception = true;
message_is_network_error = true;
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 );
}
}
+6 -12
View File
@@ -249,8 +249,7 @@ Connection::Connection( const char *desired_ip, const char *desired_port ) /* se
RTT_hit( false ),
SRTT( 1000 ),
RTTVAR( 500 ),
have_send_exception( false ),
send_exception()
send_error()
{
setup();
@@ -369,8 +368,7 @@ Connection::Connection( const char *key_str, const char *ip, const char *port )
RTT_hit( false ),
SRTT( 1000 ),
RTTVAR( 500 ),
have_send_exception( false ),
send_exception()
send_error()
{
setup();
@@ -405,14 +403,10 @@ void Connection::send( const string & s )
ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT,
&remote_addr.sa, remote_addr_len );
if ( bytes_sent == static_cast<ssize_t>( p.size() ) ) {
have_send_exception = false;
} else {
/* Notify the frontend on sendto() failure, but don't alter control flow.
sendto() success is not very meaningful because packets can be lost in
flight anyway. */
have_send_exception = true;
send_exception = NetworkException( "sendto", errno );
if ( bytes_sent != static_cast<ssize_t>( p.size() ) ) {
/* Make sendto() failure available to the frontend. */
send_error = "sendto: ";
send_error += strerror( errno );
if ( errno == EMSGSIZE ) {
MTU = DEFAULT_SEND_MTU; /* payload MTU of last resort */
+4 -6
View File
@@ -187,10 +187,8 @@ namespace Network {
double SRTT;
double RTTVAR;
/* Exception from send(), to be delivered if the frontend asks for it,
without altering control flow. */
bool have_send_exception;
NetworkException send_exception;
/* Error from send()/sendto(). */
string send_error;
Packet new_packet( const string &s_payload );
@@ -226,9 +224,9 @@ namespace Network {
const Addr &get_remote_addr( void ) const { return remote_addr; }
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; }
+1 -1
View File
@@ -119,7 +119,7 @@ namespace Network {
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(); }
const NetworkException *get_send_exception( void ) const { return connection.get_send_exception(); }
std::string &get_send_error( void ) { return connection.get_send_error(); }
};
}