捕获OperationAborted异常

This commit is contained in:
xljiulang 2021-07-18 23:48:57 +08:00
parent a7304ea5e0
commit 0876c6b35d

View File

@ -126,12 +126,19 @@ namespace FastGithub.Dns
{
var remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
while (stoppingToken.IsCancellationRequested == false)
{
try
{
var result = await this.socket.ReceiveFromAsync(this.buffer, SocketFlags.None, remoteEndPoint);
var datas = new byte[result.ReceivedBytes];
this.buffer.AsSpan(0, datas.Length).CopyTo(datas);
this.HandleRequestAsync(datas, result.RemoteEndPoint, stoppingToken);
}
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.OperationAborted)
{
break;
}
}
}
/// <summary>