mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
* Fix timestamp check in server keep-alive monitor * Retain the original client statistics property name - add comments to clarify meaning - add separate public "received" timestamp property * fix comment
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Server.Status;
|
||||
@@ -32,8 +32,17 @@ namespace MQTTnet.Server.Internal
|
||||
_lastNonKeepAlivePacketReceivedTimestamp = _connectedTimestamp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp of the last package that has been received from the client ("sent" from the client's perspective)
|
||||
/// </summary>
|
||||
public DateTime LastPacketSentTimestamp => _lastPacketSentTimestamp;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp of the last package that has been sent to the client ("received" from the client's perspective)
|
||||
/// </summary>
|
||||
public DateTime LastPacketReceivedTimestamp => _lastPacketReceivedTimestamp;
|
||||
|
||||
|
||||
public void HandleReceivedPacket(MqttBasePacket packet)
|
||||
{
|
||||
if (packet == null) throw new ArgumentNullException(nameof(packet));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client.Disconnecting;
|
||||
@@ -95,7 +95,7 @@ namespace MQTTnet.Server.Internal
|
||||
// If the client sends 1 sec. the server will allow up to 1.5 seconds.
|
||||
var maxDurationWithoutPacket = connection.KeepAlivePeriod * 1.5D;
|
||||
|
||||
var secondsWithoutPackage = (now - connection.Statistics.LastPacketReceivedTimestamp).TotalSeconds;
|
||||
var secondsWithoutPackage = (now - connection.Statistics.LastPacketSentTimestamp).TotalSeconds;
|
||||
if (secondsWithoutPackage < maxDurationWithoutPacket)
|
||||
{
|
||||
// A packet was received before the timeout is affected.
|
||||
|
||||
Reference in New Issue
Block a user