CoapRequest

- Removed `getAndReset()`, replaced it with `hasTimedOut(Duration)`

CoapClient

- The `watch()` now uses `CoapRequest`'s new `hasTimedOut(Duration)` method
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-22 16:22:27 +02:00
parent 31b5d13943
commit ed97a2a3b4
2 changed files with 20 additions and 9 deletions

View File

@ -253,7 +253,7 @@ public class CoapClient
requestsLock.lock(); requestsLock.lock();
foreach(CoapRequest curReq; outgoingRequests) foreach(CoapRequest curReq; outgoingRequests)
{ {
if(curReq.getAndReset() >= retransmitTimeout) if(curReq.hasTimedOut(retransmitTimeout))
{ {
// TODO: Retransmit // TODO: Retransmit
} }

View File

@ -73,17 +73,28 @@ package class CoapRequest
} }
/** /**
* Gets the current elapsed time and * Checks if this request has expired
* then resets it * 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 // Check if the threshold has been reached
Duration elapsed = timer.peek(); if(timer.peek() >= timeoutThreshold)
timer.reset(); {
return elapsed; timer.reset();
return true;
}
else
{
return false;
}
} }
} }