void IcmpPinger::ping(
const address &destination_ip,
const uint16_t /*destination_port*/, // the ICMP protocol does not use ports
- function<void(bool)> ping_done_callback
+ function<void(PingStatus)> ping_done_callback
)
{
PingDoneCallback = ping_done_callback;
/**
* @brief Gets called when the ping is finished: Either on timeout or on ping reply
*
- * @return void
+ * @return void (but calls PingDoneCallback)
**/
void IcmpPinger::handle_timeout(const boost::system::error_code& error)
{
if ( error == boost::asio::error::operation_aborted )
{
if (! ReplyReceived)
+ {
GlobalLogger.notice() << LogPrefix
<< "Timer waiting for ICMP echo reply was cancelled!"
<< endl;
+ set_ping_status( PingStatus_FailureAsyncCancel );
+ }
// otherwise probably called by IcmpPacketReceiveTimer.cancel in
// handle_receive_icmp_packet!
}
else
+ {
GlobalLogger.notice() << LogPrefix << "Error " << error
<< " waiting for ICMP echo reply!" << endl;
+ set_ping_status( PingStatus_FailureAsyncError );
+ }
// 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 )
- {
+ else if ( !ReplyReceived )
+ { // Check ReplyReceived since the timer handler is also called by Timer.cancel();
GlobalLogger.info() << LogPrefix << "Request timed out" << endl;
set_ping_status( PingStatus_FailureTimeout );
}
// Call ping-done handler
- bool ping_success = (PingerStatus == PingStatus_SuccessReply);
- PingDoneCallback( ping_success );
+ PingDoneCallback( PingerStatus );
}