Changed the handle_timeout() method to handle_ping_done()
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 2 Aug 2011 10:33:05 +0000 (07:33 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 2 Aug 2011 10:33:05 +0000 (07:33 -0300)
- 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
src/tcp/tcppinger.h

index ec74576..41cd54c 100644 (file)
@@ -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()
index c90bab7..7bb1be8 100644 (file)
@@ -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 );