mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Added custom exception for gracefully closed exceptions.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace MQTTnet.Exceptions
|
||||
{
|
||||
public class MqttCommunicationClosedGracefullyException : MqttCommunicationException
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,8 @@ namespace MQTTnet.Implementations
|
||||
await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_logger.Verbose($"Client '{clientSocket.RemoteEndPoint}' accepted by TCP listener '{_socket.LocalEndPoint}, {_addressFamily}'.");
|
||||
|
||||
var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, null), new MqttPacketSerializer(), _logger);
|
||||
ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace MQTTnet.Internal
|
||||
{
|
||||
public static void ThrowGracefulSocketClose()
|
||||
{
|
||||
throw new MqttCommunicationException("Connection gracefully closed from the remote party.");
|
||||
throw new MqttCommunicationClosedGracefullyException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,14 @@ namespace MQTTnet.Server
|
||||
{
|
||||
if (exception is MqttCommunicationException)
|
||||
{
|
||||
_logger.Warning(exception, "Client '{0}': Communication exception while receiving client packets.", ClientId);
|
||||
if (exception is MqttCommunicationClosedGracefullyException)
|
||||
{
|
||||
_logger.Verbose("Client '{0}': Connection closed gracefully.", ClientId); ;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warning(exception, "Client '{0}': Communication exception while receiving client packets.", ClientId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user