From f9a5e782ab8905d3a580456d174549f0223a6ba0 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Tue, 16 Jan 2018 17:58:48 +0200 Subject: Update amalgamation --- amalgamation/mqtt.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/amalgamation/mqtt.c b/amalgamation/mqtt.c index c0ff379..69d7acc 100644 --- a/amalgamation/mqtt.c +++ b/amalgamation/mqtt.c @@ -5835,7 +5835,20 @@ int MqttClientRunOnce(MqttClient *client, int timeout) if (SIMPLEQ_EMPTY(&client->sendQueue)) { + int64_t elapsed; + LOG_DEBUG("nothing to write"); + + // If there's nothing to write at this point and we haven't sent + // any packets in keepalive seconds, we should send a ping. + + elapsed = MqttGetCurrentTime() - client->lastPacketSentTime; + if (client->keepAlive > 0 && elapsed >= client->keepAlive*1000) + { + MqttClientQueueSimplePacket(client, MqttPacketTypePingReq); + client->pingSent = 1; + events |= EV_WRITE; + } } else { @@ -5923,15 +5936,6 @@ int MqttClientRunOnce(MqttClient *client, int timeout) client->pingSent = 0; client->stopped = 1; } - else if (SIMPLEQ_EMPTY(&client->sendQueue)) - { - int64_t elapsed = MqttGetCurrentTime() - client->lastPacketSentTime; - if (elapsed/1000 >= client->keepAlive && client->keepAlive > 0) - { - MqttClientQueueSimplePacket(client, MqttPacketTypePingReq); - client->pingSent = 1; - } - } } if (client->stopped) -- cgit v1.2.3