From 47553f0f5ad1f5a79398c0dffb92cfc7283315bf Mon Sep 17 00:00:00 2001 From: Pierre Goudet Date: Tue, 22 May 2018 14:02:25 +0900 Subject: [PATCH] Fix qos=0 --- lib/paho_mqtt/publisher.rb | 7 ++++--- spec/client_spec.rb | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/paho_mqtt/publisher.rb b/lib/paho_mqtt/publisher.rb index 93533e8..a08729b 100644 --- a/lib/paho_mqtt/publisher.rb +++ b/lib/paho_mqtt/publisher.rb @@ -45,6 +45,7 @@ def send_publish(topic, payload, retain, qos, new_id) when 2 push_queue(@waiting_pubrec, @pubrec_mutex, MAX_PUBREC, packet, new_id) end + @sender.append_to_writing(packet) MQTT_ERR_SUCCESS end @@ -56,7 +57,6 @@ def push_queue(waiting_queue, queue_mutex, max_packet, packet, new_id) queue_mutex.synchronize do waiting_queue.push(:id => new_id, :packet => packet, :timestamp => Time.now) end - @sender.append_to_writing(packet) rescue FullQueueException PahoMqtt.logger.error("#{packet.type_name} queue is full") if PahoMqtt.logger? sleep SELECT_TIMEOUT @@ -99,6 +99,7 @@ def send_pubrec(packet_id) :id => packet_id ) push_queue(@waiting_pubrel, @pubrel_mutex, MAX_PUBREL, packet, packet_id) + @sender.append_to_writing(packet) MQTT_ERR_SUCCESS end @@ -107,7 +108,6 @@ def do_pubrec(packet_id) @waiting_pubrec.delete_if { |pck| pck[:id] == packet_id } end send_pubrel(packet_id) - MQTT_ERR_SUCCESS end def send_pubrel(packet_id) @@ -115,6 +115,8 @@ def send_pubrel(packet_id) :id => packet_id ) push_queue(@waiting_pubcomp, @pubcomp_mutex, MAX_PUBCOMP, packet, packet_id) + @sender.append_to_writing(packet) + MQTT_ERR_SUCCESS end def do_pubrel(packet_id) @@ -122,7 +124,6 @@ def do_pubrel(packet_id) @waiting_pubrel.delete_if { |pck| pck[:id] == packet_id } end send_pubcomp(packet_id) - MQTT_ERR_SUCCESS end def send_pubcomp(packet_id) diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 5758b47..2cfda3d 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -292,6 +292,7 @@ expect(filter).to be false expect(message).to be false client.subscribe(["/My_all_topic/topic1", 1]) + sleep 1 client.publish("/My_all_topic/topic1", "Hello World", false, 0) while !message && !filter do sleep 0.0001