Commit 1adcd863 authored by justcoding121's avatar justcoding121

implement IDisposable for TcpConnectionFactory

parent 8dae49ed
...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary> /// <summary>
/// A class that manages Tcp Connection to server used by this proxy server. /// A class that manages Tcp Connection to server used by this proxy server.
/// </summary> /// </summary>
internal class TcpConnectionFactory internal class TcpConnectionFactory : IDisposable
{ {
//Tcp server connection pool cache //Tcp server connection pool cache
private readonly ConcurrentDictionary<string, ConcurrentQueue<TcpServerConnection>> cache private readonly ConcurrentDictionary<string, ConcurrentQueue<TcpServerConnection>> cache
...@@ -33,6 +33,8 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -33,6 +33,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
//cache object race operations lock //cache object race operations lock
private readonly SemaphoreSlim @lock = new SemaphoreSlim(1); private readonly SemaphoreSlim @lock = new SemaphoreSlim(1);
private bool runCleanUpTask = true;
internal ProxyServer server { get; set; } internal ProxyServer server { get; set; }
internal TcpConnectionFactory(ProxyServer server) internal TcpConnectionFactory(ProxyServer server)
...@@ -284,8 +286,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -284,8 +286,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
private async Task ClearOutdatedConnections() private async Task ClearOutdatedConnections()
{ {
while (runCleanUpTask)
while (true)
{ {
foreach (var item in cache) foreach (var item in cache)
{ {
...@@ -354,5 +355,10 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -354,5 +355,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
return true; return true;
} }
public void Dispose()
{
runCleanUpTask = false;
}
} }
} }
...@@ -565,6 +565,7 @@ namespace Titanium.Web.Proxy ...@@ -565,6 +565,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints.Clear(); ProxyEndPoints.Clear();
CertificateManager?.StopClearIdleCertificates(); CertificateManager?.StopClearIdleCertificates();
tcpConnectionFactory.Dispose();
ProxyRunning = false; ProxyRunning = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment