]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Use normalizeTV() and timeval operator+/operator- 12388/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 24 Jan 2023 10:16:18 +0000 (11:16 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 24 Jan 2023 10:16:18 +0000 (11:16 +0100)
As suggested by Otto (thanks!).

pdns/dnsdistdist/dnsdist-async.cc
pdns/dnsdistdist/dnsdist-healthchecks.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.hh
pdns/dnsdistdist/test-dnsdistasync.cc

index fc9174401c593983f32464db6265f03c737195d4..981464074a736431a8f077c9048bdf3b3b0485d1 100644 (file)
@@ -387,10 +387,7 @@ bool suspendQuery(DNSQuestion& dq, uint16_t asyncID, uint16_t queryID, uint32_t
   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);
@@ -410,10 +407,7 @@ bool suspendResponse(DNSResponse& dr, uint16_t asyncID, uint16_t queryID, uint32
   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);
index 480bfd1960a0c4eeea02977b6557a714764d323a..3f8555f35bbe304509fa67d7b87d7cb7e975b815 100644 (file)
@@ -334,10 +334,7 @@ bool queueHealthCheck(std::unique_ptr<FDMultiplexer>& mplexer, const std::shared
     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);
index c966f823c7966fd6f701d8aa222acb439310960a..81c87570b50bcada3ce5842cfd82c405fa2f0330 100644 (file)
@@ -157,6 +157,7 @@ protected:
     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;
   }
index 2e35d3679f5ba3a84ae471384e23e41285b56dbb..802ba4021d116f43429593e725c8af8d48c4d0bd 100644 (file)
@@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(test_Basic)
     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());
@@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(test_TimeoutFailClose)
   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};
   {
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(test_AddingExpiredEvent)
   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};
   {