Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 6d0d8f6

Browse files
committed
fix
1 parent 8323f79 commit 6d0d8f6

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -395,41 +395,40 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
395395
tcpServerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
396396
}
397397

398-
((ProxySocket.ProxySocket)tcpServerSocket).Connect(ipAddress, port);
399-
// var connectTask = socks
400-
// ? ProxySocketConnectionTaskFactory.CreateTask((ProxySocket.ProxySocket)tcpServerSocket, ipAddress, port)
401-
// : SocketConnectionTaskFactory.CreateTask(tcpServerSocket, ipAddress, port);
402-
403-
// await Task.WhenAny(connectTask, Task.Delay(proxyServer.ConnectTimeOutSeconds * 1000, cancellationToken));
404-
// if (!connectTask.IsCompleted || !tcpServerSocket.Connected)
405-
// {
406-
// // here we can just do some cleanup and let the loop continue since
407-
// // we will either get a connection or wind up with a null tcpClient
408-
// // which will throw
409-
// try
410-
// {
411-
// connectTask.Dispose();
412-
// }
413-
// catch
414-
// {
415-
// // ignore
416-
// }
417-
// try
418-
// {
419-
//#if NET45
420-
// tcpServerSocket?.Close();
421-
//#else
422-
// tcpServerSocket?.Dispose();
423-
//#endif
424-
// tcpServerSocket = null;
425-
// }
426-
// catch
427-
// {
428-
// // ignore
429-
// }
430-
431-
// continue;
432-
// }
398+
var connectTask = socks
399+
? ProxySocketConnectionTaskFactory.CreateTask((ProxySocket.ProxySocket)tcpServerSocket, ipAddress, port)
400+
: SocketConnectionTaskFactory.CreateTask(tcpServerSocket, ipAddress, port);
401+
402+
await Task.WhenAny(connectTask, Task.Delay(proxyServer.ConnectTimeOutSeconds * 1000, cancellationToken));
403+
if (!connectTask.IsCompleted || !tcpServerSocket.Connected)
404+
{
405+
// here we can just do some cleanup and let the loop continue since
406+
// we will either get a connection or wind up with a null tcpClient
407+
// which will throw
408+
try
409+
{
410+
connectTask.Dispose();
411+
}
412+
catch
413+
{
414+
// ignore
415+
}
416+
try
417+
{
418+
#if NET45
419+
tcpServerSocket?.Close();
420+
#else
421+
tcpServerSocket?.Dispose();
422+
#endif
423+
tcpServerSocket = null;
424+
}
425+
catch
426+
{
427+
// ignore
428+
}
429+
430+
continue;
431+
}
433432

434433
break;
435434
}

0 commit comments

Comments
 (0)