- documented that a integer is non-negative using assertions, not unsigned int (uint).
variable has the given number of bits. This states clear the intent of the
original programmer and avoids improper modifications.
-- Use int or uint for regular integer numbers that do not require any specific
- size.
+- Use only int for regular integer numbers that do not require any specific
+ size. And document that a variable is non-negative using assertions. Do not
+ use unsigned types to say a number will never be negative.
- Use std::size_t for integers that represent sizes of vectors, objects or
buffers. Thus leaving the size difinition to the platform.
this->ConfigFileName = config_file_name;
}
-uint Configuration::get_limit_to_notify() const
+int Configuration::get_limit_to_notify() const
{
return LimitToNotify;
}
-void Configuration::set_limit_to_notify( const uint limit_to_notify )
+void Configuration::set_limit_to_notify( const int limit_to_notify )
{
BOOST_ASSERT( ( MinLimitToNotify <= limit_to_notify ) && ( limit_to_notify <= MaxLimitToNotify) );
std::string get_config_file_name() const;
void set_config_file_name( const std::string &config_file_name );
- uint get_limit_to_notify() const;
- void set_limit_to_notify( const uint limit_to_notify );
+ int get_limit_to_notify() const;
+ void set_limit_to_notify( const int limit_to_notify );
std::vector<HostItem> get_hosts() const;
void set_hosts( const std::vector<HostItem> &hosts_list );
private:
std::string ConfigFileName;
- uint LimitToNotify;
+ int LimitToNotify;
std::vector<HostItem> Hosts;
- const uint MinLimitToNotify;
- const uint MaxLimitToNotify;
+ const int MinLimitToNotify;
+ const int MaxLimitToNotify;
};
{
options_description options( "Configuration" );
options.add_options()
- ( LimitToNotifyCmdStr.c_str(), value<uint>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
+ ( LimitToNotifyCmdStr.c_str(), value<int>()->default_value( DefaultLimitToNotify ), LimitToNotifyCmdDesc.c_str() )
( HostNameCmdStr.c_str(), value< vector<string> >(), HostNameCmdDesc.c_str() )
- ( HostIntervalCmdStr.c_str(), value< vector<uint> >(), HostIntervalCmdDesc.c_str() )
+ ( HostIntervalCmdStr.c_str(), value< vector<int> >(), HostIntervalCmdDesc.c_str() )
;
return options;
if ( vm.count( LimitToNotifyCmdStr ) )
{
- uint limit_to_notify = vm[ LimitToNotifyCmdStr ].as<uint> ();
+ int limit_to_notify = vm[ LimitToNotifyCmdStr ].as<int> ();
Config.set_limit_to_notify( limit_to_notify );
cout << LimitToNotifyCmdStr << "=" << limit_to_notify << endl;
}
- uint hosts_names_total = 0;
+ int hosts_names_total = 0;
if ( vm.count( HostNameCmdStr ) )
{
vector<HostItem> hosts_list;
hosts_names_total = hosts_names.size();
}
- uint hosts_interval_total = 0;
+ int hosts_interval_total = 0;
if ( vm.count( HostIntervalCmdStr ) )
{
vector<HostItem> hosts_list = Config.get_hosts();
vector<HostItem>::iterator hosts_it = hosts_list.begin();
- vector<uint> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<uint> > ();
- BOOST_FOREACH( uint host_interval, hosts_intervals )
+ vector<int> hosts_intervals = vm[ HostIntervalCmdStr ].as< vector<int> > ();
+ BOOST_FOREACH( int host_interval, hosts_intervals )
{
HostItem host_item = *hosts_it;
host_item->set_interval( host_interval );
const std::string DefaultConfigFileName;
const std::string ConfigFileCmdStr;
const std::string ConfigFileCmdDesc;
- const uint DefaultLimitToNotify;
+ const int DefaultLimitToNotify;
const std::string LimitToNotifyCmdStr;
const std::string LimitToNotifyCmdDesc;
const std::string HostNameCmdStr;
const std::string HostNameCmdDesc;
- const uint DefaultHostInterval;
+ const int DefaultHostInterval;
const std::string HostIntervalCmdStr;
const std::string HostIntervalCmdDesc;
this->Port = port;
}
-uint Host::get_interval() const
+int Host::get_interval() const
{
return Interval;
}
-void Host::set_interval( const uint interval )
+void Host::set_interval( const int interval )
{
- BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<uint>::max() ) );
+ BOOST_ASSERT( ( 0 < interval ) && ( interval < std::numeric_limits<int>::max() ) );
this->Interval = interval;
}
uint16_t get_port() const;
void set_port( const uint16_t port );
- uint get_interval() const;
- void set_interval( const uint interval );
+ int get_interval() const;
+ void set_interval( const int interval );
std::vector<std::string> get_options() const;
void set_options( const std::vector<std::string> &options );
private:
std::string Address;
uint16_t Port;
- uint Interval;
+ int Interval;
std::vector<std::string> Options;
};
*/
string DnsResolver::get_next_ip()
{
- uint list_size_before = ResolvedHostAddressList.size();
+ int list_size_before = ResolvedHostAddressList.size();
HostAddress host_address = ResolvedHostAddressList.front();
ResolvedHostAddressList.pop_front();
string destination_ip = host_address.get_ip();
ResolvedHostAddressList.push_back( host_address );
- uint list_size_after = ResolvedHostAddressList.size();
+ int list_size_after = ResolvedHostAddressList.size();
BOOST_ASSERT( list_size_before == list_size_after );
return Ip;
}
-uint HostAddress::get_ttl() const
+int HostAddress::get_ttl() const
{
return Ttl;
}
-void HostAddress::set_ttl( uint ttl )
+void HostAddress::set_ttl( int ttl )
{
this->Ttl = ttl;
}
std::string get_ip() const;
void set_ip( std::string ip );
- uint get_ttl() const;
- void set_ttl( uint ttl );
+ int get_ttl() const;
+ void set_ttl( int ttl );
private:
std::string Ip;
- uint Ttl;
+ int Ttl;
};
BOOST_FOREACH( HostItem host, hosts )
{
string ping_address = (*host).get_address();
- uint ping_interval = (*host).get_interval();
+ int ping_interval = (*host).get_interval();
PingSchedulerItem scheduler(
new PingScheduler(
io_service, ping_address, ping_interval
BoostPinger::BoostPinger(
boost::asio::io_service &io_service,
- const uint echo_reply_timeout_in_sec
+ const int echo_reply_timeout_in_sec
) :
IoService( io_service ),
Resolver( io_service ),
void BoostPinger::schedule_next_echo_request()
{
// Requests must be sent no less than one second apart.
- const uint echo_request_interval_in_sec = 1;
+ const int echo_request_interval_in_sec = 1;
Timer.expires_at( TimeSent + seconds( echo_request_interval_in_sec ) );
Timer.async_wait( boost::bind( &BoostPinger::start_send, this ) );
}
size_t bytes_received = bytes_transferred - ipv4_hdr.get_header_length();
string source_address = ipv4_hdr.get_source_address().to_string();
- uint sequence_number = icmp_hdr.get_sequence_number();
- uint ttl = ipv4_hdr.get_time_to_live();
+ int sequence_number = icmp_hdr.get_sequence_number();
+ int ttl = ipv4_hdr.get_time_to_live();
ptime now = microsec_clock::universal_time();
- uint time = (now - TimeSent).total_milliseconds();
+ int time = (now - TimeSent).total_milliseconds();
cout << bytes_received << " bytes "
<< "from " << source_address
public:
BoostPinger(
boost::asio::io_service &io_service,
- const uint echo_reply_timeout_in_sec
+ const int echo_reply_timeout_in_sec
);
virtual ~BoostPinger();
uint16_t SequenceNumber;
boost::posix_time::ptime TimeSent;
boost::asio::streambuf ReplyBuffer;
- uint RepliesCount;
- uint EchoReplyTimeoutInSec;
+ int RepliesCount;
+ int EchoReplyTimeoutInSec;
BoostPinger::PingStatus PingerStatus;
};
PingScheduler::PingScheduler(
boost::asio::io_service &io_service,
const string &ping_address,
- const uint ping_interval_in_sec
+ const int ping_interval_in_sec
) :
IoService( io_service ),
Timer( io_service ),
BOOST_ASSERT( !destination.empty() );
io_service io_service;
- uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout
+ 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_service, echo_reply_timeout_in_sec );
return pinger.ping( destination );
PingScheduler(
boost::asio::io_service &io_service,
const std::string &ping_address,
- const uint ping_interval_in_sec
+ const int ping_interval_in_sec
);
virtual ~PingScheduler();
boost::asio::deadline_timer Timer;
boost::posix_time::ptime TimeSentLastPing;
DnsResolver IpList;
- const uint PingIntervalInSec;
+ const int PingIntervalInSec;
PingAnalyzer Analyzer;
};