set_destination_endpoint( destination_ip );
- start_send();
- start_receive();
+ if (start_send())
+ start_receive();
+ else
+ GlobalLogger.info()
+ << DestinationEndpoint.address().to_string()
+ << ": not scheduling receive since send failed." << endl;
+ // there might still be an old handler in place... cancel?
}
void IcmpPinger::set_destination_endpoint( const string &destination_ip )
DestinationEndpoint = icmp::endpoint( destination_address, port );
}
-void IcmpPinger::start_send()
+bool IcmpPinger::start_send()
{
++SequenceNumber;
Protocol, Identifier, SequenceNumber );
BOOST_ASSERT( PingerStatus == PingStatus_NotSent );
- send_echo_request( icmp_packet_echo_request );
+ return send_echo_request( icmp_packet_echo_request );
}
-void IcmpPinger::send_echo_request( const IcmpPacketItem icmp_packet )
+bool IcmpPinger::send_echo_request( const IcmpPacketItem icmp_packet )
{
boost::asio::streambuf request_buffer;
ostream os( &request_buffer );
BOOST_ASSERT( !dest_address_string.empty() );
// Send the request
+ size_t bytes_sent = 0;
try
{
GlobalLogger.info()
<< ": sending ping" << endl;
const_buffers_1 data = request_buffer.data();
// Block until send the data
- size_t bytes_sent = Socket.send_to( data, DestinationEndpoint );
+ bytes_sent = Socket.send_to( data, DestinationEndpoint );
if ( bytes_sent != buffer_size( data ) )
{
GlobalLogger.error()
}
schedule_timeout_echo_reply();
+
+ return (bytes_sent > 0);
}
void IcmpPinger::schedule_timeout_echo_reply()