From: Matthew Endsley Date: Sun, 24 Jan 2021 17:24:04 +0000 (-0800) Subject: Allow subclasses to mark a connection as stale X-Git-Tag: 1.0.0~20^2~20 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=21c400dc402d8e62111ba29007841277dae50398;p=rhonda%2Fimpostor.hazel.git Allow subclasses to mark a connection as stale These connections will be disconnected at the next call to DisconnectOldConnections --- diff --git a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index dcb4268..7e2da60 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs @@ -75,6 +75,7 @@ namespace Hazel.Udp.FewerThreads } private ConcurrentDictionary allConnections = new ConcurrentDictionary(); + private ConcurrentStack staleConnections = new ConcurrentStack(); private BlockingCollection receiveQueue; private BlockingCollection sendQueue = new BlockingCollection(); @@ -127,6 +128,14 @@ namespace Hazel.Udp.FewerThreads this.Dispose(false); } + protected void MarkConnectionAsStale(ConnectionId connectionId) + { + if (this.allConnections.ContainsKey(connectionId.Id)) + { + this.staleConnections.Push(connectionId); + } + } + public void DisconnectOldConnections(TimeSpan maxAge, MessageWriter disconnectMessage) { var now = DateTime.UtcNow; @@ -137,6 +146,16 @@ namespace Hazel.Udp.FewerThreads conn.Disconnect("Stale Connection", disconnectMessage); } } + + ConnectionId connectionId; + while (this.staleConnections.TryPop(out connectionId)) + { + ThreadLimitedUdpServerConnection connection; + if (this.allConnections.TryGetValue(connectionId.Id, out connection)) + { + connection.Disconnect("Stale Connection", disconnectMessage); + } + } } private void ManageReliablePackets()