mqtt-ccutrer 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6edb25957b0e8c0253a47920bea2c49b7062f890364bdb7b85831715d2780fb2
4
- data.tar.gz: 8de9202fe28cbcff6b2f95c7fad8e9d87e693713115fff6237d69213021f3a84
3
+ metadata.gz: 5b93bce8e1cc0e50a0161ac2447fbff2c293ad89f64dc98cb848e20026e754e3
4
+ data.tar.gz: 4b480e5ffb4df550469d112274f6c831b96f4a2118bb29e32940156b9dccce58
5
5
  SHA512:
6
- metadata.gz: b9d3a01a30f91600f5e5005d1b13c240b4e0b6cb250d3c14f258fd86911cd80b443b9e3b34a1ef6b3c0170746d0b08128559f518aeb8f868218ac08c115fd58c
7
- data.tar.gz: 4b4065cedf0deda00ef06d207a7c25f8fb3c968c9ce81558229b469c19349c93fb650d9ca09a7261dbadc99dc802cdab194de49f608589dd9feb37d17fa46c91
6
+ metadata.gz: 3227b778e824d891845cab272ffe73f875ffe2de3440a56e1a3f73bffb5d6fa9edb41844665aead5411276c0241ef4f176fc369b98d1398c54bbdf78dc9103d9
7
+ data.tar.gz: 51254e256507a8c01dd9197266eed692ccad64c3a7b0baa8bbc3ec50350ea712bc2a8bbfd1b575fca4527d5fe4da0a706f33aa998a932aca8a517f5af40b6721
data/lib/mqtt/client.rb CHANGED
@@ -173,6 +173,9 @@ module MQTT
173
173
  @wake_up_pipe = IO.pipe
174
174
 
175
175
  @connected = false
176
+ @keep_alive_sent = false
177
+ @last_packet_id = 0
178
+ @batch_publish = false
176
179
  end
177
180
 
178
181
  # Get the OpenSSL context, that is used if SSL/TLS is enabled
@@ -514,6 +517,7 @@ module MQTT
514
517
 
515
518
  # Send packet
516
519
  @socket.write(packet.to_s)
520
+ @last_packet_sent_at = current_time
517
521
 
518
522
  # Receive response
519
523
  receive_connack
@@ -528,6 +532,7 @@ module MQTT
528
532
  next
529
533
  end
530
534
  @socket.write(packet.to_s)
535
+ @last_packet_sent_at = current_time
531
536
  end
532
537
  rescue => e
533
538
  @write_queue << packet if packet
@@ -643,7 +648,7 @@ module MQTT
643
648
  # Add to queue
644
649
  @read_queue.push(packet)
645
650
  when MQTT::Packet::Pingresp
646
- # do nothing; setting @last_packet_received_at already handled it
651
+ # do nothing; setting @keep_alive_sent already handled it
647
652
  when MQTT::Packet::Puback,
648
653
  MQTT::Packet::Suback,
649
654
  MQTT::Packet::Unsuback
@@ -694,8 +699,13 @@ module MQTT
694
699
  end
695
700
  return nil if timeout_from_acks.nil? && @keep_alive.nil?
696
701
 
697
- next_ping = @last_packet_received_at + @keep_alive if @keep_alive && !@keep_alive_sent
698
- next_ping = @last_packet_received_at + @keep_alive + @ack_timeout if @keep_alive && @keep_alive_sent
702
+ if @keep_alive
703
+ next_ping = if @keep_alive_sent
704
+ @last_packet_received_at + @keep_alive + @ack_timeout
705
+ else
706
+ @last_packet_sent_at + @keep_alive
707
+ end
708
+ end
699
709
  current_time_local = current_time
700
710
  [([timeout_from_acks, next_ping].compact.min || current_time_local) - current_time_local, 0].max
701
711
  end
@@ -704,7 +714,7 @@ module MQTT
704
714
  return unless @keep_alive && @keep_alive > 0
705
715
 
706
716
  current_time_local = current_time
707
- if current_time_local >= @last_packet_received_at + @keep_alive && !@keep_alive_sent
717
+ if current_time_local >= @last_packet_sent_at + @keep_alive && !@keep_alive_sent
708
718
  packet = MQTT::Packet::Pingreq.new
709
719
  send_packet(packet)
710
720
  @keep_alive_sent = true
@@ -764,7 +774,7 @@ module MQTT
764
774
  end
765
775
 
766
776
  def next_packet_id
767
- @last_packet_id = (@last_packet_id || 0).next
777
+ @last_packet_id = @last_packet_id.next
768
778
  @last_packet_id = 1 if @last_packet_id > 0xffff
769
779
  @last_packet_id
770
780
  end
data/lib/mqtt/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module MQTT
4
4
  # The version number of the MQTT gem
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mqtt-ccutrer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-04 00:00:00.000000000 Z
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler