mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-26 08:02:59 +08:00
Refactor code.
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user