Search for servers immediately when configuration changes.
authorCarl Hetherington <cth@carlh.net>
Mon, 6 Jul 2015 13:06:25 +0000 (14:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 Jul 2015 13:06:25 +0000 (14:06 +0100)
src/lib/server_finder.cc
src/lib/server_finder.h

index ecda385eb4782c69f0e09922840f61ecd44707a6..3eec6597b55df1d92125b1785ad2998a104adb33 100644 (file)
@@ -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 ();
+}
index 22f44eeb8a06641d96aaec0bbac65fb5bebe8d74..3bb0e03f9de103d498c35637d40c355f3b64e107 100644 (file)
@@ -53,6 +53,7 @@ private:
        void handle_accept (boost::system::error_code ec, boost::shared_ptr<Socket> socket);
 
        void config_changed (Config::Property what);
+       void search_now ();
 
        bool _disabled;
 
@@ -68,5 +69,8 @@ private:
        boost::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
        bool _stop;
 
+       boost::condition _search_condition;
+       boost::mutex _search_condition_mutex;
+
        static ServerFinder* _instance;
 };