From: Christian Herdtweck Date: Thu, 8 May 2014 12:51:37 +0000 (+0200) Subject: if DNS request at start of ping fails, re-schedule further requests; originally faile... X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=3f6ba9249f48a76c2fd35a83b8bf59b50a94cd5d;p=pingcheck if DNS request at start of ping fails, re-schedule further requests; originally failed at once and never tried again --- diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index 22502ac..9306467 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -71,8 +71,10 @@ PingScheduler::PingScheduler( ) : IoService(), NextPingTimer( IoService ), + NextAddressTimer( IoService ), TimeSentLastPing( microsec_clock::universal_time() ), PingIntervalInSec( ping_interval_in_sec ), + AddressResolveIntervalInSec( ping_interval_in_sec ), HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ), Ping(), Thread() @@ -92,6 +94,7 @@ PingScheduler::PingScheduler( destination_port, nameserver ); + AddressResolvedFirstTime = false; } /** @@ -135,8 +138,12 @@ bool PingScheduler::start_pinging() bool address_resolved = resolve_ping_address(); if ( !address_resolved ) { - return false; + //return false; + // new behaviour: try again later + schedule_address_resolve(); } + else + AddressResolvedFirstTime = true; setup_next_ping(); @@ -181,6 +188,17 @@ bool PingScheduler::resolve_ping_address() return true; } +void PingScheduler::schedule_address_resolve() +{ + if (resolve_ping_address()) + AddressResolvedFirstTime = true; + else + { + (void) NextAddressTimer.expires_from_now( seconds( AddressResolveIntervalInSec ) ); + NextAddressTimer.async_wait( bind( &PingScheduler::schedule_address_resolve, this ) ); + } +} + void PingScheduler::ping() { Ping->ping( boost::bind(&PingScheduler::ping_done_handler, this, _1) ); @@ -196,11 +214,14 @@ void PingScheduler::ping_done_handler( bool ping_success ) void PingScheduler::setup_next_ping() { - BOOST_ASSERT( 1 <= Ping->get_resolved_ip_count() ); + if (AddressResolvedFirstTime) + { + BOOST_ASSERT( 1 <= Ping->get_resolved_ip_count() ); - update_ping_address(); + update_ping_address(); - ping(); + ping(); + } } void PingScheduler::schedule_next_ping() diff --git a/src/host/pingscheduler.h b/src/host/pingscheduler.h index e6bf01e..e29af24 100644 --- a/src/host/pingscheduler.h +++ b/src/host/pingscheduler.h @@ -74,6 +74,7 @@ private: void update_ping_address(); bool resolve_ping_address(); + void schedule_address_resolve(); void ping(); void ping_done_handler(bool ping_success); @@ -93,16 +94,22 @@ private: boost::asio::io_service IoService; /// Timer to trigger the next ping boost::asio::deadline_timer NextPingTimer; + /// Timer to trigger the next attempt to resolve addresses + boost::asio::deadline_timer NextAddressTimer; /// Keeps track of the time when the last ping was send boost::posix_time::ptime TimeSentLastPing; /// Interval between each ping to the same host PingInterval PingIntervalInSec; + /// Interval between attempts to resolve host address + PingInterval AddressResolveIntervalInSec; /// Object responsible to evaluate the status of the host HostStatus HostAnalyzer; /// Internal boost pinger object PingRotateItem Ping; /// Thread object boost::thread Thread; + /// flag that address is resolved, so can start pinging + bool AddressResolvedFirstTime; };