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);
} }
} }
......
...@@ -161,30 +161,23 @@ namespace Titanium.Web.Proxy ...@@ -161,30 +161,23 @@ 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) if (clientStream.Available > 0)
{ {
if (clientStream.Available > 0) //send the buffered data
{ var data = new byte[clientStream.Available];
//send the buffered data await clientStream.ReadAsync(data, 0, data.Length);
var data = new byte[clientStream.Available]; await connection.StreamWriter.WriteAsync(data, true);
await clientStream.ReadAsync(data, 0, data.Length);
await connection.StreamWriter.WriteAsync(data, true);
}
var serverHelloInfo = await SslTools.PeekServerHello(connection.Stream);
((ConnectResponse)connectArgs.WebSession.Response).ServerHelloInfo = serverHelloInfo;
} }
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize, var serverHelloInfo = await SslTools.PeekServerHello(connection.Stream);
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); }, ((ConnectResponse)connectArgs.WebSession.Response).ServerHelloInfo = serverHelloInfo;
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); });
}
finally
{
UpdateServerConnectionCount(false);
} }
await TcpHelper.SendRaw(clientStream, connection.Stream, BufferSize,
(buffer, offset, count) => { connectArgs.OnDataSent(buffer, offset, count); },
(buffer, offset, count) => { connectArgs.OnDataReceived(buffer, offset, count); });
} }
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