Skip to content

Commit b8f2c6e

Browse files
committed
refactor: 代码重构
1 parent 39ac0a3 commit b8f2c6e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/BootstrapBlazor/Services/TcpSocket/TcpSocketClientBase.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ public async ValueTask<bool> ConnectAsync(IPEndPoint endPoint, CancellationToken
109109
}
110110
catch (OperationCanceledException ex)
111111
{
112-
var message = token.IsCancellationRequested
113-
? $"TCP Socket connect operation was canceled from {LocalEndPoint} to {endPoint}"
114-
: $"TCP Socket connect operation timed out from {LocalEndPoint} to {endPoint}";
115-
Log(LogLevel.Warning, ex, message);
112+
if (token.IsCancellationRequested)
113+
{
114+
Log(LogLevel.Warning, ex, $"TCP Socket connect operation was canceled from {LocalEndPoint} to {endPoint}");
115+
}
116+
else
117+
{
118+
Log(LogLevel.Warning, ex, $"TCP Socket connect operation timed out from {LocalEndPoint} to {endPoint}");
119+
}
116120
}
117121
catch (Exception ex)
118122
{
@@ -241,9 +245,14 @@ private async ValueTask<int> ReceiveCoreAsync(ISocketClientProvider client, Memo
241245
}
242246
catch (OperationCanceledException ex)
243247
{
244-
Log(LogLevel.Warning, ex, token.IsCancellationRequested
245-
? $"TCP Socket receive operation canceled from {_localEndPoint} to {_remoteEndPoint}"
246-
: $"TCP Socket receive operation timed out from {_localEndPoint} to {_remoteEndPoint}");
248+
if (token.IsCancellationRequested)
249+
{
250+
Log(LogLevel.Warning, ex, $"TCP Socket receive operation canceled from {_localEndPoint} to {_remoteEndPoint}");
251+
}
252+
else
253+
{
254+
Log(LogLevel.Warning, ex, $"TCP Socket receive operation timed out from {_localEndPoint} to {_remoteEndPoint}");
255+
}
247256
}
248257
catch (Exception ex)
249258
{

0 commit comments

Comments
 (0)