mirror of
https://github.com/deavmi/doap
synced 2024-07-04 14:30:55 +02:00
CoapClient
- Added `EXCHANGE_LIFETIME` and made it very high for starters
This commit is contained in:
parent
ae97035035
commit
41ef2a39cf
|
@ -51,6 +51,9 @@ public class CoapClient
|
||||||
private ushort rollingMid;
|
private ushort rollingMid;
|
||||||
private Mutex rollingLock;
|
private Mutex rollingLock;
|
||||||
|
|
||||||
|
import std.datetime.stopwatch : StopWatch;
|
||||||
|
private StopWatch[ushort] mids;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new CoAP client to the
|
* Creates a new CoAP client to the
|
||||||
* provided endpoint address
|
* provided endpoint address
|
||||||
|
@ -95,6 +98,43 @@ public class CoapClient
|
||||||
return newValue;
|
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
|
* Constructs a new CoAP client to the
|
||||||
* provided endpoint address and port.
|
* provided endpoint address and port.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user