From aa133bb50b9566417f0054bc1627f92b450f4a10 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 23 Feb 2025 16:34:40 +0800 Subject: [PATCH] Update SpeedtestService.cs --- v2rayN/ServiceLib/Services/SpeedtestService.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index 8cf3964f..37cb83b3 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -336,21 +336,19 @@ namespace ServiceLib.Services ipAddress = ipHostInfo.AddressList.First(); } - var timer = Stopwatch.StartNew(); - IPEndPoint endPoint = new(ipAddress, port); using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + var timer = Stopwatch.StartNew(); var result = clientSocket.BeginConnect(endPoint, null, null); if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5))) { throw new TimeoutException("connect timeout (5s): " + url); } - - clientSocket.EndConnect(result); - timer.Stop(); responseTime = (int)timer.Elapsed.TotalMilliseconds; + + clientSocket.EndConnect(result); } catch (Exception ex) {