CoapClient

- Added `EXCHANGE_LIFETIME` and made it very high for starters
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-25 21:41:32 +02:00
parent ae97035035
commit 41ef2a39cf

View File

@ -51,6 +51,9 @@ public class CoapClient
private ushort rollingMid;
private Mutex rollingLock;
import std.datetime.stopwatch : StopWatch;
private StopWatch[ushort] mids;
/**
* Creates a new CoAP client to the
* provided endpoint address
@ -95,6 +98,43 @@ public class CoapClient
return newValue;
}
private Duration EXCHANGE_LIFETIME = dur!("seconds")(500000);
private final ushort newMid2()
{
ushort guessStart = 0;
// Lock rolling counter
this.rollingLock.lock();
scope(exit)
{
// Unlock rolling counter
this.rollingLock.unlock();
}
ushort[] inUse;
foreach(ushort occupied; this.mids.keys())
{
// Peek the value of the stopwatch
if(this.mids[occupied].peek() >= EXCHANGE_LIFETIME)
{
// It's expired, so we can use it (first reset the time)
this.mids[occupied].reset();
return occupied;
}
else
{
inUse ~= occupied;
}
}
// import doap.
return
}
/**
* Constructs a new CoAP client to the
* provided endpoint address and port.