paho-mqtt 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paho-mqtt.rb +4 -2
- data/lib/paho_mqtt/client.rb +9 -6
- data/lib/paho_mqtt/handler.rb +10 -9
- data/lib/paho_mqtt/publisher.rb +3 -2
- data/lib/paho_mqtt/sender.rb +32 -15
- data/lib/paho_mqtt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36bc2ea31aa16b29dd3630d0d5db7b1e21b9723ce208d5234c0cde283cdf26e4
|
4
|
+
data.tar.gz: 2baf2f376e7be26234ea7a6e94c662648a75442022c080dc76df7fd6bfa9c5e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5293b974ec90097bf707b6d14870d6347c704a4a7da0622c63fe0cfba6591536b19673804d68726b2b0b2e77496a654caaddd8aa47cb5f6cfe58e2ce501979f7
|
7
|
+
data.tar.gz: f6f1f6c5c6f2659399cd70566b6af1d80606cdff9ee1c8fde8645799943a0b8a0d7c9608f8842d56cef8a9d885d42c0deb8fc5fcee875498b3da962fe4284c67
|
data/lib/paho-mqtt.rb
CHANGED
@@ -22,6 +22,8 @@ module PahoMqtt
|
|
22
22
|
extend self
|
23
23
|
attr_accessor :logger
|
24
24
|
|
25
|
+
MAX_PACKET_ID = 65535
|
26
|
+
|
25
27
|
# Default connection setup
|
26
28
|
DEFAULT_SSL_PORT = 8883
|
27
29
|
DEFAULT_PORT = 1883
|
@@ -30,12 +32,12 @@ module PahoMqtt
|
|
30
32
|
# MAX size of queue
|
31
33
|
MAX_SUBACK = 10
|
32
34
|
MAX_UNSUBACK = 10
|
33
|
-
MAX_READ = 100
|
34
35
|
MAX_PUBACK = 100
|
35
36
|
MAX_PUBREC = 100
|
36
37
|
MAX_PUBREL = 100
|
38
|
+
MAX_PUBLISH = 1000
|
37
39
|
MAX_PUBCOMP = 100
|
38
|
-
|
40
|
+
MAX_QUEUE = MAX_PUBACK + MAX_PUBREC + MAX_PUBREL + MAX_PUBCOMP
|
39
41
|
|
40
42
|
# Connection states values
|
41
43
|
MQTT_CS_NEW = 0
|
data/lib/paho_mqtt/client.rb
CHANGED
@@ -150,9 +150,9 @@ module PahoMqtt
|
|
150
150
|
Thread.current == @reconnect_thread
|
151
151
|
end
|
152
152
|
|
153
|
-
def loop_write
|
153
|
+
def loop_write
|
154
154
|
begin
|
155
|
-
@sender.writing_loop
|
155
|
+
@sender.writing_loop
|
156
156
|
rescue WritingException
|
157
157
|
if check_persistence
|
158
158
|
reconnect
|
@@ -162,10 +162,11 @@ module PahoMqtt
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
-
def loop_read
|
165
|
+
def loop_read
|
166
166
|
begin
|
167
|
-
|
168
|
-
@handler.receive_packet
|
167
|
+
MAX_QUEUE.times do
|
168
|
+
result = @handler.receive_packet
|
169
|
+
break if result.nil?
|
169
170
|
end
|
170
171
|
rescue ReadingException
|
171
172
|
if check_persistence
|
@@ -188,6 +189,7 @@ module PahoMqtt
|
|
188
189
|
end
|
189
190
|
@publisher.check_waiting_publisher
|
190
191
|
@subscriber.check_waiting_subscriber
|
192
|
+
sleep SELECT_TIMEOUT
|
191
193
|
end
|
192
194
|
|
193
195
|
def reconnect
|
@@ -351,7 +353,8 @@ module PahoMqtt
|
|
351
353
|
|
352
354
|
def next_packet_id
|
353
355
|
@id_mutex.synchronize do
|
354
|
-
@last_packet_id =
|
356
|
+
@last_packet_id = 0 if @last_packet_id >= MAX_PACKET_ID
|
357
|
+
@last_packet_id = @last_packet_id.next
|
355
358
|
end
|
356
359
|
end
|
357
360
|
|
data/lib/paho_mqtt/handler.rb
CHANGED
@@ -42,13 +42,14 @@ module PahoMqtt
|
|
42
42
|
unless packet.nil?
|
43
43
|
if packet.is_a?(PahoMqtt::Packet::Connack)
|
44
44
|
@last_ping_resp = Time.now
|
45
|
-
handle_connack(packet)
|
45
|
+
return handle_connack(packet)
|
46
46
|
else
|
47
47
|
handle_packet(packet)
|
48
48
|
@last_ping_resp = Time.now
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
+
return result
|
52
53
|
end
|
53
54
|
|
54
55
|
def handle_packet(packet)
|
@@ -85,7 +86,7 @@ module PahoMqtt
|
|
85
86
|
PahoMqtt.logger.debug(packet.return_msg) if PahoMqtt.logger?
|
86
87
|
handle_connack_accepted(packet.session_present)
|
87
88
|
else
|
88
|
-
PahoMqtt.logger.
|
89
|
+
PahoMqtt.logger.warn(packet.return_msg) if PahoMqtt.logger?
|
89
90
|
MQTT_CS_DISCONNECT
|
90
91
|
end
|
91
92
|
@on_connack.call(packet) unless @on_connack.nil?
|
@@ -140,12 +141,12 @@ module PahoMqtt
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def handle_publish(packet)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
id = packet.id
|
145
|
+
qos = packet.qos
|
146
|
+
if @publisher.do_publish(qos, id) == MQTT_ERR_SUCCESS
|
147
|
+
@on_message.call(packet) unless @on_message.nil?
|
148
|
+
check_callback(packet)
|
149
|
+
end
|
149
150
|
end
|
150
151
|
|
151
152
|
def handle_puback(packet)
|
@@ -254,7 +255,7 @@ module PahoMqtt
|
|
254
255
|
type.to_s.split('::').last.downcase
|
255
256
|
else
|
256
257
|
PahoMqtt.logger.error("Received an unexpeceted packet: #{packet}.") if PahoMqtt.logger?
|
257
|
-
|
258
|
+
raise PacketException.new('Invalid packet type id')
|
258
259
|
end
|
259
260
|
end
|
260
261
|
|
data/lib/paho_mqtt/publisher.rb
CHANGED
@@ -99,6 +99,7 @@ module PahoMqtt
|
|
99
99
|
:id => packet_id
|
100
100
|
)
|
101
101
|
push_queue(@waiting_pubrel, @pubrel_mutex, MAX_PUBREL, packet, packet_id)
|
102
|
+
@sender.append_to_writing(packet)
|
102
103
|
MQTT_ERR_SUCCESS
|
103
104
|
end
|
104
105
|
|
@@ -107,7 +108,6 @@ module PahoMqtt
|
|
107
108
|
@waiting_pubrec.delete_if { |pck| pck[:id] == packet_id }
|
108
109
|
end
|
109
110
|
send_pubrel(packet_id)
|
110
|
-
MQTT_ERR_SUCCESS
|
111
111
|
end
|
112
112
|
|
113
113
|
def send_pubrel(packet_id)
|
@@ -115,6 +115,8 @@ module PahoMqtt
|
|
115
115
|
:id => packet_id
|
116
116
|
)
|
117
117
|
push_queue(@waiting_pubcomp, @pubcomp_mutex, MAX_PUBCOMP, packet, packet_id)
|
118
|
+
@sender.append_to_writing(packet)
|
119
|
+
MQTT_ERR_SUCCESS
|
118
120
|
end
|
119
121
|
|
120
122
|
def do_pubrel(packet_id)
|
@@ -122,7 +124,6 @@ module PahoMqtt
|
|
122
124
|
@waiting_pubrel.delete_if { |pck| pck[:id] == packet_id }
|
123
125
|
end
|
124
126
|
send_pubcomp(packet_id)
|
125
|
-
MQTT_ERR_SUCCESS
|
126
127
|
end
|
127
128
|
|
128
129
|
def send_pubcomp(packet_id)
|
data/lib/paho_mqtt/sender.rb
CHANGED
@@ -18,11 +18,13 @@ module PahoMqtt
|
|
18
18
|
attr_accessor :last_ping_req
|
19
19
|
|
20
20
|
def initialize(ack_timeout)
|
21
|
-
@socket
|
22
|
-
@writing_queue
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
21
|
+
@socket = nil
|
22
|
+
@writing_queue = []
|
23
|
+
@publish_queue = []
|
24
|
+
@publish_mutex = Mutex.new
|
25
|
+
@writing_mutex = Mutex.new
|
26
|
+
@last_ping_req = -1
|
27
|
+
@ack_timeout = ack_timeout
|
26
28
|
end
|
27
29
|
|
28
30
|
def socket=(socket)
|
@@ -46,15 +48,24 @@ module PahoMqtt
|
|
46
48
|
send_packet(PahoMqtt::Packet::Pingreq.new)
|
47
49
|
end
|
48
50
|
|
51
|
+
def prepare_sending(queue, mutex, max_packet, packet)
|
52
|
+
if queue.length < max_packet
|
53
|
+
mutex.synchronize do
|
54
|
+
queue.push(packet)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
PahoMqtt.logger.error('Writing queue is full, slowing down') if PahoMqtt.logger?
|
58
|
+
raise FullWritingException
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
49
62
|
def append_to_writing(packet)
|
50
63
|
begin
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
64
|
+
case packet
|
65
|
+
when packet.is_a?(PahoMqtt::Packet::Publish)
|
66
|
+
prepare_sending(@publish_queue, @publish_mutex, MAX_PUBLISH, packet)
|
55
67
|
else
|
56
|
-
|
57
|
-
raise FullWritingException
|
68
|
+
prepare_sending(@writing_queue, @writing_mutex, MAX_QUEUE, packet)
|
58
69
|
end
|
59
70
|
rescue FullWritingException
|
60
71
|
sleep SELECT_TIMEOUT
|
@@ -63,13 +74,19 @@ module PahoMqtt
|
|
63
74
|
MQTT_ERR_SUCCESS
|
64
75
|
end
|
65
76
|
|
66
|
-
def writing_loop
|
77
|
+
def writing_loop
|
67
78
|
@writing_mutex.synchronize do
|
68
|
-
|
69
|
-
|
79
|
+
MAX_QUEUE.times do
|
80
|
+
break if @writing_queue.empty?
|
70
81
|
packet = @writing_queue.shift
|
71
82
|
send_packet(packet)
|
72
|
-
|
83
|
+
end
|
84
|
+
end
|
85
|
+
@publish_mutex.synchronize do
|
86
|
+
MAX_PUBLISH.times do
|
87
|
+
break if @publish_queue.empty?
|
88
|
+
packet = @publish_queue.shift
|
89
|
+
send_packet(packet)
|
73
90
|
end
|
74
91
|
end
|
75
92
|
MQTT_ERR_SUCCESS
|
data/lib/paho_mqtt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paho-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Goudet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|