#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/foreach.hpp>
+#include <boost/system/system_error.hpp>
#include <logfunc.hpp>
bytes_sent = PacketDistributor->get_socket()->send_to( data, DestinationEndpoint );
if ( bytes_sent != buffer_size( data ) )
{
- GlobalLogger.error() << LogPrefix << "fail sending ping data."
- << endl;
+ GlobalLogger.error() << LogPrefix << "fail sending ping data. Only"
+ << bytes_sent << " of " << buffer_size(data)
+ << " bytes were sent!" << endl;
}
+
+ ReplyReceived = false;
+ schedule_timeout_echo_reply();
+ }
+ catch ( const boost::system::system_error &boost_err )
+ {
+ boost::system::error_code err_code = boost_err.code();
+ GlobalLogger.error() << LogPrefix << "fail sending ping data: "
+ << boost_err.what() << " (code " << err_code.value()
+ << ", category " << err_code.category().name() << ")" << endl;
+
+ // do not wait for timeout but fail at once
+ set_ping_status(PingStatus_SendFailed);
+ ReplyReceived = true; // flag for handler to leave ping status as is
+ //handle_timeout( err_code );
+ handle_timeout( boost::system::error_code() );
}
catch ( const exception &ex )
{
- GlobalLogger.error() << LogPrefix << "fail sending ping data. "
+ GlobalLogger.error() << LogPrefix << "fail sending ping data: "
<< ex.what() << endl;
+
+ // do not wait for timeout but fail at once
+ set_ping_status(PingStatus_SendFailed);
+ ReplyReceived = true; // flag for handler to leave ping status as is
+ handle_timeout( boost::system::error_code() );
}
+ catch ( ... )
+ {
+ GlobalLogger.error() << LogPrefix << "fail sending ping data: "
+ << "Unknown exception" << endl;
- ReplyReceived = false;
- schedule_timeout_echo_reply();
+ // do not wait for timeout but fail at once
+ set_ping_status(PingStatus_SendFailed);
+ ReplyReceived = true; // flag for handler to leave ping status as is
+ handle_timeout( boost::system::error_code() );
+ }
return (bytes_sent > 0);
}
<< " waiting for ICMP echo reply!" << endl;
set_ping_status( PingStatus_FailureAsyncError );
}
+ // could check here for more details if error is forwarded from
+ // send_echo_request
// Still continue with rest of function, so PingStatus is updated and Callback executed
// when timer was cancelled
set_ping_status( PingStatus_FailureTimeout );
}
+ // otherwise assume that ping status was set already
// Call ping-done handler
PingDoneCallback( PingerStatus, static_cast<long>(