Reset the keep alive monitor if a session is being resumed from a different (or same) client.

This commit is contained in:
Christian Kratky
2018-12-01 11:00:00 +01:00
parent ccc275902f
commit b091fee554
3 changed files with 15 additions and 2 deletions
@@ -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();
+7 -2
View File
@@ -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);
} }
} }