From a2062c274516455753bd76a186d3d175d74856e1 Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 2 Nov 2022 02:12:38 +0000 Subject: [PATCH] Small reduction in work done for nextTimeout --- scan_engine.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scan_engine.cc b/scan_engine.cc index e1650636f..110c77f5f 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -628,27 +628,32 @@ bool HostScanStats::sendOK(struct timeval *when) const { the earliest one and returns true. Otherwise returns false and puts now in when. */ bool HostScanStats::nextTimeout(struct timeval *when) const { - struct timeval probe_to, earliest_to; + struct timeval earliest_to = USI->now; std::list::const_iterator probeI; - bool firstgood = true; + bool pending_probes = false; assert(when); - memset(&probe_to, 0, sizeof(probe_to)); - memset(&earliest_to, 0, sizeof(earliest_to)); + /* For any given invocation, the probe timeout is the same for all probes, so + * we can get the earliest-sent probe and then add the timeout to that. + */ for (probeI = probes_outstanding.begin(); probeI != probes_outstanding.end(); probeI++) { - if (!(*probeI)->timedout) { - TIMEVAL_ADD(probe_to, (*probeI)->sent, probeTimeout()); - if (firstgood || TIMEVAL_SUBTRACT(probe_to, earliest_to) < 0) { - earliest_to = probe_to; - firstgood = false; + UltraProbe *probe = *probeI; + if (!probe->timedout) { + pending_probes = true; + if (TIMEVAL_BEFORE(probe->sent, earliest_to)) { + earliest_to = probe->sent; } } } - - *when = (firstgood) ? USI->now : earliest_to; - return !firstgood; + if (pending_probes) { + TIMEVAL_ADD(*when, earliest_to, probeTimeout()); + } + else { + *when = USI->now; + } + return pending_probes; } /* gives the maximum try number (try numbers start at zero and