Skip to content

Commit

Permalink
Fix qos=0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-goudet committed May 22, 2018
1 parent 5df7385 commit 47553f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/paho_mqtt/publisher.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -107,22 +108,22 @@ 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)
packet = PahoMqtt::Packet::Pubrel.new(
: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)
@pubrel_mutex.synchronize do
@waiting_pubrel.delete_if { |pck| pck[:id] == packet_id }
end
send_pubcomp(packet_id)
MQTT_ERR_SUCCESS
end

def send_pubcomp(packet_id)
Expand Down
1 change: 1 addition & 0 deletions spec/client_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 47553f0

Please sign in to comment.