lib/mqtt/client.rb in mqtt-0.3.0 vs lib/mqtt/client.rb in mqtt-0.3.1

- old
+ new

@@ -51,11 +51,14 @@ attr_accessor :will_qos # If the Will message should be retain by the server after it is sent attr_accessor :will_retain + #Last ping response time + attr_reader :last_ping_response + # Timeout between select polls (in seconds) SELECT_TIMEOUT = 0.5 # Default attribute values ATTR_DEFAULTS = { @@ -171,11 +174,11 @@ end # Initialise private instance variables @packet_id = 0 @last_pingreq = Time.now - @last_pingresp = Time.now + @last_ping_response = Time.now @socket = nil @read_queue = Queue.new @read_thread = nil @write_semaphore = Mutex.new end @@ -450,9 +453,11 @@ # Yes - read in the packet packet = MQTT::Packet.read(@socket) if packet.class == MQTT::Packet::Publish # Add to queue @read_queue.push(packet) + elsif packet.class == MQTT::Packet::Pingresp + @last_ping_response = Time.now else # Ignore all other packets nil # FIXME: implement responses for QOS 1 and 2 end