X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fserver.cc;h=38f9834ff3be354a74361fc60cd6b787fe119748;hb=a605b22381ee47d2737307e0b61e3423b020547b;hp=10f64b48250ee044e87128d45b7c5db8fe85e3c3;hpb=7ef2ba523ca2ddc0470f5837bc88ad9c597361e2;p=dcpomatic.git diff --git a/src/lib/server.cc b/src/lib/server.cc index 10f64b482..38f9834ff 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -36,8 +36,15 @@ #include "config.h" #include "subtitle.h" -using namespace std; -using namespace boost; +using std::string; +using std::stringstream; +using std::multimap; +using std::vector; +using boost::shared_ptr; +using boost::algorithm::is_any_of; +using boost::algorithm::split; +using boost::thread; +using boost::bind; /** Create a server description from a string of metadata returned from as_metadata(). * @param v Metadata. @@ -123,7 +130,16 @@ Server::process (shared_ptr socket) ); shared_ptr encoded = dcp_video_frame.encode_locally (); - encoded->send (socket); + try { + encoded->send (socket); + } catch (std::exception& e) { + _log->log (String::compose ( + "Send failed; frame %1, data size %2, pixel format %3, image size %4x%5, %6 components", + frame, encoded->size(), image->pixel_format(), image->size().width, image->size().height, image->components() + ) + ); + throw; + } return frame; } @@ -132,7 +148,7 @@ void Server::worker_thread () { while (1) { - mutex::scoped_lock lock (_worker_mutex); + boost::mutex::scoped_lock lock (_worker_mutex); while (_queue.empty ()) { _worker_condition.wait (lock); } @@ -150,7 +166,7 @@ Server::worker_thread () try { frame = process (socket); } catch (std::exception& e) { - cerr << "Error: " << e.what() << "\n"; + _log->log (String::compose ("Error: %1", e.what())); } socket.reset (); @@ -176,13 +192,13 @@ Server::run (int num_threads) _worker_threads.push_back (new thread (bind (&Server::worker_thread, this))); } - asio::io_service io_service; - asio::ip::tcp::acceptor acceptor (io_service, asio::ip::tcp::endpoint (asio::ip::tcp::v4(), Config::instance()->server_port ())); + boost::asio::io_service io_service; + boost::asio::ip::tcp::acceptor acceptor (io_service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), Config::instance()->server_port ())); while (1) { shared_ptr socket (new Socket); acceptor.accept (socket->socket ()); - mutex::scoped_lock lock (_worker_mutex); + boost::mutex::scoped_lock lock (_worker_mutex); /* Wait until the queue has gone down a bit */ while (int (_queue.size()) >= num_threads * 2) {