From: Mikko Rasa Date: Fri, 16 Oct 2015 18:18:41 +0000 (+0300) Subject: Avoid crashing due to network exceptions X-Git-Url: http://git.tdb.fi/?p=xinema.git;a=commitdiff_plain;h=a1e6d14ce3a5d5415333a4d3def6c5504f4bc49b Avoid crashing due to network exceptions --- diff --git a/source/client.cpp b/source/client.cpp index 8d61f3f..ba0be5b 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -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) diff --git a/source/networkinterface.cpp b/source/networkinterface.cpp index e5283b6..29947e8 100644 --- a/source/networkinterface.cpp +++ b/source/networkinterface.cpp @@ -1,3 +1,4 @@ +#include #include #include #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::iterator i=network.clients.begin(); i!=network.clients.end(); ) {