changed start of pings to time when io_service.run() is called (and not earlier)
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 25 Mar 2015 13:11:32 +0000 (14:11 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 25 Mar 2015 13:11:32 +0000 (14:11 +0100)
src/host/pingrotate.cpp
src/host/pingscheduler.cpp

index 64b0587..d01f447 100644 (file)
@@ -159,12 +159,16 @@ void PingRotate::update_ping_protocol()
 void PingRotate::get_next_ping_protocol()
 {
     PingProtocol ping_protocol = ProtocolRotate.front();
-    ProtocolRotate.pop_front();
-    ProtocolRotate.push_back(ping_protocol);
+    if ( 1 <= ProtocolList.size() )
+    {
+        PingProtocol ping_protocol = ProtocolList.front();
+
+        ProtocolList.pop_front();
 
-    Ping = PingerFactory::createPinger( ping_protocol, IoService, NetworkInterfaceName, PingReplyTimeout );
+        Ping = PingerFactory::createPinger( ping_protocol, IoService, NetworkInterfaceName, PingReplyTimeout );
 
-    update_dns_resolver( ping_protocol );
+        update_dns_resolver( ping_protocol );
+    }
 }
 
 bool PingRotate::can_change_ping_protocol() const
index 881976a..dbde917 100644 (file)
@@ -127,21 +127,23 @@ void PingScheduler::stop_pinging()
 
 /**
  * @brief Start into infinite loop of calls to resolve_and_ping
- *   IoService which is started here and can be stopped through stop_pinging
+ *
+ * Does not start yet but set NextPingTimer (possibly to 0), so action starts
+ *   when io_service is started
  */
 void PingScheduler::start_pinging()
 {
+    // assume that even at re-start there is no IP known
     EverHadAnyIP = false;
 
     if ( FirstDelay > 0 )
-    {
         GlobalLogger.info() << "Delaying first ping by " << FirstDelay << "s";
-        (void) NextPingTimer.expires_from_now( seconds( FirstDelay ) );
-        NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this,
-                                              boost::asio::placeholders::error ) );
-    }
     else
-        resolve_and_ping(boost::system::error_code());
+        GlobalLogger.info() << "Schedule ping as soon as possible";
+
+    (void) NextPingTimer.expires_from_now( seconds( FirstDelay ) );
+    NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this,
+                                          boost::asio::placeholders::error ) );
 }