diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-10-08 23:02:35 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-10-08 23:02:35 +0100 |
| commit | 12efbd5938f08eb445b43f539fa4f27aa5caccfb (patch) | |
| tree | ff931f920b30ad187942206268d9f18b3f06448d /src/lib/server_finder.cc | |
| parent | 630a56ad9e7ecfb42b1d761098820f9e492f9c4e (diff) | |
| parent | 0ae086a90ef262fed4e265df197fd62fcdfbccf7 (diff) | |
Merge master.
Diffstat (limited to 'src/lib/server_finder.cc')
| -rw-r--r-- | src/lib/server_finder.cc | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index 14cb3af59..637103591 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -102,24 +102,31 @@ void ServerFinder::listen_thread () try { + using namespace boost::asio::ip; + + boost::asio::io_service io_service; + tcp::acceptor acceptor (io_service, tcp::endpoint (tcp::v4(), Config::instance()->server_port_base() + 1)); + while (true) { - shared_ptr<Socket> sock (new Socket (60)); + tcp::socket socket (io_service); + acceptor.accept (socket); - try { - sock->accept (Config::instance()->server_port_base() + 1); - } catch (std::exception& e) { - continue; - } + /* 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); - uint32_t length = sock->read_uint32 (); scoped_array<char> buffer (new char[length]); - sock->read (reinterpret_cast<uint8_t*> (buffer.get()), 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 = sock->socket().remote_endpoint().address().to_string (); + + 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); |
