aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-07-05 11:50:21 +0100
committerMatthew Wild <mwild1@gmail.com>2010-07-05 11:50:21 +0100
commit4b2249df84a6c1c336464f6b62684f567b436f61 (patch)
tree1f8eaddd96463da4e6af079e00d9b26a617e37e1 /net
parent180f79f833d4b119794af21ae9cb1736e319ae1f (diff)
downloadprosody-4b2249df84a6c1c336464f6b62684f567b436f61.tar.gz
prosody-4b2249df84a6c1c336464f6b62684f567b436f61.zip
net.dns: Handle our own timeouts, including falling onto other servers in resolv.conf if necessary
Diffstat (limited to 'net')
-rw-r--r--net/dns.lua26
1 files changed, 25 insertions, 1 deletions
diff --git a/net/dns.lua b/net/dns.lua
index c0de97fd..1b8a88fa 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -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 ipairs, next, pairs, print, setmetatable, tostring, assert, error, unpack
local get, set = ztact.get, ztact.set;
+local dns_timeout = 15;
-------------------------------------------------- module dns
module('dns')
@@ -678,7 +681,28 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query
--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)