From: nobu.nokada@... Date: 2002-04-19T11:38:56+09:00 Subject: Re: resolv.rb Bug Hi, At Fri, 19 Apr 2002 10:09:44 +0900, Roy J. Milican wrote: > >> I did both of the patches on resolv.rb and I am still having the > >> problems with it saying too many files open. > > nnsn> After applying the second patch, you need to close the DNS > nnsn> object explicitly, or use DNS.open with a block. Sorry, I was wrong completely. Try with following patch. > Could you give me an example. Sorry if I'm being dumb here but my > patched version is still doing the "Too many files open" thing. Since > I didn't know what you ment quite by close the DNS object explicitly I > changed my DNS.new to DNS.open, no error running it but it still gives > me the too many files error after 256 times. This is the code I'm > using. mx = Resolv::DNS.open {|dns| dns.getresources(@domain, Resolv::DNS::Resource::IN::MX)} domainrecord = mx.collect{|r| [r.exchange.to_s, r.preference]} Index: resolv.rb =================================================================== RCS file: /cvs/ruby/src/ruby/lib/resolv.rb,v retrieving revision 1.11 diff -u -2 -p -r1.11 resolv.rb --- resolv.rb 2002/04/18 05:11:31 1.11 +++ resolv.rb 2002/04/19 02:36:35 @@ -348,4 +348,14 @@ 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 @@ -370,4 +380,14 @@ 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} @@ -486,4 +506,9 @@ class Resolv def initialize @senders = {} + end + + def close + @sock.close if @sock + @sock = nil end -- Nobu Nakada