From 5b6c76c5fb435ce4ff34cefeb558d56f6c14fee2 Mon Sep 17 00:00:00 2001 From: Hakan Lindestaf Date: Sun, 3 Mar 2024 16:02:16 -0600 Subject: [PATCH] Revert back to not have the optimize send code in here --- src/Haukcode.sACN/SACNClient.cs | 81 --------------------------------- 1 file changed, 81 deletions(-) diff --git a/src/Haukcode.sACN/SACNClient.cs b/src/Haukcode.sACN/SACNClient.cs index d6cfb43..06e9f24 100644 --- a/src/Haukcode.sACN/SACNClient.cs +++ b/src/Haukcode.sACN/SACNClient.cs @@ -45,20 +45,6 @@ public SendData() } } - public class OutputData : IDisposable - { - public Stopwatch LastSent = Stopwatch.StartNew(); - - public double AgeMS => LastSent.Elapsed.TotalMilliseconds; - - public IMemoryOwner SendData; - - public void Dispose() - { - SendData.Dispose(); - } - } - private const int ReceiveBufferSize = 20480; private const int SendBufferSize = 1024; private static readonly IPEndPoint _blankEndpoint = new(IPAddress.Any, 0); @@ -83,7 +69,6 @@ public void Dispose() private int droppedPackets; private int slowSends; private readonly HashSet<(IPAddress Destination, ushort UniverseId)> usedDestinations = new(); - private readonly Dictionary<(IPAddress Destination, ushort UniverseId), OutputData> outputDataPerDestination = new(); public SACNClient(Guid senderId, string senderName, IPAddress localAddress, int port = 5568) { @@ -407,18 +392,11 @@ public void DropDMXUniverse(ushort universeId) /// Start code (default 0) public void SendMulticast(ushort universeId, ReadOnlyMemory data, byte priority = 100, ushort syncAddress = 0, byte startCode = 0) { - // See if we should send - if (SkipSending(null, universeId, data)) - return; - byte sequenceId = GetNewSequenceId(universeId); var packet = new SACNDataPacket(universeId, SenderName, SenderId, sequenceId, data, priority, syncAddress, startCode); SendPacket(universeId, packet); - - var outputData = UpdateOutputData(null, universeId); - data.CopyTo(outputData.SendData.Memory); } /// @@ -431,18 +409,11 @@ public void SendMulticast(ushort universeId, ReadOnlyMemory data, byte pri /// Start code (default 0) public void SendUnicast(IPAddress address, ushort universeId, ReadOnlyMemory data, byte priority = 100, ushort syncAddress = 0, byte startCode = 0) { - // See if we should send - if (SkipSending(address, universeId, data)) - return; - byte sequenceId = GetNewSequenceId(universeId); var packet = new SACNDataPacket(universeId, SenderName, SenderId, sequenceId, data, priority, syncAddress, startCode); SendPacket(universeId, address, packet); - - var outputData = UpdateOutputData(address, universeId); - data.CopyTo(outputData.SendData.Memory); } /// @@ -566,53 +537,6 @@ public void SendPacket(ushort universeId, SACNPacket packet) //} } - private bool SkipSending(IPAddress destination, ushort universeId, ReadOnlyMemory data) - { - if (!OptimizeSend) - return false; - - OutputData outputData; - lock (this.lockObject) - { - if (!this.outputDataPerDestination.TryGetValue((destination, universeId), out outputData)) - return false; - } - - if (outputData.AgeMS > 1_000) - // Send at least once every second - return false; - - // Check if the data has changed - if (data.Length != outputData.SendData.Memory.Length) - return false; - - if (data.Span.SequenceEqual(outputData.SendData.Memory.Span)) - // Identical - return true; - - return false; - } - - private OutputData UpdateOutputData(IPAddress destination, ushort universeId) - { - lock (this.lockObject) - { - if (!this.outputDataPerDestination.TryGetValue((destination, universeId), out var outputData)) - { - outputData = new OutputData - { - SendData = this.memoryPool.Rent(512) - }; - - this.outputDataPerDestination.Add((destination, universeId), outputData); - } - - outputData.LastSent.Restart(); - - return outputData; - } - } - public void WarmUpSockets(IEnumerable universeIds) { foreach (ushort universeId in universeIds) @@ -684,11 +608,6 @@ public void Dispose() this.listenSocket.Close(); this.listenSocket.Dispose(); - - foreach (var kvp in this.outputDataPerDestination) - { - kvp.Value.Dispose(); - } } } }