No rescheduling in BoostPinger
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 4 May 2011 15:01:15 +0000 (17:01 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 4 May 2011 15:02:10 +0000 (17:02 +0200)
src/host/boostpinger.cpp
src/host/boostpinger.h

index a67378c..58fe87b 100644 (file)
@@ -200,18 +200,6 @@ void BoostPinger::schedule_timeout_echo_reply()
     );
 }
 
-void BoostPinger::schedule_next_echo_request()
-{
-    // Requests must be sent no less than one second apart.
-    const int echo_request_interval_in_sec = 1;
-    (void) IcmpPacketReceiveTimer.expires_at(
-            TimeSent + seconds( echo_request_interval_in_sec )
-    );
-    IcmpPacketReceiveTimer.async_wait(
-            boost::bind( &BoostPinger::start_send, this )
-    );
-}
-
 void BoostPinger::start_receive()
 {
     // Discard any data already in the buffer.
@@ -226,14 +214,14 @@ void BoostPinger::start_receive()
 
 void BoostPinger::handle_timeout_icmp_packet()
 {
-    if ( RepliesCount == 0 )
+    // Check reply count as the timer handler
+    // is also called by Timer.cancel();
+    if (RepliesCount == 0)
     {
-        print_request_timeout();
+        GlobalLogger.info() << "Request timed out" << endl;
 
         set_ping_status( PingStatus_FailureTimeout );
     }
-
-    schedule_next_echo_request();
 }
 
 void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
@@ -244,11 +232,18 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
 
     istream is( &ReplyBuffer );
     if ( !is )
+    {
+        GlobalLogger.error() << "can't handle ReplyBuffer" << endl;
         return;
+    }
 
     // Decode the reply packet.
     IcmpPacket icmp_packet;
-    is >> icmp_packet;
+    if (!(is >> icmp_packet))
+    {
+        GlobalLogger.error() << "ignoring broken ICMP packet" << endl;
+        return;
+    }
 
     // We can receive all ICMP packets received by the host, so we need to
     // filter out only the echo replies that match the our identifier,
@@ -256,15 +251,9 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
     // ICMP packets from the host we had ping).
     if ( icmp_packet.match(
             IcmpType_EchoReply, Identifier, SequenceNumber,
-            DestinationEndpoint.address()
-    ) )
+            DestinationEndpoint.address())
+    )
     {
-        // If this is the first reply, interrupt the echo reply timeout.
-        if ( RepliesCount == 0 )
-        {
-            (void) IcmpPacketReceiveTimer.cancel();
-        }
-
         ++RepliesCount;
 
         print_echo_reply( icmp_packet, bytes_transferred );
@@ -276,25 +265,16 @@ void BoostPinger::handle_receive_icmp_packet( const size_t &bytes_transferred )
             DestinationEndpoint.address()
     ) )
     {
-        // If this is the first reply, interrupt the echo reply timeout.
-        if ( RepliesCount == 0 )
-        {
-            (void) IcmpPacketReceiveTimer.cancel();
-        }
-
         ++RepliesCount;
-
         print_destination_unreachable( icmp_packet );
 
         set_ping_status( PingStatus_FailureDestinationUnreachable );
+    } else
+    {
+        GlobalLogger.notice() << "unknown ICMP reply" << endl;
     }
 
-    start_receive();
-}
-
-void BoostPinger::print_request_timeout() const
-{
-    GlobalLogger.info() << "Request timed out" << endl;
+    IcmpPacketReceiveTimer.cancel();
 }
 
 void BoostPinger::print_echo_reply(
index 127655b..b0f4d9a 100644 (file)
@@ -42,13 +42,11 @@ private:
     IcmpPacket create_echo_request( const uint16_t sequence_number ) const;
     void send_echo_request( const IcmpPacket &icmp_packet );
     void schedule_timeout_echo_reply();
-    void schedule_next_echo_request();
 
     void start_receive();
     void handle_timeout_icmp_packet();
     void handle_receive_icmp_packet( const std::size_t &bytes_transferred );
 
-    void print_request_timeout() const;
     void print_echo_reply(
             const IcmpPacket &icmp_packet,
             const std::size_t &bytes_transferred