Respect keep alive interval after sending

This commit is contained in:
Christoph Stichlberger
2018-06-04 16:00:03 +02:00
parent 782dcffc62
commit b38df9eecd
@@ -419,12 +419,14 @@ namespace MQTTnet.Client
keepAliveSendInterval = _options.KeepAliveSendInterval.Value; keepAliveSendInterval = _options.KeepAliveSendInterval.Value;
} }
if (_sendTracker.Elapsed > keepAliveSendInterval) var waitTime = keepAliveSendInterval - _sendTracker.Elapsed;
if (waitTime <= TimeSpan.Zero)
{ {
await SendAndReceiveAsync<MqttPingRespPacket>(new MqttPingReqPacket()).ConfigureAwait(false); await SendAndReceiveAsync<MqttPingRespPacket>(new MqttPingReqPacket()).ConfigureAwait(false);
waitTime = keepAliveSendInterval;
} }
await Task.Delay(keepAliveSendInterval, _cancellationTokenSource.Token).ConfigureAwait(false); await Task.Delay(waitTime, _cancellationTokenSource.Token).ConfigureAwait(false);
} }
} }
catch (Exception exception) catch (Exception exception)