mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Backport of: 2129 cancellation token backport (#2144)
* Increase version * Update release notes * Adjust cancellation token handling * Fix CI build
This commit is contained in:
@@ -1051,10 +1051,13 @@ namespace MQTTnet.Client
|
||||
|
||||
if (timeWithoutPacketSent > keepAlivePeriod)
|
||||
{
|
||||
using (var timeoutCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
|
||||
using (var pingTimeout = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken))
|
||||
{
|
||||
timeoutCancellationTokenSource.CancelAfter(Options.Timeout);
|
||||
await PingAsync(timeoutCancellationTokenSource.Token).ConfigureAwait(false);
|
||||
// We already reached the keep alive timeout. Due to the RFC part [MQTT-3.1.2-24] the server will wait another
|
||||
// 1/2 of the keep alive time. So we can also use this value as the timeout.
|
||||
pingTimeout.CancelAfter((int)(keepAlivePeriod.TotalMilliseconds / 2));
|
||||
|
||||
await PingAsync(pingTimeout.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user