From 1b0e3b3575977ab7a1c6fcb310bd24ffdc9deaf5 Mon Sep 17 00:00:00 2001 From: YFdyh000 Date: Wed, 19 Feb 2020 00:11:51 +0800 Subject: [PATCH] =?UTF-8?q?tcping=E5=A2=9E=E5=8A=A05s=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=9C=BA=E5=88=B6;=20ping=E9=97=B4=E9=9A=94=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E8=87=B310ms?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN/Forms/MainForm.cs | 4 ++-- v2rayN/v2rayN/Handler/SpeedtestHandler.cs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 042159c6..c2f749a8 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -977,9 +977,9 @@ namespace v2rayN.Forms } private void ClearTestResult() { - for (int k = 0; k < lvSelecteds.Count; k++) + foreach (int s in lvSelecteds) { - SetTestResult(lvSelecteds[k], ""); + SetTestResult(s, ""); } } private void UpdateSpeedtestHandler(int index, string msg) diff --git a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs index 295650b0..367b198b 100644 --- a/v2rayN/v2rayN/Handler/SpeedtestHandler.cs +++ b/v2rayN/v2rayN/Handler/SpeedtestHandler.cs @@ -103,9 +103,8 @@ namespace v2rayN.Handler { try { - for (int k = 0; k < _selecteds.Count; k++) + foreach (int index in _selecteds) { - int index = _selecteds[k]; if (_config.vmess[index].configType == (int)EConfigType.Custom) { continue; @@ -121,7 +120,7 @@ namespace v2rayN.Handler } } - Thread.Sleep(100); + Thread.Sleep(10); } catch (Exception ex) @@ -262,8 +261,14 @@ namespace v2rayN.Handler var timer = new Stopwatch(); timer.Start(); - Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - clientSocket.Connect(new IPEndPoint(ipAddress, port)); + var endPoint = new IPEndPoint(ipAddress, port); + Socket clientSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + + IAsyncResult 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 = timer.Elapsed.Milliseconds; clientSocket.Close();