Refactor code.

This commit is contained in:
Christian
2021-04-05 12:50:42 +02:00
parent 962622a9f7
commit 77338527b4
3 changed files with 7 additions and 4 deletions
+1
View File
@@ -18,6 +18,7 @@
* [Client] Improved keep alive message sending. * [Client] Improved keep alive message sending.
* [Client] Added support for deferred message approval (#1075, thanks to @tkurucsai). * [Client] Added support for deferred message approval (#1075, thanks to @tkurucsai).
* [Client] Exposed missing APIs for .NET 5.0 build (thanks to @yyjdelete). * [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 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!). * [RpcClient] Fixed a race condition when using timeout and cancellation token at the same time (BREAKING CHANGE!).
* [Server] Improved keep alive message sending. * [Server] Improved keep alive message sending.
+5 -2
View File
@@ -320,10 +320,12 @@ namespace MQTTnet.Client
Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult) Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
{ {
var clientWasConnected = IsConnected; var clientWasConnected = IsConnected;
if (!DisconnectIsPendingOrFinished()) if (!DisconnectIsPendingOrFinished())
{ {
return DisconnectCoreAsync(sender, exception, authenticateResult, clientWasConnected); return DisconnectCoreAsync(sender, exception, authenticateResult, clientWasConnected);
} }
return PlatformAbstractionLayer.CompletedTask; 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 // This handler must be executed in a new thread because otherwise a dead lock may happen
// when trying to reconnect in that handler etc. // when trying to reconnect in that handler etc.
Task.Run(() => disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult, _disconnectReason))) Task.Run(() => disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult, _disconnectReason))).RunInBackground(_logger);
.RunInBackground(_logger);
} }
} }
} }
@@ -798,6 +799,7 @@ namespace MQTTnet.Client
bool DisconnectIsPendingOrFinished() bool DisconnectIsPendingOrFinished()
{ {
var connectionStatus = (MqttClientConnectionStatus)_connectionStatus; var connectionStatus = (MqttClientConnectionStatus)_connectionStatus;
do do
{ {
switch (connectionStatus) switch (connectionStatus)
@@ -814,6 +816,7 @@ namespace MQTTnet.Client
{ {
return false; return false;
} }
connectionStatus = curStatus; connectionStatus = curStatus;
break; break;
} }
@@ -1,9 +1,8 @@
namespace MQTTnet.Client namespace MQTTnet.Client
{ {
public enum MqttClientConnectionStatus public enum MqttClientConnectionStatus
{ {
Disconnected = 0, Disconnected,
Disconnecting, Disconnecting,
Connected, Connected,
Connecting Connecting