# File lib/thrift_client/event_machine.rb, line 10 def initialize(host, port=9090, timeout=5) @host, @port, @timeout = host, port, timeout @connection = nil end
# File lib/thrift_client/event_machine.rb, line 34 def close @connection.close end
# File lib/thrift_client/event_machine.rb, line 19 def open fiber = Fiber.current @connection = EventMachineConnection.connect(@host, @port, @timeout) @connection.callback do fiber.resume end @connection.errback do fiber.resume end Fiber.yield raise Thrift::TransportException, "Unable to connect to #{@host}:#{@port}" unless @connection.connected? @connection end
# File lib/thrift_client/event_machine.rb, line 15 def open? @connection && @connection.connected? end
# File lib/thrift_client/event_machine.rb, line 38 def read(sz) @connection.blocking_read(sz) end
# File lib/thrift_client/event_machine.rb, line 42 def write(buf) @connection.send_data(buf) end