Add missing overloads for client disconnect.

Add timeout for disconnect in managed client.
This commit is contained in:
Christian
2021-01-30 13:17:03 +01:00
parent c91a1f8572
commit a13874d8a5
4 changed files with 32 additions and 13 deletions
@@ -53,11 +53,11 @@ namespace MQTTnet.Extensions.ManagedClient
public bool IsConnected => InternalClient.IsConnected;
public bool IsStarted => _connectionCancellationToken != null;
public IMqttClient InternalClient { get; }
public int PendingApplicationMessagesCount => _messageQueue.Count;
public IManagedMqttClientOptions Options { get; private set; }
public IMqttClientConnectedHandler ConnectedHandler
@@ -92,7 +92,7 @@ namespace MQTTnet.Extensions.ManagedClient
if (options == null) throw new ArgumentNullException(nameof(options));
if (options.ClientOptions == null) throw new ArgumentException("The client options are not set.", nameof(options));
if (!_maintainConnectionTask?.IsCompleted ?? false) throw new InvalidOperationException("The managed client is already started.");
Options = options;
@@ -292,7 +292,14 @@ namespace MQTTnet.Extensions.ManagedClient
{
try
{
await InternalClient.DisconnectAsync().ConfigureAwait(false);
using (var disconnectTimeout = new CancellationTokenSource(Options.ClientOptions.CommunicationTimeout))
{
await InternalClient.DisconnectAsync(disconnectTimeout.Token).ConfigureAwait(false);
}
}
catch (OperationCanceledException)
{
_logger.Warning("Timeout while sending DISCONNECT packet.");
}
catch (Exception exception)
{