Software /
code /
prosody
Diff
net/dns.lua @ 3324:070c8ba71b76
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 05 Jul 2010 11:50:21 +0100 |
parent | 3057:ca1fe9f74bd0 |
child | 3325:b3117a1da834 |
line wrap: on
line diff
--- a/net/dns.lua Mon Jul 05 02:20:37 2010 +0100 +++ b/net/dns.lua Mon Jul 05 11:50:21 2010 +0100 @@ -16,6 +16,8 @@ local socket = require "socket"; local ztact = require "util.ztact"; +local timer = require "util.timer"; + local _, windows = pcall(require, "util.windows"); local is_windows = (_ and windows) or os.getenv("WINDIR"); @@ -27,6 +29,7 @@ local get, set = ztact.get, ztact.set; +local dns_timeout = 15; -------------------------------------------------- module dns module('dns') @@ -678,7 +681,28 @@ --set(self.yielded, co, qclass, qtype, qname, true); end - self:getsocket (o.server):send (o.packet) + local conn = self:getsocket(o.server) + conn:send (o.packet) + + if timer then + local num_servers = #self.server; + local i = 1; + timer.add_task(dns_timeout, function () + if get(self.wanted, qclass, qtype, qname, co) then + if i < num_servers then + i = i + 1; + self:servfail(conn); + o.server = self.best_server; + conn = self:getsocket(o.server); + conn:send(o.packet); + return dns_timeout; + else + -- Tried everything, failed + resolver:cancel({qclass, qtype, qname, co}, true); + end + end + end) + end end function resolver:servfail(sock)