X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=net%2Fdns.lua;h=fcc679e3d10a5bee6c40e1880f28eeaa9128ec69;hb=eab8964877447ecc589e1aa81a3179db4bf79b11;hp=6a74abd82df271094995678d3a738f377d417a91;hpb=6505bd92bd1ddefdab057d6b55349e6124abdf22;p=prosody.git diff --git a/net/dns.lua b/net/dns.lua index 6a74abd8..fcc679e3 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -29,7 +29,7 @@ local ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack local get, set = ztact.get, ztact.set; -local dns_timeout = 15; +local default_timeout = 15; -------------------------------------------------- module dns module('dns') @@ -118,6 +118,7 @@ end local resolver = {}; resolver.__index = resolver; +resolver.timeout = default_timeout; local SRV_tostring; @@ -684,10 +685,10 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query local conn = self:getsocket(o.server) conn:send (o.packet) - if timer then + if timer and self.timeout then local num_servers = #self.server; local i = 1; - timer.add_task(dns_timeout, function () + timer.add_task(self.timeout, function () if get(self.wanted, qclass, qtype, qname, co) then if i < num_servers then i = i + 1; @@ -695,10 +696,10 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query o.server = self.best_server; conn = self:getsocket(o.server); conn:send(o.packet); - return dns_timeout; + return self.timeout; else -- Tried everything, failed - resolver:cancel({qclass, qtype, qname, co}, true); + self:cancel(qclass, qtype, qname, co, true); end end end) @@ -744,6 +745,10 @@ function resolver:servfail(sock) end end +function resolver:settimeout(seconds) + self.timeout = seconds; +end + function resolver:receive(rset) -- - - - - - - - - - - - - - - - - receive --print('receive'); print(self.socket); self.time = socket.gettime(); @@ -830,13 +835,13 @@ function resolver:feed(sock, packet) return response; end -function resolver:cancel(data, call_handler) - local cos = get(self.wanted, unpack(data, 1, 3)); +function resolver:cancel(qclass, qtype, qname, co, call_handler) + local cos = get(self.wanted, qclass, qtype, qname); if cos then if call_handler then - coroutine.resume(data[4]); + coroutine.resume(co); end - cos[data[4]] = nil; + cos[co] = nil; end end @@ -988,6 +993,10 @@ function dns.cancel(...) -- - - - - - - - - - - - - - - - - - - - - - cancel return _resolver:cancel(...); end +function dns.settimeout(...) + return _resolver:settimeout(...); +end + function dns.socket_wrapper_set(...) -- - - - - - - - - socket_wrapper_set return _resolver:socket_wrapper_set(...); end