lib/pigato/client.rb in pigato-0.2.18 vs lib/pigato/client.rb in pigato-0.2.19
- 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
@@ -81,26 +82,19 @@
tid = get_thread_id()
if @sockets[tid]
@sockets[tid].close
@sockets.delete(tid)
end
-
- pid = get_proc_id()
- if @ctxs[pid]
- @ctxs[pid].destroy
- @ctxs.delete(tid)
- end
end
def reconnect_to_broker
stop
- ctx = @ctxs[get_proc_id()]
- if ctx == nil
+ if $PIGATO_zmq_ctx == nil
ctx = ZMQ::Context.new
ctx.linger = 0
- @ctxs[get_proc_id()] = ctx
+ $PIGATO_zmq_ctx = ctx
end
- socket = ctx.socket ZMQ::DEALER
+ socket = $PIGATO_zmq_ctx.socket ZMQ::DEALER
socket.identity = SecureRandom.uuid
socket.connect @broker
@sockets[get_thread_id()] = socket
end
end