]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
Remove message from inflight when not connected
authorHmvp <hmvp@hmvp.nl>
Tue, 16 Sep 2014 08:34:24 +0000 (10:34 +0200)
committerHmvp <hmvp@hmvp.nl>
Tue, 16 Sep 2014 14:12:01 +0000 (16:12 +0200)
Publishes with qos > 0 which are sent before a CONACK is received are still counted as inflight
even though they don't really get sent.  This means they get sent after the retry period (20 sec default)

But this won't work when max_inflight is 1 since this means no retry will get sent and we wait untill keepalive is exhausted
This then forces a reconnect and will reset stuff so messages can be sent.

Change-Id: I516a6cce8e5bbfbd3030711a80044af4e5bf6733
Signed-off-by: Hmvp <hmvp@hmvp.nl>
src/paho/mqtt/client.py

index b46dc1e207ca9a57a0d6f5628ebe89c6f1446614..75de42530e155f59ba0708dd8f3325e5e79ddb2d 100755 (executable)
@@ -909,6 +909,16 @@ class Client(object):
                 self._out_message_mutex.release()
 
                 rc = self._send_publish(message.mid, message.topic, message.payload, message.qos, message.retain, message.dup)
+
+                # remove from inflight messages so it will be send after a connection is made
+                if rc is MQTT_ERR_NO_CONN:
+                    with self._out_message_mutex:
+                        self._inflight_messages -= 1
+                        if qos == 1:
+                            message.state = mqtt_ms_publish_qos1
+                        elif qos == 2:
+                            message.state = mqtt_ms_publish_qos2
+
                 return (rc, local_mid)
             else:
                 message.state = mqtt_ms_queued;