]> git.tdb.fi Git - xinema.git/blobdiff - source/client.cpp
Re-display the logo after the stream finishes
[xinema.git] / source / client.cpp
index 0e87e205055f6a5c796ce40f53a056fc4293ca01..835dbbd91597f234ad794571dd3e14d56b2ec1d8 100644 (file)
@@ -16,6 +16,7 @@ Client::Client(Xinema &x, Net::StreamSocket *s):
        socket->signal_end_of_file.connect(sigc::mem_fun(this, &Client::end_of_stream));
 
        xinema.signal_stream_created.connect(sigc::mem_fun(this, &Client::stream_created));
+       xinema.signal_stream_destroyed.connect(sigc::mem_fun(this, &Client::stream_destroyed));
        XineStream *stream = xinema.get_stream();
        if(stream)
                stream_created(*stream);
@@ -24,7 +25,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;
@@ -89,8 +100,16 @@ void Client::process_command(const string &cmd)
 
 void Client::send_reply(const string &reply)
 {
-       socket->write(reply);
-       socket->put('\n');
+       Msp::MutexLock lock(mutex);
+       try
+       {
+               socket->write(reply);
+               socket->put('\n');
+       }
+       catch(const std::exception &)
+       {
+               stale = true;
+       }
 }
 
 void Client::list_directory(const FS::Path &dn)
@@ -124,6 +143,11 @@ void Client::stream_created(XineStream &stream)
                stream_duration_changed(dur);
 }
 
+void Client::stream_destroyed()
+{
+       send_reply("ejected");
+}
+
 void Client::stream_state_changed(XineStream::State state)
 {
        send_reply(format("state %s", state));