From cad0b08de225602857f64c45c499235ee80a5d9d Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Wed, 25 Mar 2015 14:11:32 +0100 Subject: [PATCH] changed start of pings to time when io_service.run() is called (and not earlier) --- src/host/pingrotate.cpp | 12 ++++++++---- src/host/pingscheduler.cpp | 16 +++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/host/pingrotate.cpp b/src/host/pingrotate.cpp index 64b0587..d01f447 100644 --- a/src/host/pingrotate.cpp +++ b/src/host/pingrotate.cpp @@ -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 diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index 881976a..dbde917 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -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 ) ); } -- 1.7.1