lib/mqtt/client.rb in mqtt-0.0.8 vs lib/mqtt/client.rb in mqtt-0.0.9
- old
+ new
@@ -115,11 +115,11 @@
# Connect to the MQTT broker
# If a block is given, then yield to that block and then disconnect again.
def connect(clientid=nil)
if !clientid.nil?
@client_id = clientid
- elsif @clientid.nil?
+ elsif @client_id.nil?
@client_id = MQTT::Client.generate_client_id
@clean_session = true
end
if not connected?
@@ -165,15 +165,15 @@
if connected?
if send_msg
packet = MQTT::Packet::Disconnect.new
send_packet(packet)
end
- @read_thread.kill if @read_thread and @read_thread.alive?
- @read_thread = nil
@socket.close unless @socket.nil?
@socket = nil
end
+ @read_thread.kill if @read_thread and @read_thread.alive?
+ @read_thread = nil
end
# Checks whether the client is connected to the broker.
def connected?
not @socket.nil?
@@ -244,9 +244,19 @@
else
# Wait for one packet to be available
packet = @read_queue.pop
return packet.topic, packet.payload
end
+ end
+
+ # Returns true if the incoming message queue is empty.
+ def queue_empty?
+ @read_queue.empty?
+ end
+
+ # Returns the length of the incoming message queue.
+ def queue_length
+ @read_queue.length
end
# Send a unsubscribe message for one or more topics on the MQTT broker
def unsubscribe(*topics)
packet = MQTT::Packet::Unsubscribe.new(