Commit 4633f88f authored by titanium007's avatar titanium007

close connection each request

parent dfc356cd
......@@ -20,7 +20,7 @@ namespace Titanium.Web.Proxy.Http
internal class TcpConnectionManager
{
static ConcurrentDictionary<string, ConcurrentStack<TcpConnection>> ConnectionCache = new ConcurrentDictionary<string, ConcurrentStack<TcpConnection>>();
static Dictionary<string, Stack<TcpConnection>> ConnectionCache = new Dictionary<string, Stack<TcpConnection>>();
public static TcpConnection GetClient(string Hostname, int port, bool IsSecure)
{
......@@ -28,17 +28,18 @@ namespace Titanium.Web.Proxy.Http
TcpConnection client;
lock (ConnectionCache)
{
ConcurrentStack<TcpConnection> connections;
Stack<TcpConnection> connections;
if (!ConnectionCache.TryGetValue(key, out connections))
{
return CreateClient(Hostname, port, IsSecure);
}
if (!connections.TryPop(out client))
if (connections.Count > 0)
{
return CreateClient(Hostname, port, IsSecure);
client = connections.Pop();
}
else
return CreateClient(Hostname, port, IsSecure);
}
return client;
}
......@@ -74,12 +75,12 @@ namespace Titanium.Web.Proxy.Http
lock (ConnectionCache)
{
ConcurrentStack<TcpConnection> connections;
Stack<TcpConnection> connections;
if (!ConnectionCache.TryGetValue(key, out connections))
{
connections = new ConcurrentStack<TcpConnection>();
connections = new Stack<TcpConnection>();
connections.Push(Client);
ConnectionCache.TryAdd(key, connections);
ConnectionCache.Add(key, connections);
}
connections.Push(Client);
......
......@@ -247,9 +247,10 @@ namespace Titanium.Web.Proxy
Dispose(client, clientStream, clientStreamReader, clientStreamWriter, args);
return;
}
//if (args.ProxySession.ProxyClient.Client.Connected)
args.ProxySession.ProxyClient.Client.Close();
// if (args.ProxySession.ProxyClient.Client.Connected)
// TcpConnectionManager.AddClient(args.ProxySession.Request.RequestUri.Host, args.ProxySession.Request.RequestUri.Port, args.IsHttps, args.ProxySession.ProxyClient);
// // read the next request
httpCmd = clientStreamReader.ReadLine();
......
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