From 03f12d85bbfff34171be15f1ec9f67e3e49fe53f Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Thu, 5 May 2011 09:36:44 +0200 Subject: [PATCH] Turn RepliesCount into ReceivedReply flag --- src/host/boostpinger.cpp | 12 ++++++------ src/host/boostpinger.h | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/host/boostpinger.cpp b/src/host/boostpinger.cpp index cc25af8..b23ff20 100644 --- a/src/host/boostpinger.cpp +++ b/src/host/boostpinger.cpp @@ -49,7 +49,7 @@ BoostPinger::BoostPinger( SequenceNumber( 0 ), TimeSent( microsec_clock::universal_time() ), ReplyBuffer(), - RepliesCount( 0 ), + ReceivedReply( false ), EchoReplyTimeoutInSec( echo_reply_timeout_in_sec ), PingerStatus( PingStatus_NotSent ), PingDoneCallback() @@ -167,7 +167,7 @@ void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet ) void BoostPinger::schedule_timeout_echo_reply() { // Wait up to N seconds for a reply. - RepliesCount = 0; + ReceivedReply = false; (void) IcmpPacketReceiveTimer.expires_at( TimeSent + seconds( EchoReplyTimeoutInSec ) ); @@ -195,9 +195,9 @@ void BoostPinger::start_receive() **/ void BoostPinger::handle_ping_done() { - // Check reply count as the timer handler + // Check ReceivedReply as the timer handler // is also called by Timer.cancel(); - if (RepliesCount == 0) + if (ReceivedReply == false) { GlobalLogger.info() << "Request timed out" << endl; @@ -239,7 +239,7 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) DestinationEndpoint.address()) ) { - ++RepliesCount; + ReceivedReply = true; print_echo_reply( icmp_packet, bytes_transferred ); @@ -250,7 +250,7 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred ) DestinationEndpoint.address() ) ) { - ++RepliesCount; + ReceivedReply = true; print_destination_unreachable( icmp_packet ); set_ping_status( PingStatus_FailureDestinationUnreachable ); diff --git a/src/host/boostpinger.h b/src/host/boostpinger.h index 6d337fe..15e2212 100644 --- a/src/host/boostpinger.h +++ b/src/host/boostpinger.h @@ -81,13 +81,14 @@ private: boost::posix_time::ptime TimeSent; /// the buffer where the data received will be placed boost::asio::streambuf ReplyBuffer; + /// Flag to indicate if we got a reply or not /// number of replies to the ICMP echo request - int RepliesCount; + bool ReceivedReply; /// the amount of time to wait for the reply int EchoReplyTimeoutInSec; /// the status of the pinger BoostPinger::PingStatus PingerStatus; - + /// Callback to notify when the ping is done (got reply/timeout) boost::function< void(bool) > PingDoneCallback; }; -- 1.7.1