- _log->log (String::compose (N_("Server starting with %1 threads"), num_threads));
-
- for (int i = 0; i < num_threads; ++i) {
- _worker_threads.push_back (new thread (bind (&Server::worker_thread, this)));
- }
-
- boost::asio::io_service io_service;
-
- /* Broadcast our presence on our interfaces */
- list<string> interfaces = network_interfaces ();
- for (list<string>::iterator i = interfaces.begin(); i != interfaces.end(); ++i) {
- boost::system::error_code error;
-
- boost::asio::ip::udp::socket socket (io_service);
- socket.open (boost::asio::ip::udp::v4(), error);
- if (error) {
- break;
- }
-
- socket.set_option (boost::asio::ip::udp::socket::reuse_address (true));
- socket.set_option (boost::asio::socket_base::broadcast (true));
-
- boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), Config::instance()->server_port ());
-
- string const data = DCPOMATIC_HELLO;
- socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point);
- socket.close (error);
- }
-
- /* Wait to be given things to do */
- 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> socket (new Socket);
- acceptor.accept (socket->socket ());
-
- boost::mutex::scoped_lock lock (_worker_mutex);
-
- /* Wait until the queue has gone down a bit */
- while (int (_queue.size()) >= num_threads * 2) {
- _worker_condition.wait (lock);
- }
-
- _queue.push_back (socket);
- _worker_condition.notify_all ();
- }