//-----------------------------------------------------------------------------
BoostPinger::BoostPinger(
- io_service &io_serv,
string source_network_interface,
const int echo_reply_timeout_in_sec
) :
- IoService( io_serv ),
+ IoService(),
DestinationEndpoint(),
- Socket( io_serv, icmp::v4() ),
- IcmpPacketReceiveTimer( io_serv ),
+ Socket( IoService, icmp::v4() ),
+ IcmpPacketReceiveTimer( IoService ),
Identifier(0),
SequenceNumber( 0 ),
TimeSent( microsec_clock::universal_time() ),
{
BOOST_ASSERT( !destination_ip.empty() );
+ // Prepare ping
+ IoService.reset();
+ PingerStatus = PingStatus_NotSent;
+
set_destination_endpoint( destination_ip );
// if start_pinger() does not block, the PingerStatus will be equal to
{
public:
BoostPinger(
- boost::asio::io_service &io_serv,
std::string source_network_interface,
const int echo_reply_timeout_in_sec
);
private:
/// io service object, which has the loop event
- boost::asio::io_service &IoService;
+ boost::asio::io_service IoService;
/// the destination host
boost::asio::ip::icmp::endpoint DestinationEndpoint;
/// the socket object
PingIntervalInSec( ping_interval_in_sec ),
IpList( destination_address, nameserver ),
HostAnalyzer( destination_address, ping_fail_percentage_limit, link_analyzer ),
+ Pinger(LocalNetworkInterfaceName, 5),
Thread()
{
}
return true;
}
-bool PingScheduler::ping( const string &destination_ip ) const
+bool PingScheduler::ping( const string &destination_ip )
{
BOOST_ASSERT( !destination_ip.empty() );
- io_service io_serv;
- int echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
-
- BoostPinger pinger(
- io_serv,
- LocalNetworkInterfaceName,
- echo_reply_timeout_in_sec
- );
- return pinger.ping( destination_ip );
+ return Pinger.ping( destination_ip );
}
void PingScheduler::setup_next_ping()
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
+#include "host/boostpinger.h"
#include "dns/dnsresolver.h"
#include "link/linkstatusanalyzer.h"
#include "host/hoststatusanalyzer.h"
void stop_pinging();
bool resolve_ping_address();
- bool ping( const std::string &destination_ip ) const;
+ bool ping( const std::string &destination_ip );
void setup_next_ping();
void schedule_next_ping();
DnsResolver IpList;
/// object responsible to evaluate the status of the host
HostStatusAnalyzer HostAnalyzer;
+ /// Internal boost pinger object
+ BoostPinger Pinger;
/// thread object
boost::thread Thread;