From 87731174938d7a3669bcbc9ed4c137f54371bb8e Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 21 Jan 2018 14:09:34 +0100 Subject: [PATCH] Fix an issue which adds a delay after every accepted connection. --- .../Implementations/MqttServerAdapter.cs | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index b4869ff..0d0429d 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -110,22 +110,14 @@ namespace MQTTnet.Implementations { // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. } - catch (SocketException exception) + catch (Exception exception) { - if (exception.SocketErrorCode == SocketError.OperationAborted) + if (exception is SocketException s && s.SocketErrorCode == SocketError.OperationAborted) { return; } _logger.Error(exception, "Error while accepting connection at default endpoint."); - } - catch (Exception exception) - { - _logger.Error(exception, "Error while accepting connection at default endpoint."); - } - finally - { - //excessive CPU consumed if in endless loop of socket errors await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } } @@ -153,22 +145,14 @@ namespace MQTTnet.Implementations { // It can happen that the listener socket is accessed after the cancellation token is already set and the listener socket is disposed. } - catch (SocketException exception) + catch (Exception exception) { - if (exception.SocketErrorCode == SocketError.OperationAborted) + if (exception is SocketException s && s.SocketErrorCode == SocketError.OperationAborted) { return; } - _logger.Error(exception, "Error while accepting connection at default endpoint."); - } - catch (Exception exception) - { _logger.Error(exception, "Error while accepting connection at TLS endpoint."); - } - finally - { - //excessive CPU consumed if in endless loop of socket errors await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); } }