mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 10:26:11 +08:00
Merge
This commit is contained in:
@@ -101,7 +101,7 @@ namespace MQTTnet.Server
|
||||
return _wasCleanDisconnect;
|
||||
}
|
||||
|
||||
public Task StopAsync(bool wasCleanDisconnect = false)
|
||||
public async Task StopAsync(MqttClientDisconnectType type)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -110,7 +110,7 @@ namespace MQTTnet.Server
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
_wasCleanDisconnect = wasCleanDisconnect;
|
||||
_wasCleanDisconnect = type == MqttClientDisconnectType.Clean;
|
||||
|
||||
_cancellationTokenSource?.Cancel(false);
|
||||
PendingMessagesQueue.WaitForCompletion();
|
||||
@@ -119,7 +119,7 @@ namespace MQTTnet.Server
|
||||
var willMessage = _willMessage;
|
||||
_willMessage = null; // clear willmessage so it is send just once
|
||||
|
||||
if (_willMessage != null && !wasCleanDisconnect)
|
||||
if (willMessage != null && !_wasCleanDisconnect)
|
||||
{
|
||||
_sessionsManager.StartDispatchApplicationMessage(this, willMessage);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ namespace MQTTnet.Server
|
||||
private Task StopDueToKeepAliveTimeoutAsync()
|
||||
{
|
||||
_logger.Info<MqttClientSession>("Client '{0}': Timeout while waiting for KeepAlive packet.", ClientId);
|
||||
return StopAsync();
|
||||
return StopAsync(MqttClientDisconnectType.NotClean);
|
||||
}
|
||||
|
||||
private async Task ReceivePacketsAsync(IMqttChannelAdapter adapter, CancellationToken cancellationToken)
|
||||
@@ -203,15 +203,18 @@ namespace MQTTnet.Server
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (MqttCommunicationException exception)
|
||||
{
|
||||
_logger.Warning<MqttClientSession>(exception, "Client '{0}': Communication exception while processing client packets.", ClientId);
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.Error<MqttClientSession>(exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId);
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
if (exception is MqttCommunicationException)
|
||||
{
|
||||
_logger.Warning<MqttClientSession>(exception, "Client '{0}': Communication exception while processing client packets.", ClientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error<MqttClientSession>(exception, "Client '{0}': Unhandled exception while processing client packets.", ClientId);
|
||||
}
|
||||
|
||||
await StopAsync(MqttClientDisconnectType.NotClean).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,16 +263,16 @@ namespace MQTTnet.Server
|
||||
|
||||
if (packet is MqttDisconnectPacket)
|
||||
{
|
||||
return StopAsync(true);
|
||||
return StopAsync(MqttClientDisconnectType.Clean);
|
||||
}
|
||||
|
||||
if (packet is MqttConnectPacket)
|
||||
{
|
||||
return StopAsync();
|
||||
return StopAsync(MqttClientDisconnectType.NotClean);
|
||||
}
|
||||
|
||||
_logger.Warning<MqttClientSession>("Client '{0}': Received not supported packet ({1}). Closing connection.", ClientId, packet);
|
||||
return StopAsync();
|
||||
return StopAsync(MqttClientDisconnectType.NotClean);
|
||||
}
|
||||
|
||||
private async Task EnqueueSubscribedRetainedMessagesAsync(ICollection<TopicFilter> topicFilters)
|
||||
@@ -288,7 +291,7 @@ namespace MQTTnet.Server
|
||||
|
||||
if (subscribeResult.CloseConnection)
|
||||
{
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
await StopAsync(MqttClientDisconnectType.NotClean).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await EnqueueSubscribedRetainedMessagesAsync(subscribePacket.TopicFilters).ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user