X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fserver_finder.cc;h=4b532f98129d4f70386040d9dfc182761973312f;hb=1858190cff2f960f3d1f0a5cc02c69da86088f5b;hp=3eec6597b55df1d92125b1785ad2998a104adb33;hpb=43877eccbedc0950ab253e76dd0cea691fd7a4b0;p=dcpomatic.git diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index 3eec6597b..4b532f981 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -22,10 +22,12 @@ #include "util.h" #include "config.h" #include "cross.h" +#include "server_description.h" #include "dcpomatic_socket.h" #include "raw_convert.h" #include #include +#include #include "i18n.h" @@ -44,10 +46,15 @@ ServerFinder::ServerFinder () , _search_thread (0) , _listen_thread (0) , _stop (false) +{ + Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1)); +} + +void +ServerFinder::start () { _search_thread = new boost::thread (boost::bind (&ServerFinder::search_thread, this)); _listen_thread = new boost::thread (boost::bind (&ServerFinder::listen_thread, this)); - Config::instance()->Changed.connect (boost::bind (&ServerFinder::config_changed, this, _1)); } ServerFinder::~ServerFinder () @@ -55,10 +62,14 @@ ServerFinder::~ServerFinder () _stop = true; _search_condition.notify_all (); - _search_thread->join (); + if (_search_thread) { + _search_thread->join (); + } _listen_io_service.stop (); - _listen_thread->join (); + if (_listen_thread) { + _listen_thread->join (); + } } void @@ -167,7 +178,7 @@ ServerFinder::handle_accept (boost::system::error_code ec, shared_ptr so if (!server_found (ip) && xml->optional_number_child("Version").get_value_or (0) == SERVER_LINK_VERSION) { ServerDescription sd (ip, xml->number_child ("Threads")); { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (_servers_mutex); _servers.push_back (sd); } emit (boost::bind (boost::ref (ServersListChanged))); @@ -179,7 +190,7 @@ ServerFinder::handle_accept (boost::system::error_code ec, shared_ptr so bool ServerFinder::server_found (string ip) const { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (_servers_mutex); list::const_iterator i = _servers.begin(); while (i != _servers.end() && i->host_name() != ip) { ++i; @@ -193,6 +204,7 @@ ServerFinder::instance () { if (!_instance) { _instance = new ServerFinder (); + _instance->start (); } return _instance; @@ -208,7 +220,7 @@ ServerFinder::drop () list ServerFinder::servers () const { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (_servers_mutex); return _servers; } @@ -217,7 +229,7 @@ ServerFinder::config_changed (Config::Property what) { if (what == Config::USE_ANY_SERVERS || what == Config::SERVERS) { { - boost::mutex::scoped_lock lm (_mutex); + boost::mutex::scoped_lock lm (_servers_mutex); _servers.clear (); } ServersListChanged ();