From: Mikko Rasa Date: Mon, 6 Apr 2015 22:26:41 +0000 (+0300) Subject: Better handling of network communication errors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d13d841852d1fc5f97c40f93221745a63fae5e11;p=r2c2.git Better handling of network communication errors Apparently, if a client abruptly disconnects, recv may return ECONNRESET. --- diff --git a/source/network/server.cpp b/source/network/server.cpp index a892ded..c60eb70 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -124,16 +124,7 @@ void Server::send(const P &pkt) { for(vector::const_iterator i=connections.begin(); i!=connections.end(); ++i) if(!(*i)->stale && (*i)->comm.is_handshake_done()) - { - try - { - (*i)->comm.send(pkt); - } - catch(...) - { - (*i)->stale = true; - } - } + (*i)->comm.send(pkt); } @@ -144,6 +135,7 @@ Server::Connection::Connection(Server &s, Net::StreamSocket *o): { socket->signal_end_of_file.connect(sigc::mem_fun(this, &Connection::end_of_file)); comm.signal_handshake_done.connect(sigc::mem_fun(this, &Connection::handshake_done)); + comm.signal_error.connect(sigc::mem_fun(this, &Connection::comm_error)); comm.initiate_handshake(); } @@ -279,6 +271,11 @@ void Server::Connection::receive(const TrainRoutePacket &pkt) } } +void Server::Connection::comm_error(const exception &) +{ + stale = true; +} + void Server::Connection::error(const string &msg) { ErrorPacket pkt; diff --git a/source/network/server.h b/source/network/server.h index 7063b86..50c0f72 100644 --- a/source/network/server.h +++ b/source/network/server.h @@ -34,6 +34,7 @@ private: virtual void receive(const TrainControlPacket &); virtual void receive(const TrainFunctionPacket &); virtual void receive(const TrainRoutePacket &); + void comm_error(const std::exception &); void error(const std::string &); };