Skip to content

Commit 816d1c9

Browse files
committed
🐛 TestStunClient3489Async
1 parent 69296f9 commit 816d1c9

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/BD.WTTS.Client.Plugins.Accelerator/Services.Implementation/NetworkTestService.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ static double GetRate(long byteArrayLength, double seconds)
202202

203203
#region RFC3489
204204

205-
StunClient3489? _stunClient;
206-
207205
/// <summary>
208206
/// 测试 STUN 客户端 基于 RFC3489
209207
/// </summary>
@@ -217,19 +215,17 @@ static double GetRate(long byteArrayLength, double seconds)
217215
string? testServerHostName = DEFAULT_TESTSERVER_HOSTNAME,
218216
int? testServerPort = DEFAULT_TESTSTUN3489_PORT,
219217
IPEndPoint? localIPEndPoint = null,
220-
bool force = false,
221218
CancellationToken cancellationToken = default
222219
)
223220
{
224221
testServerHostName ??= DEFAULT_TESTSERVER_HOSTNAME;
225222
testServerPort ??= DEFAULT_TESTSTUN3489_PORT;
226223

227-
if (_stunClient == null || force)
228-
_stunClient = await GetStunClient3489Async(testServerHostName, testServerPort.Value, localIPEndPoint);
224+
using var stunClient = await GetStunClient3489Async(testServerHostName, testServerPort.Value, localIPEndPoint);
229225

230226
try
231227
{
232-
await _stunClient.QueryAsync(cancellationToken);
228+
await stunClient.QueryAsync(cancellationToken);
233229
}
234230
catch (OperationCanceledException) { throw; }
235231
catch (Exception ex)
@@ -238,7 +234,7 @@ static double GetRate(long byteArrayLength, double seconds)
238234
return null;
239235
}
240236

241-
return _stunClient.State;
237+
return stunClient.State;
242238
}
243239

244240
private async ValueTask<StunClient3489> GetStunClient3489Async(string serverHostName, int port, IPEndPoint? localIPEndPoint = null)

src/BD.WTTS.Client.Plugins.Accelerator/Services/INetworkTestService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,12 @@ internal interface IStunTestService
9191
/// <param name="testServerHostName">STUN 服务地址</param>
9292
/// <param name="testServerPort">STUN 服务端口</param>
9393
/// <param name="localIPEndPoint">本机IP</param>
94-
/// <param name="force">刷新测试 Client</param>
9594
/// <remarks></remarks>
9695
/// <returns></returns>
9796
Task<ClassicStunResult?> TestStunClient3489Async(
9897
string? testServerHostName = default,
9998
int? testServerPort = default,
10099
IPEndPoint? localIPEndPoint = default,
101-
bool force = false,
102100
CancellationToken cancellationToken = default
103101
);
104102

0 commit comments

Comments
 (0)