mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Refactor code.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,9 +1,8 @@
|
||||
namespace MQTTnet.Client
|
||||
{
|
||||
public enum MqttClientConnectionStatus
|
||||
|
||||
{
|
||||
Disconnected = 0,
|
||||
Disconnected,
|
||||
Disconnecting,
|
||||
Connected,
|
||||
Connecting
|
||||
|
||||
Reference in New Issue
Block a user