{
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();
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 ) )
{
// 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 )