Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Merge branch 'one_connection' into replicate_robey
Browse files Browse the repository at this point in the history
  • Loading branch information
Robey Pointer committed Dec 7, 2010
2 parents 6de9267 + d676ee9 commit 5d0cc45
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/vendor/thrift_client/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,16 @@ def self.thrift_method(name, rtype, *args)
class_eval "def #{name}(#{arg_names}); _proxy(:#{name}#{args.size > 0 ? ', ' : ''}#{arg_names}); end"
end

def connection
@connection ||= TCPSocket.new(@host, @port)
end

def _proxy(method_name, *args)
cls = self.class.ancestors.find { |cls| cls.respond_to?(:_arg_structs) and cls._arg_structs[method_name.to_sym] }
arg_class, rv_class = cls._arg_structs[method_name.to_sym]
arg_struct = arg_class.new(*args)
sock = TCPSocket.new(@host, @port)
sock.write(ThriftClient::Simple.pack_request(method_name, arg_struct, @framed))
rv = ThriftClient::Simple.read_response(sock, rv_class, @framed)
sock.close
connection.write(ThriftClient::Simple.pack_request(method_name, arg_struct, @framed))
rv = ThriftClient::Simple.read_response(connection, rv_class, @framed)
rv[2]
end

Expand Down

0 comments on commit 5d0cc45

Please sign in to comment.