ruby-changes:14400
From: akr <ko1@a...>
Date: Sat, 2 Jan 2010 16:07:29 +0900 (JST)
Subject: [ruby-changes:14400] Ruby:r26230 (trunk): * lib/resolv.rb (Resolv::DNS#initialize): new option :nameserver_port.
akr 2010-01-02 16:03:24 +0900 (Sat, 02 Jan 2010) New Revision: 26230 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26230 Log: * lib/resolv.rb (Resolv::DNS#initialize): new option :nameserver_port. (Resolv::DNS#each_resource): pass port number. (Resolv::DNS#make_requester): ditto. (Resolv::DNS::Config#lazy_initialize): initialize @nameserver_port instead of @nameserver. (Resolv::DNS::Config#single?): return port number addition to the nameserver. (Resolv::DNS::Config#generate_timeouts): use @nameserver_port. (Resolv::DNS::Config#resolv): yield port number. Modified files: trunk/ChangeLog trunk/lib/resolv.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 26229) +++ ChangeLog (revision 26230) @@ -1,3 +1,15 @@ +Sat Jan 2 15:57:54 2010 Tanaka Akira <akr@f...> + + * lib/resolv.rb (Resolv::DNS#initialize): new option :nameserver_port. + (Resolv::DNS#each_resource): pass port number. + (Resolv::DNS#make_requester): ditto. + (Resolv::DNS::Config#lazy_initialize): initialize @nameserver_port + instead of @nameserver. + (Resolv::DNS::Config#single?): return port number addition to the + nameserver. + (Resolv::DNS::Config#generate_timeouts): use @nameserver_port. + (Resolv::DNS::Config#resolv): yield port number. + Sat Jan 2 00:43:22 2010 NARUSE, Yui <naruse@r...> * lib/uri/common.rb (initialize_regexp): allow leading Index: lib/resolv.rb =================================================================== --- lib/resolv.rb (revision 26229) +++ lib/resolv.rb (revision 26230) @@ -313,7 +313,17 @@ # nil:: Uses /etc/resolv.conf. # String:: Path to a file using /etc/resolv.conf's format. # Hash:: Must contain :nameserver, :search and :ndots keys. + # :nameserver_port can be used to specify port number of nameserver address. # + # The value of :nameserver should be an address string or + # an array of address strings. + # - :nameserver => '8.8.8.8' + # - :nameserver => ['8.8.8.8', '8.8.4.4'] + # + # The value of :nameserver_port should be an array of + # pair of nameserver address and port number. + # - :nameserver_port => [['8.8.8.8', 53], ['8.8.4.4', 53]] + # # Example: # # Resolv::DNS.new(:nameserver => ['210.251.121.21'], @@ -485,13 +495,13 @@ requester = make_requester senders = {} begin - @config.resolv(name) {|candidate, tout, nameserver| + @config.resolv(name) {|candidate, tout, nameserver, port| msg = Message.new msg.rd = 1 msg.add_question(candidate, typeclass) - unless sender = senders[[candidate, nameserver]] - sender = senders[[candidate, nameserver]] = - requester.sender(msg, candidate, nameserver) + unless sender = senders[[candidate, nameserver, port]] + sender = senders[[candidate, nameserver, port]] = + requester.sender(msg, candidate, nameserver, port) end reply, reply_name = requester.request(sender, tout) case reply.rcode @@ -510,8 +520,8 @@ end def make_requester # :nodoc: - if nameserver = @config.single? - Requester::ConnectedUDP.new(nameserver) + if nameserver_port = @config.single? + Requester::ConnectedUDP.new(*nameserver_port) else Requester::UnconnectedUDP.new end @@ -846,7 +856,7 @@ def lazy_initialize @mutex.synchronize { unless @initialized - @nameserver = [] + @nameserver_port = [] @search = nil @ndots = 1 case @config_info @@ -865,11 +875,18 @@ else raise ArgumentError.new("invalid resolv configuration: #{@config_info.inspect}") end - @nameserver = config_hash[:nameserver] if config_hash.include? :nameserver + if config_hash.include? :nameserver + @nameserver_port = config_hash[:nameserver].map {|ns| [ns, Port] } + end + if config_hash.include? :nameserver_port + @nameserver_port = config_hash[:nameserver_port].map {|ns, port| [ns, (port || Port)] } + end @search = config_hash[:search] if config_hash.include? :search @ndots = config_hash[:ndots] if config_hash.include? :ndots - @nameserver = ['0.0.0.0'] if @nameserver.empty? + if @nameserver_port.empty? + @nameserver_port = ['0.0.0.0', Port] + end if @search @search = @search.map {|arg| Label.split(arg) } else @@ -881,9 +898,14 @@ end end - if !@nameserver.kind_of?(Array) || - !@nameserver.all? {|ns| String === ns } - raise ArgumentError.new("invalid nameserver config: #{@nameserver.inspect}") + if !@nameserver_port.kind_of?(Array) || + @nameserver_port.any? {|ns_port| + !(Array === ns_port) || + ns_port.length != 2 + !(String === ns_port[0]) || + !(Integer === ns_port[1]) + } + raise ArgumentError.new("invalid nameserver config: #{@nameserver_port.inspect}") end if !@search.kind_of?(Array) || @@ -903,8 +925,8 @@ def single? lazy_initialize - if @nameserver.length == 1 - return @nameserver[0] + if @nameserver_port.length == 1 + return @nameserver_port[0] else return nil end @@ -930,7 +952,7 @@ def generate_timeouts ts = [InitialTimeout] - ts << ts[-1] * 2 / @nameserver.length + ts << ts[-1] * 2 / @nameserver_port.length ts << ts[-1] * 2 ts << ts[-1] * 2 return ts @@ -943,9 +965,9 @@ candidates.each {|candidate| begin timeouts.each {|tout| - @nameserver.each {|nameserver| + @nameserver_port.each {|nameserver, port| begin - yield candidate, tout, nameserver + yield candidate, tout, nameserver, port rescue ResolvTimeout end } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/