]> git.tdb.fi Git - xinema.git/blobdiff - source/client.cpp
Avoid crashing due to network exceptions
[xinema.git] / source / client.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)