lib/pigato/client.rb in pigato-0.2.15 vs lib/pigato/client.rb in pigato-0.2.17
- old
+ new
@@ -1,12 +1,13 @@
require 'thread'
+$pigato_zmq_ctx = nil
+
class Pigato::Client
def initialize broker, conf = {}
@broker = broker
- @ctxs = {}
@sockets = {}
@conf = {
:autostart => false,
:timeout => 2500
@@ -79,20 +80,22 @@
def stop
tid = get_thread_id()
if @sockets[tid]
@sockets[tid].close
+ @sockets.delete(tid)
end
end
def reconnect_to_broker
stop
- ctx = @ctxs[get_proc_id()]
- ctx = ZMQ::Context.new if ctx == nil
- ctx.linger = 0
- socket = ctx.socket ZMQ::DEALER
+ if $pigato_zmq_ctx == nil
+ ctx = ZMQ::Context.new
+ ctx.linger = 0
+ $pigato_zmq_ctx = ctx
+ end
+ socket = $pigato_zmq_ctx.socket ZMQ::DEALER
socket.identity = SecureRandom.uuid
socket.connect @broker
@sockets[get_thread_id()] = socket
- @ctxs[get_proc_id()] = ctx
end
end