Skip to content

Commit

Permalink
Fight Timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Dec 28, 2023
1 parent 6c68987 commit 7ae706b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 2 additions & 3 deletions ArtNetSharp/Communication/AbstractInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,8 @@ async Task add()
catch (Exception ex) { Logger.LogError(ex); }
semaphoreSlimAddRemoteClient.Release();

var now = DateTime.UtcNow;
var deadline = now.AddSeconds(-6); // Spec 1.4dd page 12, doubled to allow one lost reply
var timoutedClients = remoteClients.Where(p => p.Value.LastSeen < deadline);
var deadline = 7500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 1500 ms)
var timoutedClients = remoteClients.Where(p => (DateTime.UtcNow-p.Value.LastSeen).TotalMilliseconds > deadline);
if (timoutedClients.Count() != 0)
{
timoutedClients = timoutedClients.ToList();
Expand Down
16 changes: 11 additions & 5 deletions ArtNetSharp/Communication/RemoteClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ public RemoteClient(in ArtPollReply artPollReply)
ID = getIDOf(artPollReply);
MacAddress = artPollReply.MAC;
IpAddress = artPollReply.OwnIp;
LastSeen = DateTime.UtcNow;
seen();
processArtPollReply(artPollReply);
}
private void seen()
{
LastSeen = DateTime.UtcNow;
}

public static string getIDOf(ArtPollReply artPollReply)
{
Expand All @@ -274,6 +278,8 @@ public void processArtPollReply(ArtPollReply artPollReply)

if (artPollReply.Ports == 0)
return;

seen();
try
{
for (byte portIndex = 0; portIndex < artPollReply.Ports; portIndex++)
Expand All @@ -298,9 +304,8 @@ public void processArtPollReply(ArtPollReply artPollReply)
Logger.LogError(ex);
}

LastSeen = DateTime.UtcNow;
var deadline = LastSeen.AddSeconds(-6); // Spec 1.4dd page 12, doubled to allow one lost reply
var timoutedPorts = ports.Where(p => p.Value.LastSeen < deadline);
var deadline = 7500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 1500 ms)
var timoutedPorts = ports.Where(p => (DateTime.UtcNow - p.Value.LastSeen).TotalMilliseconds > deadline);
if (timoutedPorts.Count() != 0)
{
timoutedPorts = timoutedPorts.ToList();
Expand All @@ -314,7 +319,8 @@ public void processArtPollReply(ArtPollReply artPollReply)
}
public async Task processArtDataReply(ArtDataReply artDataReply)
{
if(artDataReply.Request == EDataRequest.Poll)
LastSeen = DateTime.UtcNow;
if (artDataReply.Request == EDataRequest.Poll)
{
await QueryArtData();
return;
Expand Down
4 changes: 2 additions & 2 deletions ArtNetSharp/Communication/RemoteClientPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public void processArtPollReply(ArtPollReply artPollReply)
return;

ArtPollReply = artPollReply;
LastSeen = DateTime.UtcNow;

PortType = artPollReply.PortTypes[PortIndex];
GoodOutput = artPollReply.GoodOutput[PortIndex];
Expand Down Expand Up @@ -212,8 +213,6 @@ public void processArtPollReply(ArtPollReply artPollReply)
}
else
InputPortAddress = null;

LastSeen = DateTime.UtcNow;
}
internal void AddRdmUIDs(params RDMUID[] rdmuids)
{
Expand Down Expand Up @@ -256,6 +255,7 @@ internal void ProcessArtRDM(ArtRDM artRDM)
if (!KnownRDMUIDs.Any(k => k.Uid.Equals(artRDM.Source)))
return;

LastSeen = DateTime.UtcNow;
AddRdmUIDs(artRDM.Source);
RDMMessageReceived?.Invoke(this, artRDM.Data);
}
Expand Down

0 comments on commit 7ae706b

Please sign in to comment.