"Dhcp4": { "lease-database": { <userinput>"connect-timeout" : <replaceable>timeout-in-seconds</replaceable></userinput>, ... }, ... }
</screen>
The default value of five seconds should be more than adequate for local connections.
+If a timeout is given though, it should be an integer greater than zero.
</para>
<para>Finally, the credentials of the account under which the server will
access the database should be set:
"Dhcp6": { "lease-database": { <userinput>"connect-timeout" : <replaceable>timeout-in-seconds</replaceable></userinput>, ... }, ... }
</screen>
The default value of five seconds should be more than adequate for local connections.
+If a timeout is given though, it should be an integer greater than zero.
</para>
<para>Finally, the credentials of the account under which the server will
access the database should be set:
#include <iterator>
#include <stdint.h>
#include <string>
+#include <limits>
using namespace isc;
using namespace isc::dhcp;
isc_throw(NoDatabaseName, "must specify a name for the database");
}
- int connect_timeout = MYSQL_DEFAULT_CONNECTION_TIMEOUT;
+ unsigned int connect_timeout = MYSQL_DEFAULT_CONNECTION_TIMEOUT;
string stimeout;
try {
stimeout = getParameter("connect-timeout");
if (stimeout.size() > 0) {
// Timeout was given, so try to convert it to an integer.
+
try {
- connect_timeout = boost::lexical_cast<int>(stimeout);
+ connect_timeout = boost::lexical_cast<unsigned int>(stimeout);
} catch (...) {
- // Timeout given but invalid.
- isc_throw(DbInvalidTimeout, "database connection timeout (" << stimeout <<
- ") must be numeric");
+ // Timeout given but could not be converted to an unsigned int. Set
+ // the connection timeout to an invalid value to trigger throwing
+ // of an exception.
+ connect_timeout = 0;
}
- // ... and check the range.
- if (connect_timeout <= 0) {
- isc_throw(DbInvalidTimeout, "database connection timeout (" << connect_timeout <<
- ") must be an integer greater than 0");
+ // The timeout is only valid if greater than zero, as depending on the
+ // database, a zero timeout might signify someting like "wait
+ // indefinitely".
+ //
+ // The check below also rejects a value greater than the maximum
+ // integer value. The lexical_cast operation used to obtain a numeric
+ // value from a string can get confused if trying to convert a negative
+ // integer to an unsigned int: instead of throwing an exception, it may
+ // produce a large positive value.
+ if ((connect_timeout == 0) ||
+ (connect_timeout > numeric_limits<int>::max())) {
+ isc_throw(DbInvalidTimeout, "database connection timeout (" <<
+ stimeout << ") must be an integer greater than 0");
}
}
isc_throw(NoDatabaseName, "must specify a name for the database");
}
- int connect_timeout = PGSQL_DEFAULT_CONNECTION_TIMEOUT;
+ unsigned int connect_timeout = PGSQL_DEFAULT_CONNECTION_TIMEOUT;
string stimeout;
try {
stimeout = dbconn_.getParameter("connect-timeout");
if (stimeout.size() > 0) {
// Timeout was given, so try to convert it to an integer.
+
try {
- connect_timeout = boost::lexical_cast<int>(stimeout);
+ connect_timeout = boost::lexical_cast<unsigned int>(stimeout);
} catch (...) {
- // Timeout given but invalid.
- isc_throw(DbInvalidTimeout, "database connection timeout (" << stimeout <<
- ") must be numeric");
+ // Timeout given but could not be converted to an unsigned int. Set
+ // the connection timeout to an invalid value to trigger throwing
+ // of an exception.
+ connect_timeout = 0;
}
- // ... and check the range.
- if (connect_timeout <= 0) {
- isc_throw(DbInvalidTimeout, "database connection timeout (" << connect_timeout <<
- ") must be an integer greater than 0");
+ // The timeout is only valid if greater than zero, as depending on the
+ // database, a zero timeout might signify someting like "wait
+ // indefinitely".
+ //
+ // The check below also rejects a value greater than the maximum
+ // integer value. The lexical_cast operation used to obtain a numeric
+ // value from a string can get confused if trying to convert a negative
+ // integer to an unsigned int: instead of throwing an exception, it may
+ // produce a large positive value.
+ if ((connect_timeout == 0) ||
+ (connect_timeout > numeric_limits<int>::max())) {
+ isc_throw(DbInvalidTimeout, "database connection timeout (" <<
+ stimeout << ") must be an integer greater than 0");
}
}