From: Forest Date: Sun, 6 Sep 2020 18:46:42 +0000 (-0700) Subject: Acceptable. Time to improve X-Git-Tag: 1.0.0~27^2~3 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=376bc1cec72ffa955981860ad52c2053bc9ab16e;p=rhonda%2Fimpostor.hazel.git Acceptable. Time to improve --- diff --git a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index 10076d7..f0be655 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs @@ -54,6 +54,22 @@ namespace Hazel.Udp.FewerThreads private BlockingCollection receiveQueue; private Queue sendQueue = new Queue(); + 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() { diff --git a/Hazel/FewerThreads/ThreadLimitedUdpServerConnection.cs b/Hazel/FewerThreads/ThreadLimitedUdpServerConnection.cs index ee5d2cd..84acf5f 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpServerConnection.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpServerConnection.cs @@ -9,6 +9,8 @@ namespace Hazel.Udp.FewerThreads /// internal sealed class ThreadLimitedUdpServerConnection : UdpConnection { + public readonly DateTime CreationTime = DateTime.UtcNow; + /// /// The connection listener that we use the socket of. ///