Separated the endpoint creation in a method
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 29 Apr 2011 11:46:38 +0000 (13:46 +0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@intra2net.com>
Fri, 29 Apr 2011 11:51:56 +0000 (13:51 +0200)
src/host/boostpinger.cpp
src/host/boostpinger.h

index d0c836a..c96918f 100644 (file)
@@ -76,17 +76,24 @@ bool BoostPinger::ping( const string &destination_ip )
 {
     BOOST_ASSERT( !destination_ip.empty() );
 
-    uint16_t port = 0;
-    address destination_address = address::from_string( destination_ip );
-    icmp::endpoint destination_endpoint( destination_address, port );
-    DestinationEndpoint = destination_endpoint;
+    set_destination_endpoint( destination_ip );
 
     start_pinger();
 
+    // TODO if we don't block, the PingerStatus will be PingStatus_NotSent for the first time until receive a response
     bool ping_success = (PingerStatus == PingStatus_SuccessReply);
     return ping_success;
 }
 
+void BoostPinger::set_destination_endpoint( const string &destination_ip )
+{
+    BOOST_ASSERT( !destination_ip.empty() );
+
+    uint16_t port = 0;
+    address destination_address = address::from_string( destination_ip );
+    DestinationEndpoint = icmp::endpoint( destination_address, port );
+}
+
 void BoostPinger::start_pinger()
 {
     start_send();
@@ -151,6 +158,7 @@ void BoostPinger::send_echo_request( const IcmpPacket &icmp_packet )
     try
     {
         const_buffers_1 data = request_buffer.data();
+        // Block until send the data
         size_t bytes_sent = Socket.send_to( data, DestinationEndpoint );
         if ( bytes_sent != buffer_size( data ) )
         {
@@ -208,7 +216,7 @@ void BoostPinger::start_receive()
     // Discard any data already in the buffer.
     ReplyBuffer.consume( ReplyBuffer.size() );
 
-    // Wait for a reply. We prepare the buffer to receive up to 64KB.
+    // Waiting for a reply. We prepare the buffer to receive up to 64KB.
     Socket.async_receive(
             ReplyBuffer.prepare( 65536 ),
             boost::bind( &BoostPinger::handle_receive_icmp_packet, this, _2 )
index d5b902a..09adb07 100644 (file)
@@ -35,6 +35,7 @@ private:
     };
 
 private:
+    void set_destination_endpoint( const std::string &destination_ip );
     void start_pinger();
     void stop_pinger();