) :
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()
destination_port,
nameserver
);
+ AddressResolvedFirstTime = false;
}
/**
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();
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) );
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()
void update_ping_address();
bool resolve_ping_address();
+ void schedule_address_resolve();
void ping();
void ping_done_handler(bool ping_success);
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;
};