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