Permalink
Browse files

try to reuse an existing connection!

  • Loading branch information...
Robey Pointer
Robey Pointer committed Dec 7, 2010
1 parent 333b4e7 commit d676ee99d3b49f8209e444132d531645e130f267
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/vendor/thrift_client/simple.rb
@@ -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

1 comment on commit d676ee9

Contributor

freels commented on d676ee9 Dec 7, 2010

Yay! #facepalm

Please sign in to comment.