From: Christian Herdtweck Date: Mon, 12 Jan 2015 14:37:13 +0000 (+0100) Subject: do not wait for IcmpEchoReply if sending of IcmpEchoRequest has failed completely X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=ba5d41fe9912272c55b7f84ad77ba71211ae3d2a;p=pingcheck do not wait for IcmpEchoReply if sending of IcmpEchoRequest has failed completely --- diff --git a/src/icmp/icmppinger.cpp b/src/icmp/icmppinger.cpp index a4e05a6..bcf73a5 100644 --- a/src/icmp/icmppinger.cpp +++ b/src/icmp/icmppinger.cpp @@ -118,8 +118,13 @@ void IcmpPinger::ping( 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 ) @@ -131,7 +136,7 @@ void IcmpPinger::set_destination_endpoint( const string &destination_ip ) DestinationEndpoint = icmp::endpoint( destination_address, port ); } -void IcmpPinger::start_send() +bool IcmpPinger::start_send() { ++SequenceNumber; @@ -139,10 +144,10 @@ void IcmpPinger::start_send() 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 ); @@ -159,6 +164,7 @@ void IcmpPinger::send_echo_request( const IcmpPacketItem icmp_packet ) BOOST_ASSERT( !dest_address_string.empty() ); // Send the request + size_t bytes_sent = 0; try { GlobalLogger.info() @@ -166,7 +172,7 @@ void IcmpPinger::send_echo_request( const IcmpPacketItem icmp_packet ) << ": 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() @@ -182,6 +188,8 @@ void IcmpPinger::send_echo_request( const IcmpPacketItem icmp_packet ) } schedule_timeout_echo_reply(); + + return (bytes_sent > 0); } void IcmpPinger::schedule_timeout_echo_reply() diff --git a/src/icmp/icmppinger.h b/src/icmp/icmppinger.h index ce0c0a7..715ab62 100644 --- a/src/icmp/icmppinger.h +++ b/src/icmp/icmppinger.h @@ -48,8 +48,8 @@ public: private: void set_destination_endpoint( const std::string &destination_ip ); - void start_send(); - void send_echo_request( const IcmpPacketItem icmp_packet ); + bool start_send(); + bool send_echo_request( const IcmpPacketItem icmp_packet ); void schedule_timeout_echo_reply(); void handle_ping_done();