From d0d6eae78f41999438b9cd7564265139c2edf0be Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 11 Feb 2023 18:14:02 +0100 Subject: [PATCH] feat(pcap): add running indication to pcap nostale client so it won't be run multiple times --- Pcap/NosSmooth.Pcap/PcapNostaleClient.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs b/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs index f84d30e..be12080 100644 --- a/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs +++ b/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs @@ -39,6 +39,7 @@ public class PcapNostaleClient : BaseNostaleClient private int _localPort; private long _localAddr; private CancellationToken? _stoppingToken; + private bool _running; /// /// Initializes a new instance of the class. @@ -74,6 +75,13 @@ public class PcapNostaleClient : BaseNostaleClient /// public override async Task RunAsync(CancellationToken stopRequested = default) { + if (_running) + { + return Result.FromSuccess(); + } + + _running = true; + _stoppingToken = stopRequested; TcpConnection? lastConnection = null; TcpConnection? reverseLastConnection = null; @@ -150,6 +158,8 @@ public class PcapNostaleClient : BaseNostaleClient { _pcapManager.UnregisterConnection(reverseLastConnection.Value); } + + _running = false; } return Result.FromSuccess(); -- 2.48.1