As suggested by Otto (thanks!).
struct timeval ttd = now;
ttd.tv_sec += timeoutMs / 1000;
ttd.tv_usec += (timeoutMs % 1000) * 1000;
- if (ttd.tv_usec >= 1000000) {
- ttd.tv_sec++;
- ttd.tv_usec -= 1000000;
- }
+ normalizeTV(ttd);
vinfolog("Suspending asynchronous query %d at %d.%d until %d.%d", queryID, now.tv_sec, now.tv_usec, ttd.tv_sec, ttd.tv_usec);
auto query = getInternalQueryFromDQ(dq, false);
struct timeval ttd = now;
ttd.tv_sec += timeoutMs / 1000;
ttd.tv_usec += (timeoutMs % 1000) * 1000;
- if (ttd.tv_usec >= 1000000) {
- ttd.tv_sec++;
- ttd.tv_usec -= 1000000;
- }
+ normalizeTV(ttd);
vinfolog("Suspending asynchronous response %d at %d.%d until %d.%d", queryID, now.tv_sec, now.tv_usec, ttd.tv_sec, ttd.tv_usec);
auto query = getInternalQueryFromDQ(dr, true);
gettimeofday(&data->d_ttd, nullptr);
data->d_ttd.tv_sec += ds->d_config.checkTimeout / 1000; /* ms to seconds */
data->d_ttd.tv_usec += (ds->d_config.checkTimeout % 1000) * 1000; /* remaining ms to us */
- if (data->d_ttd.tv_usec > 1000000) {
- ++data->d_ttd.tv_sec;
- data->d_ttd.tv_usec -= 1000000;
- }
+ normalizeTV(data->d_ttd);
if (!ds->doHealthcheckOverTCP()) {
sock.connect(ds->d_config.remote);
struct timeval res = now;
res.tv_sec += d_ds->d_config.checkTimeout / 1000; /* ms to s */
res.tv_usec += (d_ds->d_config.checkTimeout % 1000) * 1000; /* remaining ms to µs */
+ normalizeTV(res);
return res;
}
gettimeofday(&ttd, nullptr);
// timeout in 100 ms
const timeval add{0, 100000};
- timeradd(&ttd, &add, &ttd);
+ ttd = ttd + add;
holder->push(asyncID, queryID, ttd, std::make_unique<DummyCrossProtocolQuery>());
BOOST_CHECK(!holder->empty());
gettimeofday(&ttd, nullptr);
// timeout in 10 ms
const timeval add{0, 10000};
- timeradd(&ttd, &add, &ttd);
+ ttd = ttd + add;
std::shared_ptr<DummyQuerySender> sender{nullptr};
{
gettimeofday(&ttd, nullptr);
// timeout was 10 ms ago, for some reason (long processing time, CPU starvation...)
const timeval sub{0, 10000};
- timersub(&ttd, &sub, &ttd);
+ ttd = ttd - sub;
std::shared_ptr<DummyQuerySender> sender{nullptr};
{