mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/resolv.rb (Resolv::DNS::open, close): new.
* lib/optparse.rb, lib/optparse: import. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6ad9e20504
commit
6af4aebc95
3 changed files with 1652 additions and 17 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Jul 13 01:25:38 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* lib/resolv.rb (Resolv::DNS::open, close): new.
|
||||||
|
|
||||||
|
* lib/optparse.rb, lib/optparse: import.
|
||||||
|
|
||||||
Fri Jul 12 06:34:05 2002 Minero Aoki <aamine@loveruby.net>
|
Fri Jul 12 06:34:05 2002 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/net/http.rb: rename HTTP.get_uri get_response.
|
* lib/net/http.rb: rename HTTP.get_uri get_response.
|
||||||
|
|
1605
lib/optparse.rb
Normal file
1605
lib/optparse.rb
Normal file
File diff suppressed because it is too large
Load diff
|
@ -59,7 +59,12 @@ DNS stub resolver.
|
||||||
=== class methods
|
=== class methods
|
||||||
--- Resolv::DNS.new(resolv_conf='/etc/resolv.conf')
|
--- Resolv::DNS.new(resolv_conf='/etc/resolv.conf')
|
||||||
|
|
||||||
|
--- Resolv::DNS.open(resolv_conf='/etc/resolv.conf')
|
||||||
|
--- Resolv::DNS.open(resolv_conf='/etc/resolv.conf') {|dns| ...}
|
||||||
|
|
||||||
=== methods
|
=== methods
|
||||||
|
--- Resolv::DNS#close
|
||||||
|
|
||||||
--- Resolv::DNS#getaddress(name)
|
--- Resolv::DNS#getaddress(name)
|
||||||
--- Resolv::DNS#getaddresses(name)
|
--- Resolv::DNS#getaddresses(name)
|
||||||
--- Resolv::DNS#each_address(name) {|address| ...}
|
--- Resolv::DNS#each_address(name) {|address| ...}
|
||||||
|
@ -173,7 +178,6 @@ DNS stub resolver.
|
||||||
* NIS is not supported.
|
* NIS is not supported.
|
||||||
* /etc/nsswitch.conf is not supported.
|
* /etc/nsswitch.conf is not supported.
|
||||||
* IPv6 is not supported.
|
* IPv6 is not supported.
|
||||||
* There is no method to close DNS socket.
|
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -350,6 +354,16 @@ class Resolv
|
||||||
|
|
||||||
DNSThreadGroup = ThreadGroup.new
|
DNSThreadGroup = ThreadGroup.new
|
||||||
|
|
||||||
|
def self.open(*args)
|
||||||
|
dns = new(*args)
|
||||||
|
return dns unless block_given?
|
||||||
|
begin
|
||||||
|
yield dns
|
||||||
|
ensure
|
||||||
|
dns.close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(config="/etc/resolv.conf")
|
def initialize(config="/etc/resolv.conf")
|
||||||
@mutex = Mutex.new
|
@mutex = Mutex.new
|
||||||
@config = Config.new(config)
|
@config = Config.new(config)
|
||||||
|
@ -372,6 +386,16 @@ class Resolv
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
@mutex.synchronize {
|
||||||
|
if @initialized
|
||||||
|
@requester.close if @requester
|
||||||
|
@requester = nil
|
||||||
|
@initialized = false
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def getaddress(name)
|
def getaddress(name)
|
||||||
each_address(name) {|address| return address}
|
each_address(name) {|address| return address}
|
||||||
raise ResolvError.new("DNS result has no information for #{name}")
|
raise ResolvError.new("DNS result has no information for #{name}")
|
||||||
|
@ -490,6 +514,18 @@ class Resolv
|
||||||
@senders = {}
|
@senders = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
thread, sock, @thread, @sock = @thread, @sock
|
||||||
|
begin
|
||||||
|
if thread
|
||||||
|
thread.kill
|
||||||
|
thread.join
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
sock.close if sock
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete(arg)
|
def delete(arg)
|
||||||
case arg
|
case arg
|
||||||
when Sender
|
when Sender
|
||||||
|
@ -502,8 +538,10 @@ class Resolv
|
||||||
end
|
end
|
||||||
|
|
||||||
class Sender
|
class Sender
|
||||||
def initialize(data, queue)
|
def initialize(msg, data, sock, queue)
|
||||||
|
@msg = msg
|
||||||
@data = data
|
@data = data
|
||||||
|
@sock = sock
|
||||||
@queue = queue
|
@queue = queue
|
||||||
end
|
end
|
||||||
attr_reader :queue
|
attr_reader :queue
|
||||||
|
@ -552,9 +590,7 @@ class Resolv
|
||||||
|
|
||||||
class Sender < Requester::Sender
|
class Sender < Requester::Sender
|
||||||
def initialize(msg, data, sock, host, port, queue)
|
def initialize(msg, data, sock, host, port, queue)
|
||||||
super(data, queue)
|
super(msg, data, sock, queue)
|
||||||
@msg = msg
|
|
||||||
@sock = sock
|
|
||||||
@host = host
|
@host = host
|
||||||
@port = port
|
@port = port
|
||||||
end
|
end
|
||||||
|
@ -604,12 +640,6 @@ class Resolv
|
||||||
end
|
end
|
||||||
|
|
||||||
class Sender < Requester::Sender
|
class Sender < Requester::Sender
|
||||||
def initialize(msg, data, sock, queue)
|
|
||||||
super(data, queue)
|
|
||||||
@msg = msg
|
|
||||||
@sock = sock
|
|
||||||
end
|
|
||||||
|
|
||||||
def send
|
def send
|
||||||
@sock.send(@msg, 0)
|
@sock.send(@msg, 0)
|
||||||
end
|
end
|
||||||
|
@ -657,12 +687,6 @@ class Resolv
|
||||||
end
|
end
|
||||||
|
|
||||||
class Sender < Requester::Sender
|
class Sender < Requester::Sender
|
||||||
def initialize(msg, data, sock, queue)
|
|
||||||
super(data, queue)
|
|
||||||
@msg = msg
|
|
||||||
@sock = sock
|
|
||||||
end
|
|
||||||
|
|
||||||
def send
|
def send
|
||||||
@sock.print(@msg)
|
@sock.print(@msg)
|
||||||
@sock.flush
|
@sock.flush
|
||||||
|
|
Loading…
Reference in a new issue