Commit 4485303b authored by justcoding121's avatar justcoding121

refactor

parent 33d50f32
...@@ -181,12 +181,12 @@ namespace Titanium.Web.Proxy ...@@ -181,12 +181,12 @@ namespace Titanium.Web.Proxy
continue; continue;
} }
bool newConnection = false; //If prefetch task is available.
//Delay awaiting prefect task as far as possible.
if (serverConnection == null && prefetchTask != null) if (serverConnection == null && prefetchTask != null)
{ {
serverConnection = await prefetchTask; serverConnection = await prefetchTask;
newConnection = true; prefetchTask = null;
} }
// create a new connection if cache key changes // create a new connection if cache key changes
...@@ -197,14 +197,13 @@ namespace Titanium.Web.Proxy ...@@ -197,14 +197,13 @@ namespace Titanium.Web.Proxy
{ {
await tcpConnectionFactory.Release(serverConnection); await tcpConnectionFactory.Release(serverConnection);
serverConnection = null; serverConnection = null;
newConnection = true;
} }
//create
if (serverConnection == null) if (serverConnection == null)
{ {
serverConnection = await getServerConnection(args, false, serverConnection = await getServerConnection(args, false,
clientConnection.NegotiatedApplicationProtocol, cancellationToken); clientConnection.NegotiatedApplicationProtocol, cancellationToken);
newConnection = true;
} }
//for connection pool retry fails until cache is exhausted //for connection pool retry fails until cache is exhausted
...@@ -229,7 +228,7 @@ namespace Titanium.Web.Proxy ...@@ -229,7 +228,7 @@ namespace Titanium.Web.Proxy
catch (ServerConnectionException) catch (ServerConnectionException)
{ {
attempt++; attempt++;
if (!newConnection || !EnableConnectionPool || attempt == MaxCachedConnections + 1) if (!EnableConnectionPool || attempt == MaxCachedConnections + 1)
{ {
throw; throw;
} }
...@@ -263,13 +262,13 @@ namespace Titanium.Web.Proxy ...@@ -263,13 +262,13 @@ namespace Titanium.Web.Proxy
throw new Exception("Session was terminated by user."); throw new Exception("Session was terminated by user.");
} }
//With connection pool get connection for each HTTP session instead of per client connection. //Get/release server connection for each HTTP session instead of per client connection.
//That will be more efficient especially when client is holding connection but not using it //This will be more efficient especially when client is idly holding server connection
//between sessions without using it.
if (EnableConnectionPool) if (EnableConnectionPool)
{ {
await tcpConnectionFactory.Release(serverConnection); await tcpConnectionFactory.Release(serverConnection);
serverConnection = null; serverConnection = null;
prefetchTask = null;
} }
} }
...@@ -295,6 +294,12 @@ namespace Titanium.Web.Proxy ...@@ -295,6 +294,12 @@ namespace Titanium.Web.Proxy
{ {
await tcpConnectionFactory.Release(serverConnection, await tcpConnectionFactory.Release(serverConnection,
closeServerConnection); closeServerConnection);
if (prefetchTask!=null)
{
await tcpConnectionFactory.Release(await prefetchTask,
closeServerConnection);
}
} }
} }
......
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