Skip to content

Commit

Permalink
Some Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed May 10, 2024
1 parent 383d75c commit c6d35c2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
5 changes: 3 additions & 2 deletions ArtNetSharp/ArtNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private ArtNet()
ApplicationLogging.LoggerFactory.AddProvider(new FileProvider());

Logger = ApplicationLogging.CreateLogger<ArtNet>();
Logger.LogTrace("Initialized!");
Logger?.LogTrace("Initialized!");

_updateNetworkClientsTimer = new System.Timers.Timer();
_updateNetworkClientsTimer.Interval = 1000;
Expand All @@ -322,6 +322,8 @@ private ArtNet()

internal static void Clear()
{
Logger?.LogDebug($"Clear");

if (instance == null)
return;

Expand Down Expand Up @@ -644,7 +646,6 @@ void IDisposable.Dispose()
ipTomacAddressCache.Clear();
OnInstanceAdded = null;
OnInstanceRemoved = null;
Logger = null;
IsDisposed = true;
IsDisposing = false;

Expand Down
92 changes: 68 additions & 24 deletions ArtNetSharp/Communication/AbstractInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
Expand Down Expand Up @@ -54,7 +55,7 @@ public abstract class AbstractInstance : IInstance
private readonly List<PortConfig> portConfigs = new List<PortConfig>();
public ReadOnlyCollection<PortConfig> PortConfigs { get => portConfigs.AsReadOnly(); }

private readonly ConcurrentDictionary<PortAddress, ConcurrentDictionary<IPv4Address, DMXReceiveBag>> receivedDMXBuffer = new ConcurrentDictionary<PortAddress, ConcurrentDictionary<IPv4Address, DMXReceiveBag>>();
private readonly ConcurrentDictionary<Tuple<PortAddress, IPv4Address>, DMXReceiveBag> receivedDMXBuffer = new ConcurrentDictionary<Tuple<PortAddress, IPv4Address>, DMXReceiveBag>();
private readonly ConcurrentDictionary<RDM_TransactionID, RDMMessage> artRDMdeBumbReceive = new();

private readonly struct RDM_TransactionID : IEquatable<RDM_TransactionID>
Expand Down Expand Up @@ -91,13 +92,16 @@ public override int GetHashCode()
return Transaction.GetHashCode() + Controller.GetHashCode() + Responder.GetHashCode();
}
}
private class DMXReceiveBag
private class DMXReceiveBag: IDisposable
{
public byte[] Data { get; private set; } = new byte[512];
public byte Sequence { get; private set; } = byte.MaxValue;
public PortAddress PortAddress { get; private set; }
public IPv4Address Source { get; private set; }
public readonly PortAddress PortAddress;
public readonly IPv4Address Source;
public DateTime LastUpdate { get; private set; }

public bool IsDisposed;

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 103 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposed' is never assigned to, and will always have its default value false
public bool IsDisposing;

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 104 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXReceiveBag.IsDisposing' is never assigned to, and will always have its default value false
public DMXReceiveBag(ArtDMX artDMX, IPv4Address source)
{
PortAddress = new PortAddress(artDMX.Net, artDMX.Address);
Expand All @@ -106,6 +110,9 @@ public DMXReceiveBag(ArtDMX artDMX, IPv4Address source)
}
internal bool Update(ArtDMX artDMX, IPv4Address source)
{
if (IsDisposed || IsDisposing)
return false;

if (Source != source)
return false;

Expand All @@ -123,6 +130,9 @@ internal bool Update(ArtDMX artDMX, IPv4Address source)

private bool? checkSequence(byte _old, byte _new)
{
if (IsDisposed || IsDisposing)
return null;

if (_new == 0)
return null; //SpezialCase

Expand All @@ -134,26 +144,44 @@ internal bool Update(ArtDMX artDMX, IPv4Address source)

return false;
}

public void Dispose()
{
if (IsDisposed || IsDisposing)
return;

Data = null;
Sequence = 0;
GC.SuppressFinalize(this);
}
}
private class DMXSendBag
private class DMXSendBag: IDisposable
{
public byte[] Data { get; private set; } = new byte[512];
public bool Updated => LastUpdated > LastSended;
public byte Sequence { get; private set; }

public readonly PortAddress PortAddress;
public DateTime LastUpdated { get; private set; }
public DateTime LastSended { get; internal set; }

private readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1);
private SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1);

public DMXSendBag(byte[] data)
public bool IsDisposed;

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false

Check warning on line 170 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposed' is never assigned to, and will always have its default value false
public bool IsDisposing;

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 6.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 8.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

Check warning on line 171 in ArtNetSharp/Communication/AbstractInstance.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 7.0)

Field 'AbstractInstance.DMXSendBag.IsDisposing' is never assigned to, and will always have its default value false

public DMXSendBag(byte[] data, PortAddress portAddress)
{
Update(data);
PortAddress = portAddress;
}

internal async void Update(byte[] data, ushort? startindex = null, ushort? count = null)
{
await SemaphoreSlim.WaitAsync();
if (IsDisposed || IsDisposing)
return;

await SemaphoreSlim?.WaitAsync();
try
{
if ((startindex + count) <= Data.Length)
Expand All @@ -167,14 +195,28 @@ internal async void Update(byte[] data, ushort? startindex = null, ushort? count
{
Logger.LogError(e);
}
SemaphoreSlim.Release();
SemaphoreSlim?.Release();
}

internal byte GetSequence()
{
Sequence++;
return Sequence;
}

public void Dispose()
{
if (IsDisposed || IsDisposing)
return;

Data = null;
Sequence = 0;
LastUpdated = DateTime.MaxValue;
LastSended = DateTime.MaxValue;
SemaphoreSlim?.Dispose();
SemaphoreSlim = null;
GC.SuppressFinalize(this);
}
}
private readonly ConcurrentDictionary<PortAddress, DMXSendBag> sendDMXBuffer = new ConcurrentDictionary<PortAddress, DMXSendBag>();
private readonly SemaphoreSlim semaphoreSlimAddRemoteClient = new SemaphoreSlim(1, 1);
Expand Down Expand Up @@ -725,7 +767,7 @@ async Task add()
}
catch (Exception ex) { Logger.LogError(ex); }

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 deadline = 9500; // Spec 1.4dd page 12, doubled to allow one lost reply (6s is allowad, for some delay i add 2500 ms)
var timoutedClients = remoteClients.Where(p => (DateTime.UtcNow - p.Value.LastSeen).TotalMilliseconds > deadline);
if (timoutedClients.Count() != 0)
{
Expand Down Expand Up @@ -754,15 +796,11 @@ private void processArtDMX(ArtDMX artDMX, IPv4Address sourceIp)
return;

bool success = false;
if (!receivedDMXBuffer.TryGetValue(port.PortAddress, out ConcurrentDictionary<IPv4Address, DMXReceiveBag> cdb))
{
cdb = new ConcurrentDictionary<IPv4Address, DMXReceiveBag>();
receivedDMXBuffer.TryAdd(port.PortAddress, cdb);
}
if (!cdb.TryGetValue(sourceIp, out DMXReceiveBag bag))
var key = new Tuple<PortAddress, IPv4Address>(port.PortAddress, sourceIp);
if (!receivedDMXBuffer.TryGetValue(key, out DMXReceiveBag bag))
{
bag = new DMXReceiveBag(artDMX, sourceIp);
success = cdb.TryAdd(sourceIp, bag);
success = receivedDMXBuffer.TryAdd(key, bag);
}
else
success = bag.Update(artDMX, sourceIp);
Expand Down Expand Up @@ -965,22 +1003,19 @@ public void WriteDMXValues(PortAddress portAddress, byte[] data, ushort? startin
bag.Update(data, startindex, count);
else
{
var newBag = new DMXSendBag(data);
var newBag = new DMXSendBag(data, portAddress);
sendDMXBuffer.TryAdd(portAddress, newBag);
}
}
catch (Exception e) { Logger.LogError(e); }
}

public byte[] GetReceivedDMX(in PortAddress portAddress, EMergeMode mergeMode = EMergeMode.HTP)
public byte[] GetReceivedDMX(PortAddress portAddress, EMergeMode mergeMode = EMergeMode.HTP)
{
if (this.IsDisposing || this.IsDisposed)
return null;

if (!receivedDMXBuffer.TryGetValue(portAddress, out ConcurrentDictionary<IPv4Address, DMXReceiveBag> cdb))
if (this.IsDisposing || this.IsDisposed || this.receivedDMXBuffer.IsEmpty)
return null;

var bags = cdb.Select(b => b.Value).ToList();
var bags = receivedDMXBuffer.Values.Where(v => v.PortAddress == portAddress).ToList();

if (bags.Count == 0)
return null;
Expand Down Expand Up @@ -1162,11 +1197,20 @@ void IDisposable.Dispose()
_timerSendPoll.Elapsed -= TimerSendPoll_Elapsed;
_timerSendPoll.Enabled = false;

foreach (var rBuffer in receivedDMXBuffer.Values)
rBuffer.Dispose();
receivedDMXBuffer.Clear();

foreach (var sBuffer in sendDMXBuffer.Values)
sBuffer.Dispose();
sendDMXBuffer.Clear();

RemovePortConfig(portConfigs.ToArray());

portConfigs.Clear();
remoteClients.Clear();
knownControllerRDMUIDs.Clear();
knownRDMUIDs.Clear();
RemoteClients = null;

Dispose();
Expand Down
3 changes: 3 additions & 0 deletions ArtNetTests/LoopTests/ControllerToControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ArtNetSharp;
using ArtNetSharp.Communication;
using ArtNetTests.Mocks;
using Microsoft.Extensions.Logging;
using RDMSharp;
using System.Diagnostics;

Expand All @@ -9,6 +10,7 @@ namespace ArtNetTests.LoopTests
[Order(20)]
public class ControllerToControllerTests
{
private static readonly ILogger Logger = ApplicationLogging.CreateLogger<ControllerToControllerTests>();
private ArtNet artNet;
private ControllerInstanceMock instanceTX;
private OutputPortConfig outputPort;
Expand All @@ -23,6 +25,7 @@ public class ControllerToControllerTests
[OneTimeSetUp]
public void OneTimeSetUp()
{
Logger.LogDebug($"Test Setup: {nameof(ControllerToControllerTests)}");
ArtNet.Clear();

artNet = ArtNet.Instance;
Expand Down

0 comments on commit c6d35c2

Please sign in to comment.