]> git.tdb.fi Git - r2c2.git/blobdiff - source/network/server.cpp
Better handling of network communication errors
[r2c2.git] / source / network / server.cpp
index aced6f7202f2e6dc894af1ec686fb4fb51a1c72f..c60eb70e109f296ccad3a820f10df62c958a6798 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/refptr.h>
 #include <msp/net/inet.h>
 #include <msp/net/resolve.h>
+#include "libr2c2/catalogue.h"
 #include "libr2c2/driver.h"
 #include "libr2c2/route.h"
 #include "libr2c2/train.h"
@@ -74,7 +75,7 @@ void Server::train_added(Train &train)
 
        TrainInfoPacket pkt;
        pkt.address = train.get_address();
-       pkt.loco_type = train.get_locomotive_type().get_article_number().str();
+       pkt.loco_type = layout.get_catalogue().get_name(&train.get_locomotive_type());
        pkt.name = train.get_name();
        send(pkt);
 
@@ -123,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);
 }
 
 
@@ -143,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();
 }
 
@@ -169,6 +162,7 @@ void Server::Connection::handshake_done()
                        comm.send(pkt);
                }
 
+       const Catalogue &cat = server.layout.get_catalogue();
        const map<unsigned, Train *> &trains = server.layout.get_trains();
        for(map<unsigned, Train *>::const_iterator i=trains.begin(); i!=trains.end(); ++i)
        {
@@ -177,7 +171,7 @@ void Server::Connection::handshake_done()
                {
                        TrainInfoPacket pkt;
                        pkt.address = train.get_address();
-                       pkt.loco_type = train.get_locomotive_type().get_article_number().str();
+                       pkt.loco_type = cat.get_name(&train.get_locomotive_type());
                        pkt.name = train.get_name();
                        comm.send(pkt);
                }
@@ -277,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;