mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 17:53:03 +08:00
Merge branch 'master' into feature/Reason_Code_In_Subscription_Interceptor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Exceptions;
|
||||
using MQTTnet.Extensions.Rpc.Options;
|
||||
using MQTTnet.Extensions.Rpc.Options.TopicGeneration;
|
||||
@@ -74,6 +74,7 @@ namespace MQTTnet.Extensions.Rpc
|
||||
.WithTopic(requestTopic)
|
||||
.WithPayload(payload)
|
||||
.WithQualityOfServiceLevel(qualityOfServiceLevel)
|
||||
.WithResponseTopic(responseTopic)
|
||||
.Build();
|
||||
|
||||
try
|
||||
@@ -83,7 +84,7 @@ namespace MQTTnet.Extensions.Rpc
|
||||
#else
|
||||
var awaitable = new TaskCompletionSource<byte[]>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
#endif
|
||||
|
||||
|
||||
if (!_waitingCalls.TryAdd(responseTopic, awaitable))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MQTTnet.Exceptions
|
||||
{
|
||||
}
|
||||
|
||||
public MqttCommunicationTimedOutException(Exception innerException) : base(innerException)
|
||||
public MqttCommunicationTimedOutException(Exception innerException) : base("The operation has timed out.", innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,6 +431,31 @@ namespace MQTTnet.Server
|
||||
sessionShouldPersist = !connectPacket.CleanSession;
|
||||
}
|
||||
|
||||
bool sessionShouldPersist;
|
||||
|
||||
if (context.ProtocolVersion == MqttProtocolVersion.V500)
|
||||
{
|
||||
// MQTT 5.0 section 3.1.2.11.2
|
||||
// The Client and Server MUST store the Session State after the Network Connection is closed if the Session Expiry Interval is greater than 0 [MQTT-3.1.2-23].
|
||||
//
|
||||
// A Client that only wants to process messages while connected will set the Clean Start to 1 and set the Session Expiry Interval to 0.
|
||||
// It will not receive Application Messages published before it connected and has to subscribe afresh to any topics that it is interested
|
||||
// in each time it connects.
|
||||
|
||||
// Persist if SessionExpiryInterval != 0, but may start with a clean session
|
||||
sessionShouldPersist = context.SessionExpiryInterval.GetValueOrDefault() != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// MQTT 3.1.1 section 3.1.2.4: persist only if 'not CleanSession'
|
||||
//
|
||||
// If CleanSession is set to 1, the Client and Server MUST discard any previous Session and start a new one.
|
||||
// This Session lasts as long as the Network Connection. State data associated with this Session MUST NOT be
|
||||
// reused in any subsequent Session [MQTT-3.1.2-6].
|
||||
|
||||
sessionShouldPersist = !connectPacket.CleanSession;
|
||||
}
|
||||
|
||||
using (await _createConnectionSyncRoot.WaitAsync(CancellationToken.None).ConfigureAwait(false))
|
||||
{
|
||||
MqttSession session;
|
||||
@@ -450,6 +475,8 @@ namespace MQTTnet.Server
|
||||
else
|
||||
{
|
||||
_logger.Verbose("Reusing existing session of client '{0}'.", connectPacket.ClientId);
|
||||
// Session persistence could change for MQTT 5 clients that reconnect with different SessionExpiryInterval
|
||||
session.IsPersistent = sessionShouldPersist;
|
||||
connAckPacket.IsSessionPresent = true;
|
||||
session.Recover();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user