From bd66be8f6385101addac5b80a148859be0d90925 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 2 Aug 2011 07:33:05 -0300 Subject: [PATCH] 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 --- src/tcp/tcppinger.cpp | 28 +++++++++++++++++++--------- src/tcp/tcppinger.h | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) 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 ); -- 1.7.1