- while (1) {
- {
- /* See if we need to stop */
- boost::mutex::scoped_lock lm (_mutex);
- if (_terminate) {
- return;
- }
- }
-
- shared_ptr<Socket> sock (new Socket (10));
-
- try {
- sock->accept (Config::instance()->server_port_base() + 1);
- } catch (std::exception& e) {
- continue;
- }
-
- uint32_t length = sock->read_uint32 ();
- scoped_array<char> buffer (new char[length]);
- sock->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
-
- stringstream s (buffer.get());
- shared_ptr<cxml::Document> xml (new cxml::Document ("ServerAvailable"));
- xml->read_stream (s);
-
- {
- /* See if we already know about this server */
- string const ip = sock->socket().remote_endpoint().address().to_string ();
- boost::mutex::scoped_lock lm (_mutex);
- ThreadList::iterator i = _threads.begin();
- while (i != _threads.end() && (!i->first || i->first->host_name() != ip)) {
- ++i;
- }
-
- if (i == _threads.end ()) {
- add_worker_threads (ServerDescription (ip, xml->number_child<int> ("Threads")));
- }
- }
- }