]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[283-perfdhcp-fix-send-due] Fixed late sent flag (second try)
authorFrancis Dupont <fdupont@isc.org>
Mon, 10 Dec 2018 17:26:16 +0000 (18:26 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 13 Dec 2018 13:36:57 +0000 (14:36 +0100)
src/bin/perfdhcp/rate_control.cc

index a61cd5840d7cde6e67bba59f99c00c58b751484a..8e10b8e9b042a58e1915010068c6080788cfb6ee 100644 (file)
@@ -108,12 +108,14 @@ RateControl::updateSendDue() {
         send_due_ = start_time_ +
             time_duration(0, 0, static_cast<long>(seconds),
                           static_cast<long>(fracts));
-        // Compute the time of the last due.
-        offset = 1. / getRate();
-        fracts = offset * time_duration::ticks_per_second();
-        boost::posix_time::ptime last_due =
-            send_due_ - time_duration(0, 0, 0, static_cast<long>(fracts));
-        if (last_due > currentTime()) {
+        // Compute the number of packets we should have sent.
+        boost::posix_time::time_period period(start_time_, currentTime());
+        boost::posix_time::time_duration duration = period.length();
+        offset = static_cast<double>(duration.ticks()) /
+            time_duration::ticks_per_second();
+        uint64_t should_sent =
+            static_cast<uint64_t>(getRate() * offset) - 1;
+        if (should_sent > sent_) {
             late_sent_ = true;
         } else {
             late_sent_ = false;