Procházet zdrojové kódy

* Cancel the TokenSource when disposing or nulling it out for the MqttClient

release/3.x.x
Andre Crabb před 6 roky
rodič
revize
39bc70cbf0
2 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. +4
    -4
      Source/MQTTnet/Client/MqttClient.cs
  2. +3
    -1
      Source/MQTTnet/Server/MqttClientSession.cs

+ 4
- 4
Source/MQTTnet/Client/MqttClient.cs Zobrazit soubor

@@ -176,10 +176,12 @@ namespace MQTTnet.Client

public void Dispose()
{
_cancellationTokenSource?.Cancel ();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;

_adapter?.Dispose();
_adapter = null;
}

private async Task<MqttConnAckPacket> AuthenticateAsync(MqttApplicationMessage willApplicationMessage, CancellationToken cancellationToken)
@@ -238,10 +240,7 @@ namespace MQTTnet.Client
}
finally
{
_adapter?.Dispose();
_adapter = null;
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
Dispose ();
_cleanDisconnectInitiated = false;

_logger.Info("Disconnected.");
@@ -384,6 +383,7 @@ namespace MQTTnet.Client

if (exception is OperationCanceledException)
{
_logger.Info ("MQTT OperationCanceled exception while receiving packets.");
}
else if (exception is MqttCommunicationException)
{


+ 3
- 1
Source/MQTTnet/Server/MqttClientSession.cs Zobrazit soubor

@@ -125,7 +125,7 @@ namespace MQTTnet.Server
}

_adapter = null;
_cancellationTokenSource?.Cancel ();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}
@@ -240,7 +240,9 @@ namespace MQTTnet.Server
{
_pendingPacketsQueue?.Dispose();

_cancellationTokenSource?.Cancel ();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}

private void ProcessReceivedPacket(IMqttChannelAdapter adapter, MqttBasePacket packet, CancellationToken cancellationToken)


Načítá se…
Zrušit
Uložit