lib/pigato/client.rb in pigato-0.4.2 vs lib/pigato/client.rb in pigato-0.4.3

- old
+ new

@@ -1,9 +1,8 @@ require "#{File.dirname(__FILE__)}/base.rb" class Pigato::Client < Pigato::Base - @@mtx = Mutex.new @@ctxs = {} @@sockets = {} def initialize broker, conf = {} @@ -21,23 +20,28 @@ if @conf[:autostart] start end end - def request service, request, opts = {} + def send msg iid = get_iid start if @@sockets[iid] == nil && @conf[:autostart] - socket = get_socket return nil if socket.nil? + socket.send_message msg + true + end + def request service, request, opts = {} request = [Oj.dump(request), Oj.dump(opts)] rid = SecureRandom.uuid request = [Pigato::C_CLIENT, Pigato::W_REQUEST, service, rid].concat(request) msg = ZMQ::Message.new request.reverse.each{|p| msg.push(ZMQ::Frame(p))} - socket.send_message msg + + res = send msg + return nil if res.nil? res = [] while 1 do chunk = _recv rid break if chunk == nil