Commit 12d17b77 authored by Honfika's avatar Honfika

make easier to switch to netstandard

parent 46140093
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Titanium.Web.Proxy.Extensions
{
internal static class DotNetStandardExtensions
{
/// <summary>
/// Disposes the specified client.
/// Int .NET framework 4.5 the TcpClient class has no Dispose method,
/// it is available from .NET 4.6, see
/// https://msdn.microsoft.com/en-us/library/dn823304(v=vs.110).aspx
/// </summary>
/// <param name="client">The client.</param>
internal static void Dispose(this TcpClient client)
{
client.Close();
}
/// <summary>
/// Disposes the specified client.
/// Int .NET framework 4.5 the X509Store class has no Dispose method,
/// it is available from .NET 4.6, see
/// https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509store.dispose(v=vs.110).aspx
/// </summary>
/// <param name="client">The client.</param>
internal static void Dispose(this X509Store client)
{
client.Close();
}
}
}
...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Extensions ...@@ -26,7 +26,7 @@ namespace Titanium.Web.Proxy.Extensions
catch (SocketException e) catch (SocketException e)
{ {
// 10035 == WSAEWOULDBLOCK // 10035 == WSAEWOULDBLOCK
return e.NativeErrorCode.Equals(10035); return e.SocketErrorCode == SocketError.WouldBlock;
} }
finally finally
{ {
......
...@@ -7,6 +7,7 @@ using System.Linq; ...@@ -7,6 +7,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Network.Certificate; using Titanium.Web.Proxy.Network.Certificate;
...@@ -348,7 +349,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -348,7 +349,7 @@ namespace Titanium.Web.Proxy.Network
} }
finally finally
{ {
x509Store.Close(); x509Store.Dispose();
} }
} }
......
using System; using System;
using System.IO; using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
...@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -57,7 +58,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
Stream?.Close(); Stream?.Dispose();
StreamReader?.Dispose(); StreamReader?.Dispose();
...@@ -70,7 +71,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -70,7 +71,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion //It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes //due to default TCP CLOSE_WAIT timeout for 4 minutes
TcpClient.LingerState = new LingerOption(true, 0); TcpClient.LingerState = new LingerOption(true, 0);
TcpClient.Close(); TcpClient.Dispose();
} }
} }
catch catch
......
...@@ -77,7 +77,6 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -77,7 +77,6 @@ namespace Titanium.Web.Proxy.Network.Tcp
} }
await writer.WriteLineAsync(); await writer.WriteLineAsync();
await writer.FlushAsync(); await writer.FlushAsync();
writer.Close();
} }
using (var reader = new CustomBinaryReader(stream, server.BufferSize)) using (var reader = new CustomBinaryReader(stream, server.BufferSize))
...@@ -113,7 +112,7 @@ namespace Titanium.Web.Proxy.Network.Tcp ...@@ -113,7 +112,7 @@ namespace Titanium.Web.Proxy.Network.Tcp
catch (Exception) catch (Exception)
{ {
stream?.Dispose(); stream?.Dispose();
client?.Close(); client?.Dispose();
throw; throw;
} }
......
...@@ -8,6 +8,7 @@ using System.Security.Cryptography.X509Certificates; ...@@ -8,6 +8,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Helpers.WinHttp; using Titanium.Web.Proxy.Helpers.WinHttp;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
...@@ -723,7 +724,7 @@ namespace Titanium.Web.Proxy ...@@ -723,7 +724,7 @@ namespace Titanium.Web.Proxy
//It helps to avoid eventual deterioration of performance due to TCP port exhaustion //It helps to avoid eventual deterioration of performance due to TCP port exhaustion
//due to default TCP CLOSE_WAIT timeout for 4 minutes //due to default TCP CLOSE_WAIT timeout for 4 minutes
tcpClient.LingerState = new LingerOption(true, 0); tcpClient.LingerState = new LingerOption(true, 0);
tcpClient.Close(); tcpClient.Dispose();
} }
} }
catch catch
...@@ -744,7 +745,6 @@ namespace Titanium.Web.Proxy ...@@ -744,7 +745,6 @@ namespace Titanium.Web.Proxy
private void QuitListen(ProxyEndPoint endPoint) private void QuitListen(ProxyEndPoint endPoint)
{ {
endPoint.Listener.Stop(); endPoint.Listener.Stop();
endPoint.Listener.Server.Close();
endPoint.Listener.Server.Dispose(); endPoint.Listener.Server.Dispose();
} }
} }
......
...@@ -217,7 +217,6 @@ namespace Titanium.Web.Proxy ...@@ -217,7 +217,6 @@ namespace Titanium.Web.Proxy
/// <param name="serverConnection"></param> /// <param name="serverConnection"></param>
private void Dispose(Stream clientStream, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, TcpConnection serverConnection) private void Dispose(Stream clientStream, CustomBinaryReader clientStreamReader, StreamWriter clientStreamWriter, TcpConnection serverConnection)
{ {
clientStream?.Close();
clientStream?.Dispose(); clientStream?.Dispose();
clientStreamReader?.Dispose(); clientStreamReader?.Dispose();
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
<Compile Include="EventArguments\DataEventArgs.cs" /> <Compile Include="EventArguments\DataEventArgs.cs" />
<Compile Include="EventArguments\TunnelConnectEventArgs.cs" /> <Compile Include="EventArguments\TunnelConnectEventArgs.cs" />
<Compile Include="Extensions\ByteArrayExtensions.cs" /> <Compile Include="Extensions\ByteArrayExtensions.cs" />
<Compile Include="Extensions\DotNetStandardExtensions.cs" />
<Compile Include="Extensions\FuncExtensions.cs" /> <Compile Include="Extensions\FuncExtensions.cs" />
<Compile Include="Helpers\HttpHelper.cs" /> <Compile Include="Helpers\HttpHelper.cs" />
<Compile Include="Extensions\StringExtensions.cs" /> <Compile Include="Extensions\StringExtensions.cs" />
......
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