*/
PingerItem PingerFactory::createPinger(
const PingProtocol protocol,
- io_service &io_serv,
+ const shared_ptr<io_service> io_serv,
const string &network_interface
)
{
*/
PingerItem PingerFactory::createPinger(
const PingProtocolList &protocol_list,
- io_service &io_serv,
+ const shared_ptr<io_service> io_serv,
const string &network_interface
)
{
public:
static PingerItem createPinger(
const PingProtocol protocol,
- boost::asio::io_service &io_serv,
+ const boost::shared_ptr<boost::asio::io_service> io_serv,
const std::string &network_interface
);
static PingerItem createPinger(
const PingProtocolList &protocol_list,
- boost::asio::io_service &io_serv,
+ const boost::shared_ptr<boost::asio::io_service> io_serv,
const std::string &network_interface
);
using namespace std;
using boost::asio::io_service;
using boost::function;
+using boost::shared_ptr;
//-----------------------------------------------------------------------------
// PingRotate
* host. The protocols will be used in the order they are in the list.
*/
PingRotate::PingRotate(
- io_service &io_serv,
+ const shared_ptr<io_service> io_serv,
const string &network_interface,
PingProtocolList protocol_rotation_list
) :
#include <boost/asio.hpp>
#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
#include "host/pinger.h"
#include "host/pingprotocol.h"
{
public:
PingRotate(
- boost::asio::io_service &io_serv,
+ const boost::shared_ptr<boost::asio::io_service> io_serv,
const std::string &network_interface,
PingProtocolList protocol_rotation_list
);
//
/// The IO service object, which has the loop event
- boost::asio::io_service &IoService;
+ boost::shared_ptr<boost::asio::io_service> IoService;
/// The network interface name
std::string NetworkInterfaceName;
/// The list of protocols to ping
using boost::posix_time::ptime;
using boost::posix_time::seconds;
using boost::thread;
+using boost::shared_ptr;
using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
BOOST_ASSERT( (0 <= ping_fail_percentage_limit) && (ping_fail_percentage_limit <= 100) );
BOOST_ASSERT( !nameserver.empty() );
- Ping = PingerFactory::createPinger( ping_protocol_list, IoService, network_interface );
+ shared_ptr<io_service> io_serv( &IoService );
+
+ Ping = PingerFactory::createPinger( ping_protocol_list, io_serv, network_interface );
}
/**
bool address_resolved = resolve_ping_address();
if ( !address_resolved )
{
- GlobalLogger.error() << "Error: could not update host "
- "IP, may use outdated address" << endl;
+ GlobalLogger.error() << "Error: could not update host IP, may use outdated address"
+ << endl;
}
}
string destination_ip = IpList.get_next_ip();
+
ping( destination_ip, DestinationPort );
}
{
PingIntervalInSec.speed_up();
- GlobalLogger.info() << "- Speeding up ping interval to: "
- << PingIntervalInSec << "s" << endl;
+ GlobalLogger.info() << "- Speeding up ping interval to: " << PingIntervalInSec << "s"
+ << endl;
}
else
{
PingIntervalInSec.back_to_original();
- GlobalLogger.info() << "- Stick to the original ping interval: "
- << PingIntervalInSec << "s" << endl;
+ GlobalLogger.info() << "- Stick to the original ping interval: " << PingIntervalInSec << "s"
+ << endl;
}
}
ptime now = microsec_clock::universal_time();
time_resolution_traits_adapted64_impl::int_type elapsed_time_in_sec =
(now - TimeSentLastPing).total_seconds();
- GlobalLogger.info() << "- Time elapsed since last ping: "
- << elapsed_time_in_sec << "s" << endl;
+ GlobalLogger.info() << "- Time elapsed since last ping: " << elapsed_time_in_sec << "s" << endl;
TimeSentLastPing = microsec_clock::universal_time();
}
using boost::function;
using boost::posix_time::microsec_clock;
using boost::posix_time::seconds;
+using boost::shared_ptr;
using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
* @param echo_reply_timeout_in_sec The amount of time to wait for a reply.
*/
IcmpPinger::IcmpPinger(
- io_service &io_serv,
+ const shared_ptr<io_service> io_serv,
const icmp::socket::protocol_type &protocol,
const string &source_network_interface,
const int echo_reply_timeout_in_sec
IoService( io_serv ),
DestinationEndpoint(),
Protocol( protocol ),
- Socket( IoService, Protocol ),
+ Socket( *IoService, Protocol ),
NetInterface( source_network_interface, Socket ),
- IcmpPacketReceiveTimer( IoService ),
+ IcmpPacketReceiveTimer( *IoService ),
Identifier( 0 ),
SequenceNumber( 0 ),
TimeSent( microsec_clock::universal_time() ),
#include <boost/asio.hpp>
#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
#include "host/networkinterface.hpp"
#include "host/pinger.h"
{
public:
IcmpPinger(
- boost::asio::io_service &io_serv,
+ const boost::shared_ptr<boost::asio::io_service> io_serv,
const boost::asio::ip::icmp::socket::protocol_type &protocol,
const std::string &source_network_interface,
const int echo_reply_timeout_in_sec
private:
/// The IO service object, which has the loop event
- boost::asio::io_service &IoService;
+ boost::shared_ptr<boost::asio::io_service> IoService;
/// The destination host
boost::asio::ip::icmp::endpoint DestinationEndpoint;
/// Network layer protocol used to ping, IPv4 or IPv6
using boost::posix_time::microsec_clock;
using boost::posix_time::ptime;
using boost::posix_time::seconds;
+using boost::shared_ptr;
using I2n::Logger::GlobalLogger;
//-----------------------------------------------------------------------------
* @param echo_reply_timeout_in_sec The amount of time to wait for a reply.
*/
TcpPinger::TcpPinger(
- io_service &io_serv,
+ const shared_ptr<io_service> io_serv,
const tcp_raw_protocol::socket::protocol_type &protocol,
const string &source_network_interface_name,
const int rst_reply_timeout_in_sec
IoService( io_serv ),
DestinationEndpoint(),
Protocol( protocol ),
- Socket( IoService, Protocol ),
+ Socket( *IoService, Protocol ),
NetInterface( source_network_interface_name, Socket ),
- TcpSegmentReceiveTimer( IoService ),
+ TcpSegmentReceiveTimer( *IoService ),
Identifier( 0 ),
SequenceNumber( 0 ),
TimeSent( microsec_clock::universal_time() ),
#include <boost/asio.hpp>
#include <boost/asio/ip/tcp_raw_protocol.hpp>
#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
#include "host/networkinterface.hpp"
#include "host/pinger.h"
{
public:
TcpPinger(
- boost::asio::io_service &io_service,
+ const boost::shared_ptr<boost::asio::io_service> io_serv,
const boost::asio::ip::tcp_raw_protocol::socket::protocol_type &protocol,
const std::string &source_network_interface_name,
const int rst_reply_timeout_in_sec
void set_ping_status( PingStatus ping_status );
private:
- /// io service object, which has the loop event
- boost::asio::io_service &IoService;
- /// the destination host
+ /// IO service object, which has the loop event
+ boost::shared_ptr<boost::asio::io_service> IoService;
+ /// The destination host
boost::asio::ip::tcp_raw_protocol::endpoint DestinationEndpoint;
/// Network layer protocol used to ping, IPv4 or IPv6
boost::asio::ip::tcp_raw_protocol::socket::protocol_type Protocol;
boost::asio::streambuf ReplyBuffer;
/// A flag to indicate if we got a reply or not
bool ReceivedReply;
- /// the amount of time to wait for the reply
+ /// The amount of time to wait for the reply
int RstReplyTimeoutInSec;
- /// the status of the pinger
+ /// The status of the pinger
PingStatus PingerStatus;
/// Callback to notify when the ping is done (got reply/timeout)
boost::function< void(bool) > PingDoneCallback;