Commit e7a9d66a authored by Honfika's avatar Honfika

Update server connection count only in TcpConnection class

parent 40cd60cc
......@@ -13,6 +13,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary>
internal class TcpConnection : IDisposable
{
private ProxyServer proxyServer { get; }
internal ExternalProxy UpStreamProxy { get; set; }
internal string HostName { get; set; }
......@@ -55,9 +57,11 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary>
internal DateTime LastAccess { get; set; }
internal TcpConnection()
internal TcpConnection(ProxyServer proxyServer)
{
LastAccess = DateTime.Now;
this.proxyServer = proxyServer;
this.proxyServer.UpdateServerConnectionCount(true);
}
/// <summary>
......@@ -70,6 +74,8 @@ namespace Titanium.Web.Proxy.Network.Tcp
Stream?.Dispose();
TcpClient.CloseSocket();
proxyServer.UpdateServerConnectionCount(false);
}
}
}
......@@ -116,9 +116,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
throw;
}
server.UpdateServerConnectionCount(true);
return new TcpConnection
return new TcpConnection(server)
{
UpStreamProxy = externalProxy,
UpStreamEndPoint = upStreamEndPoint,
......
......@@ -621,7 +621,6 @@ namespace Titanium.Web.Proxy
{
serverConnection.Dispose();
serverConnection = null;
UpdateServerConnectionCount(false);
}
}
......
......@@ -160,8 +160,6 @@ namespace Titanium.Web.Proxy
{
//create new connection
using (var connection = await GetServerConnection(connectArgs, true))
{
try
{
if (isClientHello)
{
......@@ -181,11 +179,6 @@ namespace Titanium.Web.Proxy
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); });
}
finally
{
UpdateServerConnectionCount(false);
}
}
return;
}
......@@ -370,7 +363,6 @@ namespace Titanium.Web.Proxy
{
connection.Dispose();
connection = null;
UpdateServerConnectionCount(false);
}
if (connection == null)
......
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