Browse Source

Refactor code.

release/3.x.x
Christian 3 years ago
parent
commit
77338527b4
3 changed files with 7 additions and 4 deletions
  1. +1
    -0
      Build/MQTTnet.nuspec
  2. +5
    -2
      Source/MQTTnet/Client/MqttClient.cs
  3. +1
    -2
      Source/MQTTnet/Client/MqttClientConnectionStatus.cs

+ 1
- 0
Build/MQTTnet.nuspec View File

@@ -18,6 +18,7 @@
* [Client] Improved keep alive message sending.
* [Client] Added support for deferred message approval (#1075, thanks to @tkurucsai).
* [Client] Exposed missing APIs for .NET 5.0 build (thanks to @yyjdelete).
* [Client] Improved disconnect handling (#1134, thanks to @yyjdelete).
* [RpcClient] Fixed an issue when using a custom application message reveived handler (#1093).
* [RpcClient] Fixed a race condition when using timeout and cancellation token at the same time (BREAKING CHANGE!).
* [Server] Improved keep alive message sending.


+ 5
- 2
Source/MQTTnet/Client/MqttClient.cs View File

@@ -320,10 +320,12 @@ namespace MQTTnet.Client
Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
{
var clientWasConnected = IsConnected;
if (!DisconnectIsPendingOrFinished())
{
return DisconnectCoreAsync(sender, exception, authenticateResult, clientWasConnected);
}
return PlatformAbstractionLayer.CompletedTask;
}

@@ -371,8 +373,7 @@ namespace MQTTnet.Client
{
// This handler must be executed in a new thread because otherwise a dead lock may happen
// when trying to reconnect in that handler etc.
Task.Run(() => disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult, _disconnectReason)))
.RunInBackground(_logger);
Task.Run(() => disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult, _disconnectReason))).RunInBackground(_logger);
}
}
}
@@ -798,6 +799,7 @@ namespace MQTTnet.Client
bool DisconnectIsPendingOrFinished()
{
var connectionStatus = (MqttClientConnectionStatus)_connectionStatus;
do
{
switch (connectionStatus)
@@ -814,6 +816,7 @@ namespace MQTTnet.Client
{
return false;
}
connectionStatus = curStatus;
break;
}


+ 1
- 2
Source/MQTTnet/Client/MqttClientConnectionStatus.cs View File

@@ -1,9 +1,8 @@
namespace MQTTnet.Client
{
public enum MqttClientConnectionStatus

{
Disconnected = 0,
Disconnected,
Disconnecting,
Connected,
Connecting


Loading…
Cancel
Save