Kouhei Sutou
null+****@clear*****
Fri Jan 17 16:22:23 JST 2014
Kouhei Sutou 2014-01-17 16:22:23 +0900 (Fri, 17 Jan 2014) New Revision: 5998f973142125702ff53548afd42d50d5fea1d3 https://github.com/droonga/droonga-client-ruby/commit/5998f973142125702ff53548afd42d50d5fea1d3 Message: Use Socket.gethostname as the default receiver host Modified files: lib/droonga/client.rb lib/droonga/client/connection/droonga_protocol.rb Modified: lib/droonga/client.rb (+4 -0) =================================================================== --- lib/droonga/client.rb 2014-01-17 16:20:59 +0900 (f05a202) +++ lib/droonga/client.rb 2014-01-17 16:22:23 +0900 (06994e3) @@ -52,6 +52,10 @@ module Droonga # The host name or IP address of the Droonga Engine to be connected. # @option options [Integer] :port (24224) # The port number of the Droonga Engine to be connected. + # @option options [String] :receiver_host (Socket.gethostname) + # The host name or IP address to receive response from the Droonga Engine. + # @option options [Integer] :receiver_port (0) + # The port number to receive response from the Droonga Engine. # @option options [Integer] :timeout (5) # The timeout value for connecting to, writing to and reading # from Droonga Engine. Modified: lib/droonga/client/connection/droonga_protocol.rb (+13 -11) =================================================================== --- lib/droonga/client/connection/droonga_protocol.rb 2014-01-17 16:20:59 +0900 (eb8def6) +++ lib/droonga/client/connection/droonga_protocol.rb 2014-01-17 16:22:23 +0900 (c2e9de0) @@ -41,10 +41,10 @@ module Droonga :port => 24224, :timeout => 1, } - options = default_options.merge(options) - @logger = Fluent::Logger::FluentLogger.new(options.delete(:tag), - options) - @timeout = options[:timeout] + @options = default_options.merge(options) + @logger = Fluent::Logger::FluentLogger.new(@options.delete(:tag), + @options) + @timeout = @options[:timeout] end # Sends a request message and receives one or more response @@ -74,7 +74,7 @@ module Droonga # # @return [Request] The request object. def reciprocate(message, options={}, &block) - receiver = Receiver.new + receiver = create_receiver message = message.dup message["replyTo"] = "#{receiver.host}:#{receiver.port}/droonga" send(message, options) @@ -109,6 +109,11 @@ module Droonga end private + def create_receiver + Receiver.new(:host => @options[:receiver_host], + :port => @options[:receiver_port]) + end + def receive(receiver, options) timeout = options[:timeout] || @timeout @@ -133,12 +138,9 @@ module Droonga class Receiver def initialize(options={}) - default_options = { - :host => "0.0.0.0", - :port => 0, - } - options = default_options.merge(options) - @socket = TCPServer.new(options[:host], options[:port]) + host = options[:host] || Socket.gethostname + port = options[:port] || 0 + @socket = TCPServer.new(host, port) @read_ios = [@socket] @client_handlers = {} end -------------- next part -------------- HTML����������������������������...Download