Commit e1cf60d6 authored by justcoding121's avatar justcoding121

#87 Fix abrupt termination of SSL connections

parent 44ba131c
......@@ -65,19 +65,18 @@ namespace Titanium.Web.Proxy.Helpers
sb.Append(Environment.NewLine);
}
var tcpConnection = await tcpConnectionFactory.CreateClient(bufferSize, connectionTimeOutSeconds,
remoteHostName, remotePort,
httpVersion, isHttps,
supportedProtocols, remoteCertificateValidationCallback, localCertificateSelectionCallback,
null, null, clientStream);
TcpClient tunnelClient = tcpConnection.TcpClient;
Stream tunnelStream = tcpConnection.Stream;
try
{
TcpClient tunnelClient = tcpConnection.TcpClient;
Stream tunnelStream = tcpConnection.Stream;
Task sendRelay;
//Now async relay all server=>client & client=>server data
......@@ -101,7 +100,7 @@ namespace Titanium.Web.Proxy.Helpers
}
finally
{
tunnelStream.Dispose();
tcpConnection.Dispose();
}
}
......
......@@ -44,11 +44,15 @@ namespace Titanium.Web.Proxy.Network
public void Dispose()
{
Stream.Dispose();
TcpClient.LingerState = new LingerOption(true, 0);
TcpClient.Client.Shutdown(SocketShutdown.Both);
TcpClient.Client.Disconnect(true);
TcpClient.Client.Close();
TcpClient.Client.Dispose();
Stream.Dispose();
TcpClient.Close();
}
}
}
......@@ -120,6 +120,8 @@ namespace Titanium.Web.Proxy.Network
stream.ReadTimeout = connectionTimeOutSeconds * 1000;
stream.WriteTimeout = connectionTimeOutSeconds * 1000;
client.NoDelay = true;
return new TcpConnection()
{
HostName = remoteHostName,
......
......@@ -381,10 +381,14 @@ namespace Titanium.Web.Proxy
if (tcpClient != null)
{
Task.Run(async () =>
{
try
{
tcpClient.NoDelay = true;
if (endPoint.GetType() == typeof(TransparentProxyEndPoint))
{
await HandleClient(endPoint as TransparentProxyEndPoint, tcpClient);
......@@ -393,16 +397,18 @@ namespace Titanium.Web.Proxy
{
await HandleClient(endPoint as ExplicitProxyEndPoint, tcpClient);
}
}
finally
{
if (tcpClient != null)
{
tcpClient.LingerState = new LingerOption(true, 0);
tcpClient.Client.Shutdown(SocketShutdown.Both);
tcpClient.Client.Disconnect(true);
tcpClient.Client.Close();
tcpClient.Client.Dispose();
tcpClient.Close();
}
}
});
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.Compression;
......
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