]> git.tdb.fi Git - r2c2.git/commitdiff
Better handling of network communication errors
authorMikko Rasa <tdb@tdb.fi>
Mon, 6 Apr 2015 22:26:41 +0000 (01:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 7 Apr 2015 11:12:18 +0000 (14:12 +0300)
Apparently, if a client abruptly disconnects, recv may return ECONNRESET.

source/network/server.cpp
source/network/server.h

index a892dedd25a85c79e9ba8edd1f3c60db767855a6..c60eb70e109f296ccad3a820f10df62c958a6798 100644 (file)
@@ -124,16 +124,7 @@ void Server::send(const P &pkt)
 {
        for(vector<Connection *>::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;
index 7063b861bbf66011bc12fad43050a60aa735cbef..50c0f72fae98d6ac2a0f0ce00e7d49a9b194ad02 100644 (file)
@@ -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 &);
        };