Commit 8616de17 authored by justcoding121's avatar justcoding121

implement IDisposable for TcpConnectionFactory

parent b3499602
......@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// <summary>
/// A class that manages Tcp Connection to server used by this proxy server.
/// </summary>
internal class TcpConnectionFactory
internal class TcpConnectionFactory : IDisposable
{
//Tcp server connection pool cache
private readonly ConcurrentDictionary<string, ConcurrentQueue<TcpServerConnection>> cache
......@@ -33,6 +33,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
//cache object race operations lock
private readonly SemaphoreSlim @lock = new SemaphoreSlim(1);
private bool runCleanUpTask = true;
internal ProxyServer server { get; set; }
internal TcpConnectionFactory(ProxyServer server)
......@@ -284,8 +286,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
private async Task ClearOutdatedConnections()
{
while (true)
while (runCleanUpTask)
{
foreach (var item in cache)
{
......@@ -354,5 +355,10 @@ namespace Titanium.Web.Proxy.Network.Tcp
return true;
}
public void Dispose()
{
runCleanUpTask = false;
}
}
}
......@@ -565,6 +565,7 @@ namespace Titanium.Web.Proxy
ProxyEndPoints.Clear();
CertificateManager?.StopClearIdleCertificates();
tcpConnectionFactory.Dispose();
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