]> git.tdb.fi Git - xinema.git/commitdiff
Avoid crashing due to network exceptions
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 18:18:41 +0000 (21:18 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 18:18:41 +0000 (21:18 +0300)
source/client.cpp
source/networkinterface.cpp

index 8d61f3fa51e56c9a78d12a322e4ea973c9a479ba..ba0be5b44da51b11af152c59e1c6255c584ac958 100644 (file)
@@ -24,7 +24,17 @@ Client::Client(Xinema &x, Net::StreamSocket *s):
 void Client::data_available()
 {
        char rbuf[1024];
-       unsigned len = socket->read(rbuf, sizeof(rbuf));
+       unsigned len;
+       try
+       {
+               len = socket->read(rbuf, sizeof(rbuf));
+       }
+       catch(const std::exception &)
+       {
+               stale = true;
+               return;
+       }
+
        buffer.append(rbuf, len);
 
        string::size_type start = 0;
@@ -90,8 +100,15 @@ void Client::process_command(const string &cmd)
 void Client::send_reply(const string &reply)
 {
        Msp::MutexLock lock(mutex);
-       socket->write(reply);
-       socket->put('\n');
+       try
+       {
+               socket->write(reply);
+               socket->put('\n');
+       }
+       catch(const std::exception &)
+       {
+               stale = true;
+       }
 }
 
 void Client::list_directory(const FS::Path &dn)
index e5283b6ff96791c068b334e0a42ea1a0d102ad91..29947e84574701ea5e2c3c36e833636f5f8124ac 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/io/print.h>
 #include <msp/net/inet6.h>
 #include <msp/net/resolve.h>
 #include "client.h"
@@ -68,7 +69,14 @@ void NetworkInterface::NetworkThread::main()
 {
        while(!done)
        {
-               network.event_disp.tick();
+               try
+               {
+                       network.event_disp.tick();
+               }
+               catch(const std::exception &e)
+               {
+                       IO::print(IO::cerr, "Unhandled exception in network thread: %s\n", e.what());
+               }
 
                for(list<Client *>::iterator i=network.clients.begin(); i!=network.clients.end(); )
                {