BIND 10 trac1954, updated. ff8a54c66f7c0fadcceb18aa6b6d33c0cfbd615b [1954] Replaced atoi, atoll, atof with lexical_cast.
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri May 18 15:47:16 UTC 2012
The branch, trac1954 has been updated
via ff8a54c66f7c0fadcceb18aa6b6d33c0cfbd615b (commit)
via d18d92e4e6a83f370258801c2c05caf15cdb6322 (commit)
from 35a0237e8d8263e32717c64f1b16b7bf59990ba7 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ff8a54c66f7c0fadcceb18aa6b6d33c0cfbd615b
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri May 18 17:42:40 2012 +0200
[1954] Replaced atoi, atoll, atof with lexical_cast.
commit d18d92e4e6a83f370258801c2c05caf15cdb6322
Author: Marcin Siodelski <marcin at isc.org>
Date: Fri May 18 17:33:41 2012 +0200
[1954] Make CommandOptions class singleton.
-----------------------------------------------------------------------
Summary of changes:
tests/tools/perfdhcp/command_options.cc | 95 ++++++++++++++++++++++---------
tests/tools/perfdhcp/command_options.h | 29 +++++++---
2 files changed, 88 insertions(+), 36 deletions(-)
-----------------------------------------------------------------------
diff --git a/tests/tools/perfdhcp/command_options.cc b/tests/tools/perfdhcp/command_options.cc
index 4f30714..de57be5 100644
--- a/tests/tools/perfdhcp/command_options.cc
+++ b/tests/tools/perfdhcp/command_options.cc
@@ -35,6 +35,28 @@ using namespace isc;
namespace isc {
namespace perfdhcp {
+/// IfaceMgr is a singleton implementation
+CommandOptions* CommandOptions::instance_ = 0;
+
+void
+CommandOptions::instanceCreate() {
+ if (instance_) {
+ // no need to do anything. Instance is already created.
+ // Who called it again anyway? Uh oh. Had to be us, as
+ // this is private method.
+ return;
+ }
+ instance_ = new CommandOptions();
+}
+
+CommandOptions&
+CommandOptions::instance() {
+ if (instance_ == 0) {
+ instanceCreate();
+ }
+ return (*instance_);
+}
+
// Reset stored values to the defaults.
void
CommandOptions::reset() {
@@ -120,19 +142,19 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'r':
- rate_ = atoi(optarg);
+ rate_ = boost::lexical_cast<int>(optarg);
check(rate_ <= 0, "rate_ must be a positive integer");
break;
case 't':
- report_delay_ = atoi(optarg);
+ report_delay_ = boost::lexical_cast<int>(optarg);
check(report_delay_ <= 0, "report_delay_ must be a positive integer");
break;
case 'R':
- r = atoll(optarg);
+ r = boost::lexical_cast<long long>(optarg);
check(r < 0, "random_range_ must not be a negative integer");
- random_range_ = (uint32_t) r;
+ random_range_ = static_cast<uint32_t>(r);
if ((random_range_ != 0) && (random_range_ != UINT32_MAX)) {
uint32_t s = random_range_ + 1;
uint64_t b = UINT32_MAX + 1, m;
@@ -152,7 +174,7 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'n':
- nr = atoi(optarg);
+ nr = boost::lexical_cast<int>(optarg);
check(nr <= 0, "num-request must be a positive integer");
if (num_request_.size() >= 2) {
isc_throw(isc::InvalidParameter,
@@ -162,12 +184,12 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'p':
- period_ = atoi(optarg);
+ period_ = boost::lexical_cast<int>(optarg);
check(period_ <= 0, "test-period must be a positive integer");
break;
case 'd':
- lost_time_[lost_time_set_] = atof(optarg);
+ lost_time_[lost_time_set_] = boost::lexical_cast<double>(optarg);
check(lost_time_[lost_time_set_] <= 0., "drop-time must be a positive number");
lost_time_set_ = 1;
break;
@@ -176,13 +198,13 @@ CommandOptions::initialize(int argc, char** const argv) {
pc = strchr(optarg, '%');
if (pc != NULL) {
*pc = '\0';
- dp = atof(optarg);
- max_pdrop_[max_drop_set_] = atof(optarg);
+ dp = boost::lexical_cast<double>(optarg);
+ max_pdrop_[max_drop_set_] = boost::lexical_cast<double>(optarg);
check((dp <= 0) || (dp >= 100), "invalid drop-time percentage");
max_pdrop_.push_back(dp);
break;
}
- di = atoi(optarg);
+ di = boost::lexical_cast<int>(optarg);
check(di <= 0, "max-drop must be a positive integer");
max_drop_.push_back(di);
break;
@@ -192,24 +214,24 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'P':
- preload_ = atoi(optarg);
+ preload_ = boost::lexical_cast<int>(optarg);
check(preload_ < 0, "preload must not be a negative integer");
break;
case 'a':
- aggressivity_ = atoi(optarg);
+ aggressivity_ = boost::lexical_cast<int>(optarg);
check(aggressivity_ <= 0, "aggressivity must be a positive integer");
break;
case 'L':
- local_port_ = atoi(optarg);
+ local_port_ = boost::lexical_cast<int>(optarg);
check(local_port_ < 0, "local-port must not be a negative integer");
check(local_port_ > (int) UINT16_MAX, "local-port must be lower than UINT16_MAX");
break;
case 's':
seeded_ = true;
- seed_ = (unsigned int) atol(optarg);
+ seed_ = boost::lexical_cast<unsigned int>(optarg);
break;
case 'i':
@@ -242,7 +264,7 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'X':
- of = atoi(optarg);
+ of = boost::lexical_cast<int>(optarg);
check(of <= 0, "xid-offset must be a positive integer");
if (xid_offset_.size() >= 2) {
xid_offset_.resize(0);
@@ -251,7 +273,7 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'O':
- of = atoi(optarg);
+ of = boost::lexical_cast<int>(optarg);
check(of < 3, "random-offset must be greater than 3");
if (rnd_offset_.size() >= 2) {
rnd_offset_.resize(0);
@@ -260,17 +282,17 @@ CommandOptions::initialize(int argc, char** const argv) {
break;
case 'E':
- elp_offset_ = atoi(optarg);
+ elp_offset_ = boost::lexical_cast<int>(optarg);
check(elp_offset_ < 0, "time-offset must not be a negative integer");
break;
case 'S':
- sid_offset_ = atoi(optarg);
+ sid_offset_ = boost::lexical_cast<int>(optarg);
check(sid_offset_ <= 0, "srvid-offset must be a positive integer");
break;
case 'I':
- rip_offset_ = atoi(optarg);
+ rip_offset_ = boost::lexical_cast<int>(optarg);
check(rip_offset_ <= 0, "ip-offset must be a positive integer");
break;
@@ -288,17 +310,34 @@ CommandOptions::initialize(int argc, char** const argv) {
}
}
- if (ipversion_ == 0)
- ipversion_ = 4;
- if (template_file_.size() > 1) {
- if (xid_offset_.size() == 1)
+ if (ipversion_ == 0)
+ ipversion_ = 4;
+ if (template_file_.size() > 1) {
+ if (xid_offset_.size() == 1)
xid_offset_.push_back(xid_offset_[0]);
- if (rnd_offset_.size() == 1)
- rnd_offset_.push_back(rnd_offset_[0]);
- }
+ if (rnd_offset_.size() == 1)
+ rnd_offset_.push_back(rnd_offset_[0]);
+ }
- // TODO HADNLE SERVER ARG
+ /* get server argument */
+ check(optind < argc -1, "extra arguments?");
+ if (optind == argc - 1) {
+ server_name_ = argv[optind];
+ /* decode special cases */
+ if ((ipversion_ == 4) &&
+ (server_name_.compare("all") == 0)) {
+ broadcast_ = 1;
+ server_name_ = "255.255.255.255";
+ } else if ((ipversion_ == 6) &&
+ (server_name_.compare("all") == 0)) {
+ server_name_ = "FF02::1:2";
+ } else if ((ipversion_ == 6) &&
+ (server_name_.compare("servers") == 0)) {
+ server_name_ = "FF05::1:3";
+ }
+ }
+ // TODO USE NON EXISTING IFACE MANAGER TO HANDLE -l option
}
void
@@ -414,7 +453,7 @@ CommandOptions::check(bool condition, const std::string errmsg) const {
void
CommandOptions::usage(void)
{
- fprintf(stderr, "%s",
+ fprintf(stdout, "%s",
"perfdhcp [-hv] [-4|-6] [-r<rate>] [-t<report>] [-R<range>] [-b<base>]\n"
" [-n<num-request>] [-p<test-period>] [-d<drop-time>] [-D<max-drop>]\n"
" [-l<local-addr|interface>] [-P<preload>] [-a<aggressivity>]\n"
diff --git a/tests/tools/perfdhcp/command_options.h b/tests/tools/perfdhcp/command_options.h
index aed5696..c44588a 100644
--- a/tests/tools/perfdhcp/command_options.h
+++ b/tests/tools/perfdhcp/command_options.h
@@ -18,6 +18,8 @@
#include <string>
#include <vector>
+#include <boost/noncopyable.hpp>
+
namespace isc {
namespace perfdhcp {
@@ -26,19 +28,18 @@ namespace perfdhcp {
/// This class is responsible for parsing the command-line and storing the
/// specified options.
///
-class CommandOptions {
+class CommandOptions : public boost::noncopyable {
public:
enum ExchangeMode {
DO_SA,
DORR_SARR
};
- /// \brief Default Constructor
+ /// CommandOptions is a singleton class. This method returns reference
+ /// to its sole instance.
///
- /// Set values to defaults.
- CommandOptions() {
- reset();
- }
+ /// \return the only existing instance of command options
+ static CommandOptions& instance();
/// \brief Reset to defaults
///
@@ -220,7 +221,19 @@ public:
/// Prints perfdhcp usage
void usage(void);
+protected:
+
+ /// \brief Default Constructor
+ ///
+ /// Protected constructor as this is a singleton class.
+ /// Use CommandOptions::instance() to get instance of it.
+ CommandOptions() {
+ reset();
+ }
+
private:
+ /// \brief Create instance of the singleton class
+ static void instanceCreate();
/// \brief Initializes class members based command line
///
@@ -261,6 +274,8 @@ private:
/// \throw InvalidParameter if base is invalid
void decodeDuid(const std::string& base);
+ static CommandOptions * instance_; ///< A pointer to sole instance of this class
+
uint8_t ipversion_; ///< IP version
ExchangeMode exchange_mode_ ; ///< Packet exchange mode (e.g. DORR/SARR)
int rate_; ///< rate in exchange per second
@@ -296,8 +311,6 @@ private:
std::string diags_; ///< diagnostic selectors
std::string wrapped_; ///< wrapped command
std::string server_name_; ///< server
-
-
};
} // namespace perfdhcp
More information about the bind10-changes
mailing list