From 7ae514af0aea1b953a93f88d5507e6c1dd675908 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 6 Jul 2015 13:37:35 +0100 Subject: Better updating of servers list when things change. --- src/lib/server_finder.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/lib/server_finder.h') diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index ec855938b..c43c2a422 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -19,13 +19,12 @@ #include "server.h" #include "signaller.h" +#include "config.h" #include class ServerFinder : public Signaller, public ExceptionStore { public: - boost::signals2::connection connect (boost::function); - static ServerFinder* instance (); static void drop (); @@ -37,6 +36,11 @@ public: return _disabled; } + std::list servers () const; + + /** Emitted whenever the list of servers changes */ + boost::signals2::signal ServersListChanged; + private: ServerFinder (); ~ServerFinder (); @@ -48,7 +52,7 @@ private: void start_accept (); void handle_accept (boost::system::error_code ec, boost::shared_ptr socket); - boost::signals2::signal ServerFound; + void config_changed (Config::Property what); bool _disabled; -- cgit v1.2.3 From a6e7017b36ea2cee9f95c45fc0a4f85294dbc16f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 6 Jul 2015 13:44:05 +0100 Subject: Rename broadcast thread to search thread. --- src/lib/server_finder.cc | 10 +++++----- src/lib/server_finder.h | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/lib/server_finder.h') diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index a189ae802..ecda385eb 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -41,11 +41,11 @@ ServerFinder* ServerFinder::_instance = 0; ServerFinder::ServerFinder () : _disabled (false) - , _broadcast_thread (0) + , _search_thread (0) , _listen_thread (0) , _stop (false) { - _broadcast_thread = new boost::thread (boost::bind (&ServerFinder::broadcast_thread, this)); + _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)); } @@ -54,15 +54,15 @@ ServerFinder::~ServerFinder () { _stop = true; - _broadcast_thread->interrupt (); - _broadcast_thread->join (); + _search_thread->interrupt (); + _search_thread->join (); _listen_io_service.stop (); _listen_thread->join (); } void -ServerFinder::broadcast_thread () +ServerFinder::search_thread () try { boost::system::error_code error; diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index c43c2a422..22f44eeb8 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -45,7 +45,7 @@ private: ServerFinder (); ~ServerFinder (); - void broadcast_thread (); + void search_thread (); void listen_thread (); bool server_found (std::string) const; @@ -56,8 +56,8 @@ private: bool _disabled; - /** Thread to periodically issue broadcasts to find encoding servers */ - boost::thread* _broadcast_thread; + /** Thread to periodically issue broadcasts and requests to find encoding servers */ + boost::thread* _search_thread; /** Thread to listen to the responses from servers */ boost::thread* _listen_thread; -- cgit v1.2.3 From 96a2b6f7ce0be67248cbc612e2ef03ea7d586039 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 6 Jul 2015 14:06:25 +0100 Subject: Search for servers immediately when configuration changes. --- src/lib/server_finder.cc | 16 ++++++++++------ src/lib/server_finder.h | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/lib/server_finder.h') diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index ecda385eb..3eec6597b 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -54,7 +54,7 @@ ServerFinder::~ServerFinder () { _stop = true; - _search_thread->interrupt (); + _search_condition.notify_all (); _search_thread->join (); _listen_io_service.stop (); @@ -106,11 +106,8 @@ try } } - try { - boost::thread::sleep (boost::get_system_time() + boost::posix_time::seconds (10)); - } catch (boost::thread_interrupted& e) { - return; - } + boost::mutex::scoped_lock lm (_search_condition_mutex); + _search_condition.timed_wait (lm, boost::get_system_time() + boost::posix_time::seconds (10)); } } catch (...) @@ -224,5 +221,12 @@ ServerFinder::config_changed (Config::Property what) _servers.clear (); } ServersListChanged (); + search_now (); } } + +void +ServerFinder::search_now () +{ + _search_condition.notify_all (); +} diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index 22f44eeb8..3bb0e03f9 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -53,6 +53,7 @@ private: void handle_accept (boost::system::error_code ec, boost::shared_ptr socket); void config_changed (Config::Property what); + void search_now (); bool _disabled; @@ -68,5 +69,8 @@ private: boost::shared_ptr _listen_acceptor; bool _stop; + boost::condition _search_condition; + boost::mutex _search_condition_mutex; + static ServerFinder* _instance; }; -- cgit v1.2.3