]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Acceptable. Time to improve
authorForest <forest@innersloth.com>
Sun, 6 Sep 2020 18:46:42 +0000 (11:46 -0700)
committerForest <forest@innersloth.com>
Sun, 6 Sep 2020 18:46:42 +0000 (11:46 -0700)
Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs
Hazel/FewerThreads/ThreadLimitedUdpServerConnection.cs

index 10076d77ff059a7638c6218fa916fa9f4ad52a7e..f0be65534d499161bea9b3db39562d252f982a06 100644 (file)
@@ -54,6 +54,22 @@ namespace Hazel.Udp.FewerThreads
         private BlockingCollection<ReceiveMessageInfo> receiveQueue;
         private Queue<SendMessageInfo> sendQueue = new Queue<SendMessageInfo>();
 
+        public int MaxAge
+        {
+            get
+            {
+                var now = DateTime.UtcNow;
+                TimeSpan max = new TimeSpan();
+                foreach (var con in allConnections.Values)
+                {
+                    var val = now - con.CreationTime;
+                    if (val > max) max = val;
+                }
+
+                return (int)max.TotalSeconds;
+            }
+        }
+
         public int ConnectionCount { get { return this.allConnections.Count; } }
         public int SendQueueLength { get { lock(this.sendQueue) return this.sendQueue.Count; } }
         public int ReceiveQueueLength { get { return this.receiveQueue.Count; } }
@@ -84,6 +100,18 @@ namespace Hazel.Udp.FewerThreads
         {
             this.Dispose(false);
         }
+
+        public void DisconnectOldConnections(TimeSpan maxAge, MessageWriter disconnectMessage)
+        {
+            var now = DateTime.UtcNow;
+            foreach (var conn in this.allConnections.Values)
+            {
+                if (now - conn.CreationTime > maxAge)
+                {
+                    conn.Disconnect("Stale Connection", disconnectMessage);
+                }
+            }
+        }
         
         private void ManageReliablePackets()
         {
index ee5d2cda808f8a565e89a54cf256328adfb12f2c..84acf5f871f40da1c19a627391e5451a8398a53b 100644 (file)
@@ -9,6 +9,8 @@ namespace Hazel.Udp.FewerThreads
     /// <inheritdoc/>
     internal sealed class ThreadLimitedUdpServerConnection : UdpConnection
     {
+        public readonly DateTime CreationTime = DateTime.UtcNow;
+
         /// <summary>
         ///     The connection listener that we use the socket of.
         /// </summary>