{
GlobalLogger.info() << "Delaying first ping by " << FirstDelay << "s";
(void) NextPingTimer.expires_from_now( seconds( FirstDelay ) );
- NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this ) );
+ NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this,
+ boost::asio::placeholders::error ) );
}
else
- resolve_and_ping();
+ resolve_and_ping(boost::system::error_code());
}
* call ping;
* If name resolution fails too often, reports this to HostAnalyzer
*/
-void PingScheduler::resolve_and_ping()
+void PingScheduler::resolve_and_ping(const boost::system::error_code &error)
{
+ if ( error )
+ {
+ if ( error == boost::asio::error::operation_aborted )
+ GlobalLogger.error() << "Timer for resolve_and_ping was cancelled! Stopping" << endl;
+ else
+ GlobalLogger.error() << "Received error " << error
+ << " waiting for resolve_and_ping! Stopping" << endl;
+ return;
+ }
+
bool ips_up_to_date = EverHadAnyIP && !Ping->expired_resolved_ip();
// determine if address resolution is required
HostAnalyzer.report_dns_resolution_failure();
}
(void) NextAddressTimer.expires_from_now( seconds( AddressResolveIntervalInSec ) );
- NextAddressTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this ) );
+ NextAddressTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this,
+ boost::asio::placeholders::error ) );
}
}
// schedule next ping
(void) NextPingTimer.expires_from_now( seconds( PingIntervalInSec ) );
- NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this ) );
+ NextPingTimer.async_wait( bind( &PingScheduler::resolve_and_ping, this,
+ boost::asio::placeholders::error ) );
}
void PingScheduler::update_ping_interval()
// Methods
//
- void resolve_and_ping();
+ void resolve_and_ping(const boost::system::error_code &error);
bool resolve_address();
void force_address_resolution();
TimeSent + seconds( EchoReplyTimeoutInSec )
);
IcmpPacketReceiveTimer.async_wait(
- boost::bind( &IcmpPinger::handle_ping_done, this )
+ boost::bind( &IcmpPinger::handle_timeout, this, boost::asio::placeholders::error )
);
}
*
* @return void
**/
-void IcmpPinger::handle_ping_done()
+void IcmpPinger::handle_timeout(const boost::system::error_code& error)
{
+ if (error)
+ {
+ if ( error == boost::asio::error::operation_aborted )
+ {
+ if (! ReplyReceived)
+ GlobalLogger.notice() << "Timer waiting for ICMP echo reply was cancelled!" << endl;
+ // otherwise probably called by IcmpPacketReceiveTimer.cancel in handle_receive_icmp_packet!
+ }
+ else
+ GlobalLogger.notice() << "Error " << error << " waiting for ICMP echo reply!" << endl;
+
+ // Still continue with rest of function, so PingStatus is updated and Callback executed
+ // when timer was cancelled
+ }
+
// Check ReplyReceived as the timer handler
// is also called by Timer.cancel();
if ( !ReplyReceived )
// Waiting for a reply, We prepare the buffer to receive up to SOCKET_BUFFER_SIZE bytes
Socket.async_receive(
ReplyBuffer.prepare( SOCKET_BUFFER_SIZE ),
- boost::bind( &IcmpPinger::handle_receive_icmp_packet, this, _1, _2 )
+ boost::bind( &IcmpPinger::handle_receive_icmp_packet, this, boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred )
);
ReceiveHandlerInPlace = true;
}
bool start_send();
bool send_echo_request( const IcmpPacketItem icmp_packet );
void schedule_timeout_echo_reply();
- void handle_ping_done();
+ void handle_timeout(const boost::system::error_code &error);
void start_receive();
void handle_receive_icmp_packet( const boost::system::error_code &error,