From ed97a2a3b4365c3b412b250658c160341878fc91 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 22 Sep 2023 16:22:27 +0200 Subject: [PATCH] CoapRequest - Removed `getAndReset()`, replaced it with `hasTimedOut(Duration)` CoapClient - The `watch()` now uses `CoapRequest`'s new `hasTimedOut(Duration)` method --- source/doap/client/client.d | 2 +- source/doap/client/request.d | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/doap/client/client.d b/source/doap/client/client.d index 838b0a5..d4ca3b4 100644 --- a/source/doap/client/client.d +++ b/source/doap/client/client.d @@ -253,7 +253,7 @@ public class CoapClient requestsLock.lock(); foreach(CoapRequest curReq; outgoingRequests) { - if(curReq.getAndReset() >= retransmitTimeout) + if(curReq.hasTimedOut(retransmitTimeout)) { // TODO: Retransmit } diff --git a/source/doap/client/request.d b/source/doap/client/request.d index 872dee1..48e101b 100644 --- a/source/doap/client/request.d +++ b/source/doap/client/request.d @@ -73,17 +73,28 @@ package class CoapRequest } /** - * Gets the current elapsed time and - * then resets it + * Checks if this request has expired + * according to the given timeout + * threshold * - * Returns: the elapsed time + * If timed out then the timer + * restarts. + * + * Returns: `true` if timed out, + * `false` if not */ - package Duration getAndReset() + package bool hasTimedOut(Duration timeoutThreshold) { - // Get the value and restart timer - Duration elapsed = timer.peek(); - timer.reset(); - return elapsed; + // Check if the threshold has been reached + if(timer.peek() >= timeoutThreshold) + { + timer.reset(); + return true; + } + else + { + return false; + } } }