lib/pigato/client.rb in pigato-0.2.12 vs lib/pigato/client.rb in pigato-0.2.13

- old
+ new

@@ -20,15 +20,17 @@ if @conf[:autostart] start end end + def getid + tid = "#" + Process.pid.to_s + "|" + Thread.current.object_id.to_s + tid + end def request service, request, opts = {} - start if @sockets[Thread.current.object_id] == nil - socket = @sockets[Thread.current.object_id] - + socket = @sockets[getid()] return nil if socket == nil; request = [Oj.dump(request), Oj.dump(opts)] rid = SecureRandom.uuid @@ -49,11 +51,11 @@ return res[0] if res.length == 1 res end def _recv rid - socket = @sockets[Thread.current.object_id] + socket = @sockets[getid()] socket.rcvtimeo = @conf[:timeout] data = [] d1 = Time.now msg = socket.recv_message() while 1 do @@ -71,20 +73,21 @@ def start reconnect_to_broker end def stop - socket = @sockets[Thread.current.object_id] + tid = getid() + socket = @sockets[tid] if socket socket.close - @sockets.delete(Thread.current.object_id) + @sockets.delete(tid) end end def reconnect_to_broker stop socket = @ctx.socket ZMQ::DEALER socket.identity = SecureRandom.uuid socket.connect @broker - @sockets[Thread.current.object_id] = socket + @sockets[getid()] = socket end end