X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fclient.cpp;h=835dbbd91597f234ad794571dd3e14d56b2ec1d8;hb=4761421;hp=0e87e205055f6a5c796ce40f53a056fc4293ca01;hpb=e9e15ac445100aee25fb3314a3ad89e7142c33fb;p=xinema.git diff --git a/source/client.cpp b/source/client.cpp index 0e87e20..835dbbd 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -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));