mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 08:42:37 +08:00
Merge pull request #941 from chkr1011/disconnect-reason-codes
Added missing disconnect reason codes.
This commit is contained in:
@@ -3,6 +3,34 @@
|
|||||||
public enum MqttClientDisconnectReason
|
public enum MqttClientDisconnectReason
|
||||||
{
|
{
|
||||||
NormalDisconnection = 0,
|
NormalDisconnection = 0,
|
||||||
|
DisconnectWithWillMessage = 4,
|
||||||
|
UnspecifiedError = 128,
|
||||||
|
MalformedPacket = 129,
|
||||||
|
ProtocolError = 130,
|
||||||
|
ImplementationSpecificError = 131,
|
||||||
|
NotAuthorized = 135,
|
||||||
|
ServerBusy = 137,
|
||||||
|
ServerShuttingDown = 139,
|
||||||
|
BadAuthenticationMethod = 140,
|
||||||
|
KeepaliveTimeout = 141,
|
||||||
|
SessionTakenOver = 142,
|
||||||
|
TopicFilterInvalid = 143,
|
||||||
|
TopicNameInvalid = 144,
|
||||||
|
ReceiveMaximumExceeded = 147,
|
||||||
|
TopicAliasInvalid = 148,
|
||||||
|
PacketTooLarge = 149,
|
||||||
|
MessageRateTooHigh = 150,
|
||||||
|
QuotaExceeded = 151,
|
||||||
|
AdministrativeAction = 152,
|
||||||
|
PayloadFormatInvalid = 153,
|
||||||
|
RetainNotSupported = 154,
|
||||||
|
QosNotSupported = 155,
|
||||||
|
UseAnotherServer = 156,
|
||||||
|
ServerMoved = 157,
|
||||||
|
SharedSubscriptionsNotSupported = 158,
|
||||||
|
ConnectionRateExceeded = 159,
|
||||||
|
MaximumConnectTime = 160,
|
||||||
|
SubscriptionIdentifiersNotSupported = 161,
|
||||||
|
WildcardSubscriptionsNotSupported = 162
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ namespace MQTTnet.Client.Disconnecting
|
|||||||
{
|
{
|
||||||
public class MqttClientDisconnectedEventArgs : EventArgs
|
public class MqttClientDisconnectedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public MqttClientDisconnectedEventArgs(bool clientWasConnected, Exception exception, MqttClientAuthenticateResult authenticateResult)
|
public MqttClientDisconnectedEventArgs(bool clientWasConnected, Exception exception, MqttClientAuthenticateResult authenticateResult, MqttClientDisconnectReason reasonCode)
|
||||||
{
|
{
|
||||||
ClientWasConnected = clientWasConnected;
|
ClientWasConnected = clientWasConnected;
|
||||||
Exception = exception;
|
Exception = exception;
|
||||||
AuthenticateResult = authenticateResult;
|
AuthenticateResult = authenticateResult;
|
||||||
|
ReasonCode = reasonCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ClientWasConnected { get; }
|
public bool ClientWasConnected { get; }
|
||||||
@@ -17,5 +18,7 @@ namespace MQTTnet.Client.Disconnecting
|
|||||||
public Exception Exception { get; }
|
public Exception Exception { get; }
|
||||||
|
|
||||||
public MqttClientAuthenticateResult AuthenticateResult { get; }
|
public MqttClientAuthenticateResult AuthenticateResult { get; }
|
||||||
|
|
||||||
|
public MqttClientDisconnectReason ReasonCode { get; set; } = MqttClientDisconnectReason.NormalDisconnection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,6 +303,7 @@ namespace MQTTnet.Client
|
|||||||
async Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
|
async Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
|
||||||
{
|
{
|
||||||
var clientWasConnected = IsConnected;
|
var clientWasConnected = IsConnected;
|
||||||
|
var reasonCode = MqttClientDisconnectReason.NormalDisconnection;
|
||||||
|
|
||||||
TryInitiateDisconnect();
|
TryInitiateDisconnect();
|
||||||
_isConnected = false;
|
_isConnected = false;
|
||||||
@@ -320,6 +321,7 @@ namespace MQTTnet.Client
|
|||||||
catch (Exception adapterException)
|
catch (Exception adapterException)
|
||||||
{
|
{
|
||||||
_logger.Warning(adapterException, "Error while disconnecting from adapter.");
|
_logger.Warning(adapterException, "Error while disconnecting from adapter.");
|
||||||
|
reasonCode = MqttClientDisconnectReason.UnspecifiedError;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -335,6 +337,7 @@ namespace MQTTnet.Client
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(e, "Error while waiting for internal tasks.");
|
_logger.Warning(e, "Error while waiting for internal tasks.");
|
||||||
|
reasonCode = MqttClientDisconnectReason.UnspecifiedError;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -348,7 +351,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))).Forget(_logger);
|
Task.Run(() => disconnectedHandler.HandleDisconnectedAsync(new MqttClientDisconnectedEventArgs(clientWasConnected, exception, authenticateResult, reasonCode))).Forget(_logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user