mirror of
https://github.com/2dust/v2rayN.git
synced 2025-11-29 03:02:53 +00:00
Update SpeedtestService.cs
This commit is contained in:
parent
9137bd0924
commit
88a377ea9f
1 changed files with 13 additions and 15 deletions
|
|
@ -323,8 +323,6 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
|||
{
|
||||
var responseTime = -1;
|
||||
|
||||
try
|
||||
{
|
||||
if (!IPAddress.TryParse(url, out var ipAddress))
|
||||
{
|
||||
var ipHostInfo = await Dns.GetHostEntryAsync(url);
|
||||
|
|
@ -335,18 +333,18 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
|
|||
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
var timer = Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
await clientSocket.ConnectAsync(endPoint, cts.Token).ConfigureAwait(false);
|
||||
timer.Stop();
|
||||
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// 超时情况,responseTime保持为-1
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
timer.Stop();
|
||||
responseTime = (int)timer.Elapsed.TotalMilliseconds;
|
||||
}
|
||||
return responseTime;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue