Turn RepliesCount into ReceivedReply flag
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 5 May 2011 07:36:44 +0000 (09:36 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 5 May 2011 07:36:44 +0000 (09:36 +0200)
src/host/boostpinger.cpp
src/host/boostpinger.h

index cc25af8..b23ff20 100644 (file)
@@ -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 );
index 6d337fe..15e2212 100644 (file)
@@ -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;
 };