paho-mqtt 1.0.4 → 1.0.5

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
  SHA1:
3
- metadata.gz: 59165a42d0455ead88b2d98f90ffded161270bd5
4
- data.tar.gz: 4b1518662800f85b79bc02ed79d694ec4c8d1d60
3
+ metadata.gz: 80ab469d38120ae2f9cdcb6901ecc3f82e31cdca
4
+ data.tar.gz: 2ac290819f952a35d16708d78105acac6edd10dd
5
5
  SHA512:
6
- metadata.gz: da53418b2eca67e6815ca89f1923c14eb205eaad902026becb715a3910b56718a1d75c0d89db4f4f92ec126d726844a02eb45f70385ada6b9c3981c9bb97c95b
7
- data.tar.gz: e96111e7f79286a660a90932f56bdf273d548816e93eb4df423103530990552b0eb3c1e6f6a6fd10f5cb247c4135d0238a2bc2f459ae8800cb9a959491e2a1f9
6
+ metadata.gz: 022c3db947547fd72a9b7cdba15a1c60d5a0412ffed0e31bfca54e934178ba1a0d30935b9bba49402959bf9a91ff9c3e2dc3ceff51fb3806ed657e1c3e90240b
7
+ data.tar.gz: 22712df65d41429e9c16d3f34ebf4130af07c2b026f7ab4a6eadc8712181844d358c6030c529ec18ac363e41ee9fa4268019bab60a7615ff1737085c8df76293
data/lib/paho-mqtt.rb CHANGED
@@ -104,6 +104,7 @@ module PahoMqtt
104
104
 
105
105
  def logger=(logger_path)
106
106
  file = File.open(logger_path, "a+")
107
+ file.sync = true
107
108
  log_file = Logger.new(file)
108
109
  log_file.level = Logger::DEBUG
109
110
  @logger = log_file
@@ -111,18 +111,28 @@ module PahoMqtt
111
111
  @connection_helper.send_connect(session_params)
112
112
  begin
113
113
  @connection_state = @connection_helper.do_connect(reconnect?)
114
+ if connected?
115
+ build_pubsub
116
+ daemon_mode unless @blocking
117
+ end
114
118
  rescue LowVersionException
115
119
  downgrade_version
116
120
  end
117
- build_pubsub
118
- daemon_mode unless @blocking || !connected?
119
121
  end
120
122
 
121
123
  def daemon_mode
122
124
  @mqtt_thread = Thread.new do
123
125
  @reconnect_thread.kill unless @reconnect_thread.nil? || !@reconnect_thread.alive?
124
- while connected? do
125
- mqtt_loop
126
+ begin
127
+ while connected? do
128
+ mqtt_loop
129
+ end
130
+ rescue SystemCallError => e
131
+ if @persistent
132
+ reconnect()
133
+ else
134
+ raise e
135
+ end
126
136
  end
127
137
  end
128
138
  end
@@ -176,21 +186,20 @@ module PahoMqtt
176
186
  @subscriber.check_waiting_subscriber
177
187
  end
178
188
 
179
- def reconnect(retry_time=RECONNECT_RETRY_TIME, retry_tempo=RECONNECT_RETRY_TEMPO)
189
+ def reconnect
180
190
  @reconnect_thread = Thread.new do
181
- retry_time.times do
191
+ RECONNECT_RETRY_TIME.times do
182
192
  PahoMqtt.logger.debug("New reconnect atempt...") if PahoMqtt.logger?
183
193
  connect
184
194
  if connected?
185
195
  break
186
196
  else
187
- sleep retry_tempo
197
+ sleep RECONNECT_RETRY_TIME
188
198
  end
189
199
  end
190
200
  unless connected?
191
201
  PahoMqtt.logger.error("Reconnection atempt counter is over.(#{RECONNECT_RETRY_TIME} times)") if PahoMqtt.logger?
192
202
  disconnect(false)
193
- exit
194
203
  end
195
204
  end
196
205
  end
@@ -35,6 +35,7 @@ module PahoMqtt
35
35
  end
36
36
 
37
37
  def do_connect(reconnection=false)
38
+ @cs = MQTT_CS_NEW
38
39
  @handler.socket = @socket
39
40
  # Waiting a Connack packet for "ack_timeout" second from the remote
40
41
  connect_timeout = Time.now + @ack_timeout
@@ -1,3 +1,3 @@
1
1
  module PahoMqtt
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -1,11 +1,7 @@
1
1
  require 'paho-mqtt'
2
- require 'logger'
3
2
 
4
- file = File.open('paho.log', "a+")
5
- log = Logger.new(file)
6
- log.level = Logger::DEBUG
7
-
8
- client = PahoMqtt::Client.new({logger: log})
3
+ client = PahoMqtt::Client.new()
4
+ PahoMqtt.logger = 'paho.log'
9
5
 
10
6
  client.on_message do |pck|
11
7
  puts "New Message: #{pck.topic}\n>>> #{pck.payload}"
@@ -2,7 +2,7 @@ require 'paho-mqtt'
2
2
 
3
3
  ### Create a simple client with default attributes
4
4
  client = PahoMqtt::Client.new
5
-
5
+ PahoMqtt.logger = 'paho_mqtt'
6
6
  ### Register a callback on message event to display messages
7
7
  message_counter = 0
8
8
  client.on_message do |message|
@@ -2,7 +2,7 @@ require "paho-mqtt"
2
2
  require "logger"
3
3
 
4
4
  cli = PahoMqtt::Client.new({persistent: true, keep_alive: 7})
5
- PahoMqtt.logger = ('paho_log')
5
+ PahoMqtt.logger = 'paho_log'
6
6
 
7
7
  cli.connect('localhost', 1883)
8
8
 
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
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Goudet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,8 +94,8 @@ files:
94
94
  - lib/paho_mqtt/subscriber.rb
95
95
  - lib/paho_mqtt/version.rb
96
96
  - paho-mqtt.gemspec
97
+ - samples/client_blocking(reading).rb
97
98
  - samples/client_blocking(writing).rb
98
- - samples/client_blocking.rb
99
99
  - samples/getting_started.rb
100
100
  - samples/test_client.rb
101
101
  homepage: https://github.com/RubyDevInc/paho.mqtt.ruby