@@ -395,41 +395,40 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
395
395
tcpServerSocket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . ReuseAddress , true ) ;
396
396
}
397
397
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
+ }
433
432
434
433
break ;
435
434
}
0 commit comments