@@ -14,10 +14,10 @@ namespace MQTTnet.Core.Adapter | |||||
{ | { | ||||
public class MqttChannelCommunicationAdapter : IMqttCommunicationAdapter | public class MqttChannelCommunicationAdapter : IMqttCommunicationAdapter | ||||
{ | { | ||||
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); | |||||
private readonly ILogger<MqttChannelCommunicationAdapter> _logger; | private readonly ILogger<MqttChannelCommunicationAdapter> _logger; | ||||
private readonly IMqttCommunicationChannel _channel; | private readonly IMqttCommunicationChannel _channel; | ||||
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1); | |||||
public MqttChannelCommunicationAdapter(IMqttCommunicationChannel channel, IMqttPacketSerializer serializer, ILogger<MqttChannelCommunicationAdapter> logger) | public MqttChannelCommunicationAdapter(IMqttCommunicationChannel channel, IMqttPacketSerializer serializer, ILogger<MqttChannelCommunicationAdapter> logger) | ||||
{ | { | ||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||||
@@ -68,7 +68,6 @@ namespace MQTTnet.Core.Server | |||||
try | try | ||||
{ | { | ||||
// ReSharper disable once UseNullPropagation | |||||
if (_options.Storage != null) | if (_options.Storage != null) | ||||
{ | { | ||||
await _options.Storage.SaveRetainedMessagesAsync(allRetainedMessages); | await _options.Storage.SaveRetainedMessagesAsync(allRetainedMessages); | ||||
@@ -13,11 +13,11 @@ using Microsoft.Extensions.Options; | |||||
namespace MQTTnet.Core.Server | namespace MQTTnet.Core.Server | ||||
{ | { | ||||
public sealed class MqttClientSession : IDisposable | |||||
public sealed class MqttClientSession | |||||
{ | { | ||||
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager; | |||||
private readonly HashSet<ushort> _unacknowledgedPublishPackets = new HashSet<ushort>(); | private readonly HashSet<ushort> _unacknowledgedPublishPackets = new HashSet<ushort>(); | ||||
private readonly IMqttClientRetainedMessageManager _clientRetainedMessageManager; | |||||
private readonly MqttClientSubscriptionsManager _subscriptionsManager; | private readonly MqttClientSubscriptionsManager _subscriptionsManager; | ||||
private readonly MqttClientSessionsManager _sessionsManager; | private readonly MqttClientSessionsManager _sessionsManager; | ||||
private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; | private readonly MqttClientPendingMessagesQueue _pendingMessagesQueue; | ||||
@@ -113,12 +113,6 @@ namespace MQTTnet.Core.Server | |||||
_pendingMessagesQueue.Enqueue(publishPacket); | _pendingMessagesQueue.Enqueue(publishPacket); | ||||
} | } | ||||
public void Dispose() | |||||
{ | |||||
_cancellationTokenSource?.Cancel(); | |||||
_cancellationTokenSource?.Dispose(); | |||||
} | |||||
private async Task ReceivePacketsAsync(IMqttCommunicationAdapter adapter, CancellationToken cancellationToken) | private async Task ReceivePacketsAsync(IMqttCommunicationAdapter adapter, CancellationToken cancellationToken) | ||||
{ | { | ||||
try | try | ||||
@@ -164,10 +164,10 @@ namespace MQTTnet.Core.Server | |||||
if (connectPacket.CleanSession) | if (connectPacket.CleanSession) | ||||
{ | { | ||||
_clientSessions.Remove(connectPacket.ClientId); | _clientSessions.Remove(connectPacket.ClientId); | ||||
clientSession.Dispose(); | |||||
clientSession.Stop(); | |||||
clientSession = null; | clientSession = null; | ||||
_logger.LogTrace("Disposed existing session of client '{0}'.", connectPacket.ClientId); | |||||
_logger.LogTrace("Stopped existing session of client '{0}'.", connectPacket.ClientId); | |||||
} | } | ||||
else | else | ||||
{ | { | ||||