mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-24 22:53:04 +08:00
Reset the keep alive monitor if a session is being resumed from a different (or same) client.
This commit is contained in:
@@ -50,6 +50,12 @@ namespace MQTTnet.Server
|
|||||||
_isPaused = false;
|
_isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
_lastPacketReceivedTracker.Restart();
|
||||||
|
_lastNonKeepAlivePacketReceivedTracker.Restart();
|
||||||
|
}
|
||||||
|
|
||||||
public void PacketReceived(MqttBasePacket packet)
|
public void PacketReceived(MqttBasePacket packet)
|
||||||
{
|
{
|
||||||
_lastPacketReceivedTracker.Restart();
|
_lastPacketReceivedTracker.Restart();
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public string ClientId { get; }
|
public string ClientId { get; }
|
||||||
|
|
||||||
|
public void ResumeSession()
|
||||||
|
{
|
||||||
|
_keepAliveMonitor.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
public void FillStatus(MqttClientSessionStatus status)
|
public void FillStatus(MqttClientSessionStatus status)
|
||||||
{
|
{
|
||||||
status.ClientId = ClientId;
|
status.ClientId = ClientId;
|
||||||
@@ -87,11 +92,11 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
_cancellationTokenSource = new CancellationTokenSource();
|
_cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
//woraround for https://github.com/dotnet/corefx/issues/24430
|
//workaround for https://github.com/dotnet/corefx/issues/24430
|
||||||
#pragma warning disable 4014
|
#pragma warning disable 4014
|
||||||
_cleanupHandle = _cancellationTokenSource.Token.Register(() => CleanupAsync());
|
_cleanupHandle = _cancellationTokenSource.Token.Register(() => CleanupAsync());
|
||||||
#pragma warning restore 4014
|
#pragma warning restore 4014
|
||||||
//endworkaround
|
//end workaround
|
||||||
|
|
||||||
_wasCleanDisconnect = false;
|
_wasCleanDisconnect = false;
|
||||||
_willMessage = connectPacket.WillMessage;
|
_willMessage = connectPacket.WillMessage;
|
||||||
|
|||||||
@@ -312,6 +312,8 @@ namespace MQTTnet.Server
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
clientSession.ResumeSession();
|
||||||
|
|
||||||
_logger.Verbose("Reusing existing session of client '{0}'.", connectPacket.ClientId);
|
_logger.Verbose("Reusing existing session of client '{0}'.", connectPacket.ClientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user