- boost::asio::io_service io_service;
- tcp::acceptor acceptor (io_service, tcp::endpoint (tcp::v4(), Config::instance()->server_port_base() + 1));
-
- while (true) {
- tcp::socket socket (io_service);
- acceptor.accept (socket);
-
- /* XXX: these reads should have timeouts, otherwise we will stop finding servers
- if one dies during this conversation
- */
-
- uint32_t length = 0;
- boost::asio::read (socket, boost::asio::buffer (&length, sizeof (uint32_t)));
- length = ntohl (length);
-
- scoped_array<char> buffer (new char[length]);
- boost::asio::read (socket, boost::asio::buffer (reinterpret_cast<uint8_t*> (buffer.get ()), length));
-
- string s (buffer.get());
- shared_ptr<cxml::Document> xml (new cxml::Document ("ServerAvailable"));
- xml->read_string (s);
-
- string const ip = socket.remote_endpoint().address().to_string ();
- if (!server_found (ip)) {
- ServerDescription sd (ip, xml->number_child<int> ("Threads"));
- _servers.push_back (sd);
- ui_signaller->emit (boost::bind (boost::ref (ServerFound), sd));
- }
+ try {
+ _listen_acceptor.reset (new tcp::acceptor (_listen_io_service, tcp::endpoint (tcp::v4(), Config::instance()->server_port_base() + 1)));
+ } catch (...) {
+ boost::throw_exception (NetworkError (_("Could not listen for remote encode servers. Perhaps another instance of DCP-o-matic is running.")));