From: Thomas Jarosch Date: Wed, 4 May 2011 15:01:15 +0000 (+0200) Subject: No rescheduling in BoostPinger X-Git-Tag: v1.0~23 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=83e1eae2d8eed87b44687cf3de353c082d85ebd0;p=pingcheck No rescheduling in BoostPinger --- diff --git a/src/host/boostpinger.cpp b/src/host/boostpinger.cpp index a67378c..58fe87b 100644 --- a/src/host/boostpinger.cpp +++ b/src/host/boostpinger.cpp @@ -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( diff --git a/src/host/boostpinger.h b/src/host/boostpinger.h index 127655b..b0f4d9a 100644 --- a/src/host/boostpinger.h +++ b/src/host/boostpinger.h @@ -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