return uid;
}
-int ArgvMap::asNum(const string &arg)
+int ArgvMap::asNum(const string &arg, int def)
{
int retval;
const char *cptr_orig;
if(!parmIsset(arg))
throw ArgException(string("Undefined but needed argument: '")+arg+"'");
- // treat empty values as zeros
+ // use default for empty values
if (params[arg].empty())
- return 0;
+ return def;
cptr_orig = params[arg].c_str();
retval = static_cast<int>(strtol(cptr_orig, &cptr_ret, 0));
typedef map<string,string> param_t; //!< use this if you need to know the content of the map
bool parmIsset(const string &var); //!< Checks if a parameter is set to *a* value
bool mustDo(const string &var); //!< if a switch is given, if we must do something (--help)
- int asNum(const string &var); //!< return a variable value as a number
+ int asNum(const string &var, int def=0); //!< return a variable value as a number or the default if the variable is empty
mode_t asMode(const string &var); //!< return value interpreted as octal number
uid_t asUid(const string &var); //!< return user id, resolves if necessary
gid_t asGid(const string &var); //!< return group id, resolves if necessary
void *qthread(void *number)
{
DNSPacket *P;
- DNSDistributor *distributor = DNSDistributor::Create(::arg().asNum("distributor-threads")); // the big dispatcher!
+ DNSDistributor *distributor = DNSDistributor::Create(::arg().asNum("distributor-threads", 1)); // the big dispatcher!
DNSPacket question;
DNSPacket cached;
pthread_create(&qtid,0,carbonDumpThread, 0); // runs even w/o carbon, might change @ runtime
// fork(); (this worked :-))
- unsigned int max_rthreads= ::arg().asNum("receiver-threads");
+ unsigned int max_rthreads= ::arg().asNum("receiver-threads", 1);
for(unsigned int n=0; n < max_rthreads; ++n)
pthread_create(&qtid,0,qthread, reinterpret_cast<void *>(n)); // receives packets
{
pthread_t tid;
pthread_create(&tid,0,&launchhelper,this); // Starts CommunicatorClass::mainloop()
- for(int n=0; n < ::arg().asNum("retrieval-threads"); ++n)
+ for(int n=0; n < ::arg().asNum("retrieval-threads", 1); ++n)
pthread_create(&tid, 0, &retrieveLaunchhelper, this); // Starts CommunicatorClass::retrievalLoopThread()
d_preventSelfNotification = ::arg().mustDo("prevent-self-notification");
trc.d_mac = outpacket->d_trc.d_mac;
outpacket = getFreshAXFRPacket(q);
- ChunkedSigningPipe csp(target, securedZone, "", ::arg().asNum("signing-threads"));
+ ChunkedSigningPipe csp(target, securedZone, "", ::arg().asNum("signing-threads", 1));
typedef map<string, NSECXEntry> nsecxrepo_t;
nsecxrepo_t nsecxrepo;