aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2018-01-16 17:58:48 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2018-01-16 17:58:48 +0200
commitf9a5e782ab8905d3a580456d174549f0223a6ba0 (patch)
treed4d9caf878929a2128e1d3a2c6fce3f507399f0e
parentfe74d0707215320a23ed10f989e87437c4f7ea4d (diff)
downloadmqtt-master.tar.gz
mqtt-master.zip
Update amalgamationHEADv0.6master
-rw-r--r--amalgamation/mqtt.c22
1 files 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)