]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Allow subclasses to mark a connection as stale
authorMatthew Endsley <mendsley@gmail.com>
Sun, 24 Jan 2021 17:24:04 +0000 (09:24 -0800)
committerMatthew Endsley <mendsley@gmail.com>
Tue, 2 Feb 2021 16:53:34 +0000 (08:53 -0800)
These connections will be disconnected at the next call to DisconnectOldConnections

Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs

index dcb42689d327a1c3958909c54a9333ba8f4fc23c..7e2da604af30aa1920123b6eb9c6588c4691b4eb 100644 (file)
@@ -75,6 +75,7 @@ namespace Hazel.Udp.FewerThreads
         }
 
         private ConcurrentDictionary<ulong, ThreadLimitedUdpServerConnection> allConnections = new ConcurrentDictionary<ulong, ThreadLimitedUdpServerConnection>();
+        private ConcurrentStack<ConnectionId> staleConnections = new ConcurrentStack<ConnectionId>();
 
         private BlockingCollection<ReceiveMessageInfo> receiveQueue;
         private BlockingCollection<SendMessageInfo> sendQueue = new BlockingCollection<SendMessageInfo>();
@@ -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()