- /* Emit the current list of servers */
- for (list<ServerDescription>::iterator i = _servers.begin(); i != _servers.end(); ++i) {
- fn (*i);
+ uint32_t length;
+ socket->read (reinterpret_cast<uint8_t*> (&length), sizeof (uint32_t));
+ length = ntohl (length);
+
+ scoped_array<char> buffer (new char[length]);
+ socket->read (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->socket().remote_endpoint().address().to_string ();
+ if (!server_found (ip) && xml->optional_number_child<int>("Version").get_value_or (0) == SERVER_LINK_VERSION) {
+ ServerDescription sd (ip, xml->number_child<int> ("Threads"));
+ {
+ boost::mutex::scoped_lock lm (_servers_mutex);
+ _servers.push_back (sd);
+ }
+ emit (boost::bind (boost::ref (ServersListChanged)));
+ }
+
+ start_accept ();
+}
+
+bool
+ServerFinder::server_found (string ip) const
+{
+ boost::mutex::scoped_lock lm (_servers_mutex);
+ list<ServerDescription>::const_iterator i = _servers.begin();
+ while (i != _servers.end() && i->host_name() != ip) {
+ ++i;