summaryrefslogtreecommitdiff
path: root/src/lib/server_finder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-07-06 13:37:35 +0100
committerCarl Hetherington <cth@carlh.net>2015-07-06 13:37:35 +0100
commit7ae514af0aea1b953a93f88d5507e6c1dd675908 (patch)
treed14505318a517a3f86944fc194d9b4f5ce05a3e3 /src/lib/server_finder.cc
parent8fb1e87dc19210dc29a1eabc4e410af4a3fb740b (diff)
Better updating of servers list when things change.
Diffstat (limited to 'src/lib/server_finder.cc')
-rw-r--r--src/lib/server_finder.cc35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc
index ac4651657..a189ae802 100644
--- a/src/lib/server_finder.cc
+++ b/src/lib/server_finder.cc
@@ -47,6 +47,7 @@ ServerFinder::ServerFinder ()
{
_broadcast_thread = new boost::thread (boost::bind (&ServerFinder::broadcast_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 ()
@@ -172,7 +173,7 @@ ServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Socket> so
boost::mutex::scoped_lock lm (_mutex);
_servers.push_back (sd);
}
- emit (boost::bind (boost::ref (ServerFound), sd));
+ emit (boost::bind (boost::ref (ServersListChanged)));
}
start_accept ();
@@ -190,19 +191,6 @@ ServerFinder::server_found (string ip) const
return i != _servers.end ();
}
-boost::signals2::connection
-ServerFinder::connect (boost::function<void (ServerDescription)> fn)
-{
- boost::mutex::scoped_lock lm (_mutex);
-
- /* Emit the current list of servers */
- for (list<ServerDescription>::iterator i = _servers.begin(); i != _servers.end(); ++i) {
- fn (*i);
- }
-
- return ServerFound.connect (fn);
-}
-
ServerFinder*
ServerFinder::instance ()
{
@@ -219,3 +207,22 @@ ServerFinder::drop ()
delete _instance;
_instance = 0;
}
+
+list<ServerDescription>
+ServerFinder::servers () const
+{
+ boost::mutex::scoped_lock lm (_mutex);
+ return _servers;
+}
+
+void
+ServerFinder::config_changed (Config::Property what)
+{
+ if (what == Config::USE_ANY_SERVERS || what == Config::SERVERS) {
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ _servers.clear ();
+ }
+ ServersListChanged ();
+ }
+}