From 39e10382681007220d97ff4140d41c7c181faddf Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Fri, 29 Apr 2011 13:46:38 +0200 Subject: [PATCH] Separated the endpoint creation in a method --- src/host/boostpinger.cpp | 18 +++++++++++++----- src/host/boostpinger.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/host/boostpinger.cpp b/src/host/boostpinger.cpp index d0c836a..c96918f 100644 --- a/src/host/boostpinger.cpp +++ b/src/host/boostpinger.cpp @@ -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 ) diff --git a/src/host/boostpinger.h b/src/host/boostpinger.h index d5b902a..09adb07 100644 --- a/src/host/boostpinger.h +++ b/src/host/boostpinger.h @@ -35,6 +35,7 @@ private: }; private: + void set_destination_endpoint( const std::string &destination_ip ); void start_pinger(); void stop_pinger(); -- 1.7.1