Sha256: a31018d42b59c930183b60c2ddadba4fd2e7aa2de532ca41f8667c696cc4c436

Contents?: true

Size: 877 Bytes

Versions: 2

Compression:

Stored size: 877 Bytes

Contents

module BERTRPC
  class Call
    include Encodes
    
    def initialize(svc, mod, fun, args)
      @svc = svc
      @mod = mod
      @fun = fun
      @args = args
    end

    def execute
      bert_request = encode_ruby_request([:call, @mod, @fun, @args])
      bert_response = sync_request(bert_request)
      decode_bert_response(bert_response)
    end

    #private

    def sync_request(bert_request)
      sock = TCPSocket.new(@svc.host, @svc.port)
      sock.write([bert_request.length].pack("N"))
      sock.write(bert_request)
      lenheader = sock.read(4)
      raise ProtocolError.new("Unable to read length header from server.") unless lenheader
      len = lenheader.unpack('N').first
      bert_response = sock.read(len)
      raise ProtocolError.new("Unable to read data from server.") unless bert_response
      sock.close
      bert_response
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mojombo-bertrpc-0.2.0 lib/bertrpc/call.rb
bertrpc-0.2.0 lib/bertrpc/call.rb