From: Guilherme Maciel Ferreira Date: Tue, 2 Aug 2011 10:33:05 +0000 (-0300) Subject: Changed the handle_timeout() method to handle_ping_done() X-Git-Tag: v1.1^2~33 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=bd66be8f6385101addac5b80a148859be0d90925;p=pingcheck Changed the handle_timeout() method to handle_ping_done() - now it calls the ping call back function - and do not schedule the next ping anymore, let it to the callback responsability --- diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index ec74576..41cd54c 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -237,19 +237,29 @@ void TcpPinger::schedule_timeout_rst_reply() TimeSent + seconds( RstReplyTimeoutInSec ) ); TcpSegmentReceiveTimer.async_wait( - boost::bind( &TcpPinger::handle_timeout, this ) + boost::bind( &TcpPinger::handle_ping_done, this ) ); } -void TcpPinger::handle_timeout() +/** + * @brief Gets called when the ping is finished: Either on timeout or on ping reply + * + * @return void + **/ +void TcpPinger::handle_ping_done() { - ReceivedReply = false; - TcpSegmentReceiveTimer.expires_at( - TimeSent + seconds( RstReplyTimeoutInSec ) - ); - TcpSegmentReceiveTimer.async_wait( - boost::bind( &TcpPinger::start_send, this ) - ); + // Check ReceivedReply as the timer handler + // is also called by Timer.cancel(); + if ( ReceivedReply == false ) + { + GlobalLogger.info() << "Request timed out" << endl; + + set_ping_status( PingStatus_FailureTimeout ); + } + + // Call ping-done handler + bool ping_success = (PingerStatus == PingStatus_SuccessReply); + PingDoneCallback(ping_success); } void TcpPinger::start_receive() diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index c90bab7..7bb1be8 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -75,7 +75,7 @@ private: ) const; void send_ack_request( const TcpHeader &tcp_header ); void schedule_timeout_rst_reply(); - void handle_timeout(); + void handle_ping_done(); void start_receive(); void handle_receive_tcp_segment( const std::size_t &bytes_transferred );