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>
|
||||
|
||||
* 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
|
||||
--- 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
|
||||
--- Resolv::DNS#close
|
||||
|
||||
--- Resolv::DNS#getaddress(name)
|
||||
--- Resolv::DNS#getaddresses(name)
|
||||
--- Resolv::DNS#each_address(name) {|address| ...}
|
||||
|
@ -173,7 +178,6 @@ DNS stub resolver.
|
|||
* NIS is not supported.
|
||||
* /etc/nsswitch.conf is not supported.
|
||||
* IPv6 is not supported.
|
||||
* There is no method to close DNS socket.
|
||||
|
||||
=end
|
||||
|
||||
|
@ -350,6 +354,16 @@ class Resolv
|
|||
|
||||
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")
|
||||
@mutex = Mutex.new
|
||||
@config = Config.new(config)
|
||||
|
@ -372,6 +386,16 @@ class Resolv
|
|||
}
|
||||
end
|
||||
|
||||
def close
|
||||
@mutex.synchronize {
|
||||
if @initialized
|
||||
@requester.close if @requester
|
||||
@requester = nil
|
||||
@initialized = false
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def getaddress(name)
|
||||
each_address(name) {|address| return address}
|
||||
raise ResolvError.new("DNS result has no information for #{name}")
|
||||
|
@ -490,6 +514,18 @@ class Resolv
|
|||
@senders = {}
|
||||
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)
|
||||
case arg
|
||||
when Sender
|
||||
|
@ -502,8 +538,10 @@ class Resolv
|
|||
end
|
||||
|
||||
class Sender
|
||||
def initialize(data, queue)
|
||||
def initialize(msg, data, sock, queue)
|
||||
@msg = msg
|
||||
@data = data
|
||||
@sock = sock
|
||||
@queue = queue
|
||||
end
|
||||
attr_reader :queue
|
||||
|
@ -552,9 +590,7 @@ class Resolv
|
|||
|
||||
class Sender < Requester::Sender
|
||||
def initialize(msg, data, sock, host, port, queue)
|
||||
super(data, queue)
|
||||
@msg = msg
|
||||
@sock = sock
|
||||
super(msg, data, sock, queue)
|
||||
@host = host
|
||||
@port = port
|
||||
end
|
||||
|
@ -604,12 +640,6 @@ class Resolv
|
|||
end
|
||||
|
||||
class Sender < Requester::Sender
|
||||
def initialize(msg, data, sock, queue)
|
||||
super(data, queue)
|
||||
@msg = msg
|
||||
@sock = sock
|
||||
end
|
||||
|
||||
def send
|
||||
@sock.send(@msg, 0)
|
||||
end
|
||||
|
@ -657,12 +687,6 @@ class Resolv
|
|||
end
|
||||
|
||||
class Sender < Requester::Sender
|
||||
def initialize(msg, data, sock, queue)
|
||||
super(data, queue)
|
||||
@msg = msg
|
||||
@sock = sock
|
||||
end
|
||||
|
||||
def send
|
||||
@sock.print(@msg)
|
||||
@sock.flush
|
||||
|
|
Loading…
Reference in a new issue