Skip to content

Commit 8600cb9

Browse files
committed
Grrrg
1 parent c0878eb commit 8600cb9

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

ArtNetSharp/Communication/AbstractInstance.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -819,28 +819,27 @@ void add(RemoteClient rc)
819819
if (remoteClients.TryAdd(rc.ID, rc))
820820
{
821821
Logger.LogInformation($"Discovered: {rc.ID}");
822-
RemoteClientDiscovered?.InvokeFailSafe(this, rc);
822+
Task.Run(() => RemoteClientDiscovered?.InvokeFailSafe(this, rc));
823823
return;
824824
}
825825
Logger.LogWarning($"Cant add {rc.ID} to Dictionary");
826826
}
827827
}
828828
catch (Exception ex) { Logger.LogError(ex); }
829829

830-
var deadline = 9500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 2500 ms)
831-
var timoutedClients = remoteClients.Where(p => (DateTime.UtcNow - p.Value.LastSeen).TotalMilliseconds > deadline);
830+
var timoutedClients = RemoteClients.Where(p => p.Timouted());
832831
if (timoutedClients.Count() != 0)
833832
{
834833
timoutedClients = timoutedClients.ToList();
835834
foreach (var rc in timoutedClients)
836835
{
837836

838-
if (remoteClients.TryRemove(rc.Key, out RemoteClient removed))
837+
if (remoteClients.TryRemove(rc.ID, out RemoteClient removed))
839838
remoteClientsTimeouted.TryAdd(removed.ID, removed);
840839
if (removed != null)
841840
{
842-
Logger.LogInformation($"Timeout: {removed.ID} ({(DateTime.UtcNow - rc.Value.LastSeen).TotalMilliseconds}ms)");
843-
RemoteClientTimedOut?.InvokeFailSafe(this, removed);
841+
Logger.LogInformation($"Timeout: {removed.ID} ({(DateTime.UtcNow - rc.LastSeen).TotalMilliseconds}ms)");
842+
Task.Run(() => RemoteClientTimedOut?.InvokeFailSafe(this, removed));
844843
}
845844
}
846845
}

ArtNetSharp/Communication/RemoteClient.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ private set
8080
onPropertyChanged();
8181
}
8282
}
83+
internal bool Timouted() // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 2500 ms)
84+
{
85+
var now = DateTime.UtcNow.AddSeconds(-9.5);
86+
return LastSeen <= now;
87+
}
88+
8389
private bool isRDMCapable;
8490
public bool IsRDMCapable
8591
{
@@ -252,11 +258,13 @@ internal AbstractInstance Instance
252258

253259
public RemoteClient(in ArtPollReply artPollReply)
254260
{
261+
seen();
255262
ID = getIDOf(artPollReply);
256263
MacAddress = artPollReply.MAC;
257264
IpAddress = artPollReply.OwnIp;
258265
seen();
259266
processArtPollReply(artPollReply);
267+
seen();
260268
}
261269
private void seen()
262270
{
@@ -292,7 +300,7 @@ public void processArtPollReply(ArtPollReply artPollReply)
292300
port = new RemoteClientPort(artPollReply, portIndex);
293301
if (ports.TryAdd(physicalPort, port))
294302
{
295-
PortDiscovered?.InvokeFailSafe(this, port);
303+
Task.Run(() => PortDiscovered?.InvokeFailSafe(this, port));
296304
port.RDMUIDReceived += Port_RDMUIDReceived;
297305
}
298306
}
@@ -302,23 +310,24 @@ public void processArtPollReply(ArtPollReply artPollReply)
302310
{
303311
Logger.LogError(ex);
304312
}
313+
seen();
305314

306-
var deadline = 7500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 1500 ms)
307-
var timoutedPorts = ports.Where(p => (DateTime.UtcNow - p.Value.LastSeen).TotalMilliseconds > deadline);
315+
var timoutedPorts = ports.Where(p => p.Value.Timouted());
308316
if (timoutedPorts.Count() != 0)
309317
{
310318
timoutedPorts = timoutedPorts.ToList();
311319
foreach (var port in timoutedPorts)
312320
{
313321
ports.TryRemove(port.Key, out _);
314-
PortTimedOut?.InvokeFailSafe(this, port.Value);
322+
Task.Run(()=>PortTimedOut?.InvokeFailSafe(this, port));
315323
}
316324
}
325+
seen();
317326
Ports = ports.Select(p => p.Value).ToList().AsReadOnly();
318327
}
319328
public async Task processArtDataReply(ArtDataReply artDataReply)
320329
{
321-
LastSeen = DateTime.UtcNow;
330+
seen();
322331
if (artDataReply.Request == EDataRequest.Poll)
323332
{
324333
await QueryArtData();

ArtNetSharp/Communication/RemoteClientPort.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ private set
3333
onPropertyChanged();
3434
}
3535
}
36-
internal bool Timouted()
36+
private void seen()
3737
{
38-
var now = DateTime.UtcNow.AddSeconds(-30);
38+
LastSeen = DateTime.UtcNow;
39+
}
40+
internal bool Timouted()// Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 1500 ms)
41+
{
42+
var now = DateTime.UtcNow.AddSeconds(-7.5);
3943
return LastSeen <= now;
4044
}
4145
public ArtPollReply ArtPollReply { get; private set; }
@@ -157,6 +161,7 @@ private void onPropertyChanged(PropertyChangedEventArgs eventArgs)
157161

158162
public RemoteClientPort(in ArtPollReply artPollReply, byte portIndex = 0)
159163
{
164+
seen();
160165
ID = getIDOf(artPollReply, portIndex);
161166
IpAddress = artPollReply.OwnIp;
162167
BindIndex = artPollReply.BindIndex;
@@ -182,7 +187,7 @@ public void processArtPollReply(ArtPollReply artPollReply)
182187
return;
183188

184189
ArtPollReply = artPollReply;
185-
LastSeen = DateTime.UtcNow;
190+
seen();
186191

187192
PortType = artPollReply.PortTypes[PortIndex];
188193
GoodOutput = artPollReply.GoodOutput[PortIndex];
@@ -210,6 +215,7 @@ public void processArtPollReply(ArtPollReply artPollReply)
210215
}
211216
else
212217
InputPortAddress = null;
218+
seen();
213219
}
214220
private void addControllerRdmUID(UID rdmuid)
215221
{
@@ -270,7 +276,7 @@ internal void ProcessArtRDM(ArtRDM artRDM)
270276
if (!KnownResponderRDMUIDs.Any(k => k.Uid.Equals(artRDM.Source)))
271277
return;
272278

273-
LastSeen = DateTime.UtcNow;
279+
seen();
274280
}
275281

276282
public override string ToString()

0 commit comments

Comments
 (0)