paho-mqtt 1.0.9 → 1.0.10
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 +3 -4
- data/lib/paho_mqtt/client.rb +8 -11
- data/lib/paho_mqtt/connection_helper.rb +2 -9
- data/lib/paho_mqtt/exception.rb +6 -0
- data/lib/paho_mqtt/handler.rb +2 -2
- data/lib/paho_mqtt/publisher.rb +20 -31
- data/lib/paho_mqtt/sender.rb +21 -4
- data/lib/paho_mqtt/subscriber.rb +0 -1
- 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: aeeb9db2020a2162a6f5581da55c235db4fc26e9cf6786729b5c40352b3560fd
|
4
|
+
data.tar.gz: 68241bd854291fc771c7bdfc90d9c31dffe027c7987383cb5bb06b0e1c871a8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 802ee8ab38a2afeb1af1ee350278bf8a7b10fd1904ec062baf1e9a0d38dda796da4ced668b7e497888aabc62654368afaf3445096f8cde2a29c2ed59b44496a2
|
7
|
+
data.tar.gz: 17c1ca5fb822a9f1f0f42cdf8f0a02ab9fc4c455da9d7d062fcbbd0a439604cd2bbfadf8644377a28828a89285c33251140cff15ab491fa279a4eba7c4cf04bc
|
data/lib/paho-mqtt.rb
CHANGED
@@ -25,18 +25,17 @@ module PahoMqtt
|
|
25
25
|
# Default connection setup
|
26
26
|
DEFAULT_SSL_PORT = 8883
|
27
27
|
DEFAULT_PORT = 1883
|
28
|
-
SELECT_TIMEOUT = 0
|
29
|
-
LOOP_TEMPO = 0.005
|
28
|
+
SELECT_TIMEOUT = 0.002
|
30
29
|
|
31
30
|
# MAX size of queue
|
32
31
|
MAX_SUBACK = 10
|
33
32
|
MAX_UNSUBACK = 10
|
34
|
-
MAX_READ =
|
33
|
+
MAX_READ = 100
|
35
34
|
MAX_PUBACK = 100
|
36
35
|
MAX_PUBREC = 100
|
37
36
|
MAX_PUBREL = 100
|
38
37
|
MAX_PUBCOMP = 100
|
39
|
-
MAX_WRITING =
|
38
|
+
MAX_WRITING = 1000
|
40
39
|
|
41
40
|
# Connection states values
|
42
41
|
MQTT_CS_NEW = 0
|
data/lib/paho_mqtt/client.rb
CHANGED
@@ -163,15 +163,15 @@ module PahoMqtt
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def loop_read(max_packet=MAX_READ)
|
166
|
-
|
167
|
-
|
166
|
+
begin
|
167
|
+
max_packet.times do
|
168
168
|
@handler.receive_packet
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
169
|
+
end
|
170
|
+
rescue ReadingException
|
171
|
+
if check_persistence
|
172
|
+
reconnect
|
173
|
+
else
|
174
|
+
raise ReadingException
|
175
175
|
end
|
176
176
|
end
|
177
177
|
end
|
@@ -180,7 +180,6 @@ module PahoMqtt
|
|
180
180
|
loop_read
|
181
181
|
loop_write
|
182
182
|
loop_misc
|
183
|
-
sleep LOOP_TEMPO
|
184
183
|
end
|
185
184
|
|
186
185
|
def loop_misc
|
@@ -238,7 +237,6 @@ module PahoMqtt
|
|
238
237
|
MQTT_ERR_SUCCESS
|
239
238
|
rescue ProtocolViolation
|
240
239
|
PahoMqtt.logger.error("Subscribe topics need one topic or a list of topics.") if PahoMqtt.logger?
|
241
|
-
disconnect(false)
|
242
240
|
raise ProtocolViolation
|
243
241
|
end
|
244
242
|
end
|
@@ -252,7 +250,6 @@ module PahoMqtt
|
|
252
250
|
MQTT_ERR_SUCCESS
|
253
251
|
rescue ProtocolViolation
|
254
252
|
PahoMqtt.logger.error("Unsubscribe need at least one topic.") if PahoMqtt.logger?
|
255
|
-
disconnect(false)
|
256
253
|
raise ProtocolViolation
|
257
254
|
end
|
258
255
|
end
|
@@ -41,7 +41,6 @@ module PahoMqtt
|
|
41
41
|
connect_timeout = Time.now + @ack_timeout
|
42
42
|
while (Time.now <= connect_timeout) && !is_connected? do
|
43
43
|
@cs = @handler.receive_packet
|
44
|
-
sleep 0.0001
|
45
44
|
end
|
46
45
|
unless is_connected?
|
47
46
|
PahoMqtt.logger.warn("Connection failed. Couldn't recieve a Connack packet from: #{@host}.") if PahoMqtt.logger?
|
@@ -144,22 +143,16 @@ module PahoMqtt
|
|
144
143
|
MQTT_ERR_SUCCESS
|
145
144
|
end
|
146
145
|
|
147
|
-
def send_pingreq
|
148
|
-
packet = PahoMqtt::Packet::Pingreq.new
|
149
|
-
@sender.send_packet(packet)
|
150
|
-
MQTT_ERR_SUCCESS
|
151
|
-
end
|
152
|
-
|
153
146
|
def check_keep_alive(persistent, last_ping_resp, keep_alive)
|
154
147
|
now = Time.now
|
155
148
|
timeout_req = (@sender.last_ping_req + (keep_alive * 0.7).ceil)
|
156
149
|
if timeout_req <= now && persistent
|
157
150
|
PahoMqtt.logger.debug("Checking if server is still alive...") if PahoMqtt.logger?
|
158
|
-
send_pingreq
|
151
|
+
@sender.send_pingreq
|
159
152
|
end
|
160
153
|
timeout_resp = last_ping_resp + (keep_alive * 1.1).ceil
|
161
154
|
if timeout_resp <= now
|
162
|
-
PahoMqtt.logger.debug("No activity
|
155
|
+
PahoMqtt.logger.debug("No activity is over timeout, disconnecting from #{@host}.") if PahoMqtt.logger?
|
163
156
|
@cs = MQTT_CS_DISCONNECT
|
164
157
|
end
|
165
158
|
@cs
|
data/lib/paho_mqtt/exception.rb
CHANGED
data/lib/paho_mqtt/handler.rb
CHANGED
@@ -36,7 +36,7 @@ module PahoMqtt
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def receive_packet
|
39
|
-
result = IO.select([@socket],
|
39
|
+
result = IO.select([@socket], nil, nil, SELECT_TIMEOUT) unless @socket.nil? || @socket.closed?
|
40
40
|
unless result.nil?
|
41
41
|
packet = PahoMqtt::Packet::Base.read(@socket)
|
42
42
|
unless packet.nil?
|
@@ -86,7 +86,7 @@ module PahoMqtt
|
|
86
86
|
handle_connack_accepted(packet.session_present)
|
87
87
|
else
|
88
88
|
PahoMqtt.logger.warm(packet.return_msg) if PahoMqtt.logger?
|
89
|
-
|
89
|
+
MQTT_CS_DISCONNECT
|
90
90
|
end
|
91
91
|
@on_connack.call(packet) unless @on_connack.nil?
|
92
92
|
MQTT_CS_CONNECTED
|
data/lib/paho_mqtt/publisher.rb
CHANGED
@@ -41,26 +41,30 @@ module PahoMqtt
|
|
41
41
|
)
|
42
42
|
case qos
|
43
43
|
when 1
|
44
|
-
@puback_mutex
|
45
|
-
if @waiting_puback.length >= MAX_PUBACK
|
46
|
-
PahoMqtt.logger.error('PUBACK queue is full, could not send with qos=1') if PahoMqtt.logger?
|
47
|
-
return MQTT_ERR_FAIL
|
48
|
-
end
|
49
|
-
@waiting_puback.push(:id => new_id, :packet => packet, :timestamp => Time.now)
|
50
|
-
end
|
44
|
+
push_queue(@waiting_puback, @puback_mutex, MAX_PUBACK, packet, new_id)
|
51
45
|
when 2
|
52
|
-
@pubrec_mutex
|
53
|
-
if @waiting_pubrec.length >= MAX_PUBREC
|
54
|
-
PahoMqtt.logger.error('PUBREC queue is full, could not send with qos=2') if PahoMqtt.logger?
|
55
|
-
return MQTT_ERR_FAIL
|
56
|
-
end
|
57
|
-
@waiting_pubrec.push(:id => new_id, :packet => packet, :timestamp => Time.now)
|
58
|
-
end
|
46
|
+
push_queue(@waiting_pubrec, @pubrec_mutex, MAX_PUBREC, packet, new_id)
|
59
47
|
end
|
60
48
|
@sender.append_to_writing(packet)
|
61
49
|
MQTT_ERR_SUCCESS
|
62
50
|
end
|
63
51
|
|
52
|
+
def push_queue(waiting_queue, queue_mutex, max_packet, packet, new_id)
|
53
|
+
begin
|
54
|
+
if waiting_queue.length >= max_packet
|
55
|
+
raise FullQueueException
|
56
|
+
end
|
57
|
+
queue_mutex.synchronize do
|
58
|
+
waiting_queue.push(:id => new_id, :packet => packet, :timestamp => Time.now)
|
59
|
+
end
|
60
|
+
rescue FullQueueException
|
61
|
+
PahoMqtt.logger.error("#{packet.type_name} queue is full") if PahoMqtt.logger?
|
62
|
+
sleep SELECT_TIMEOUT
|
63
|
+
retry
|
64
|
+
end
|
65
|
+
MQTT_ERR_SUCCESS
|
66
|
+
end
|
67
|
+
|
64
68
|
def do_publish(qos, packet_id)
|
65
69
|
case qos
|
66
70
|
when 0
|
@@ -94,14 +98,7 @@ module PahoMqtt
|
|
94
98
|
packet = PahoMqtt::Packet::Pubrec.new(
|
95
99
|
:id => packet_id
|
96
100
|
)
|
97
|
-
@pubrel_mutex
|
98
|
-
if @waiting_pubrel.length >= MAX_PUBREL
|
99
|
-
PahoMqtt.logger.error('PUBREL queue is full, could not acknowledge qos=2') if PahoMqtt.logger?
|
100
|
-
return MQTT_ERR_FAIL
|
101
|
-
end
|
102
|
-
@waiting_pubrel.push(:id => packet_id , :packet => packet, :timestamp => Time.now)
|
103
|
-
end
|
104
|
-
@sender.append_to_writing(packet)
|
101
|
+
push_queue(@waiting_pubrel, @pubrel_mutex, MAX_PUBREL, packet, packet_id)
|
105
102
|
MQTT_ERR_SUCCESS
|
106
103
|
end
|
107
104
|
|
@@ -117,15 +114,7 @@ module PahoMqtt
|
|
117
114
|
packet = PahoMqtt::Packet::Pubrel.new(
|
118
115
|
:id => packet_id
|
119
116
|
)
|
120
|
-
@pubcomp_mutex
|
121
|
-
if @waiting_pubcomp.length >= MAX_PUBCOMP
|
122
|
-
PahoMqtt.logger.error('PUBCOMP queue is full, could not acknowledge qos=2') if PahoMqtt.logger?
|
123
|
-
return MQTT_ERR_FAIL
|
124
|
-
end
|
125
|
-
@waiting_pubcomp.push(:id => packet_id, :packet => packet, :timestamp => Time.now)
|
126
|
-
end
|
127
|
-
@sender.append_to_writing(packet)
|
128
|
-
MQTT_ERR_SUCCESS
|
117
|
+
push_queue(@waiting_pubcomp, @pubcomp_mutex, MAX_PUBCOMP, packet, packet_id)
|
129
118
|
end
|
130
119
|
|
131
120
|
def do_pubrel(packet_id)
|
data/lib/paho_mqtt/sender.rb
CHANGED
@@ -34,14 +34,31 @@ module PahoMqtt
|
|
34
34
|
@socket.write(packet.to_s) unless @socket.nil? || @socket.closed?
|
35
35
|
@last_ping_req = Time.now
|
36
36
|
MQTT_ERR_SUCCESS
|
37
|
-
rescue StandardError
|
38
|
-
raise WritingException
|
39
37
|
end
|
38
|
+
rescue StandardError
|
39
|
+
raise WritingException
|
40
|
+
rescue IO::WaitWritable
|
41
|
+
IO.select(nil, [@socket], nil, SELECT_TIMEOUT)
|
42
|
+
retry
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_pingreq
|
46
|
+
send_packet(PahoMqtt::Packet::Pingreq.new)
|
40
47
|
end
|
41
48
|
|
42
49
|
def append_to_writing(packet)
|
43
|
-
|
44
|
-
|
50
|
+
begin
|
51
|
+
if @writing_queue.length <= MAX_WRITING
|
52
|
+
@writing_mutex.synchronize do
|
53
|
+
@writing_queue.push(packet)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
PahoMqtt.logger.error('Writing queue is full slowing down') if PahoMqtt.logger?
|
57
|
+
raise FullWritingException
|
58
|
+
end
|
59
|
+
rescue FullWritingException
|
60
|
+
sleep SELECT_TIMEOUT
|
61
|
+
retry
|
45
62
|
end
|
46
63
|
MQTT_ERR_SUCCESS
|
47
64
|
end
|
data/lib/paho_mqtt/subscriber.rb
CHANGED
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.10
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|