diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-09-18 02:46:11 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-09-18 02:46:11 +0100 |
commit | 97c697c83e00be46bb38e8b5e972f36aa900582e (patch) | |
tree | 9475d3317ce41e44b003961f45e9cbeb3f34b843 /net | |
parent | 243f4c0fb35b75a3ca120c8e076ca7e7458c1c77 (diff) | |
download | prosody-97c697c83e00be46bb38e8b5e972f36aa900582e.tar.gz prosody-97c697c83e00be46bb38e8b5e972f36aa900582e.zip |
net.adns: Utilise new net.dns API to handle DNS network errors
Diffstat (limited to 'net')
-rw-r--r-- | net/adns.lua | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/net/adns.lua b/net/adns.lua index 34ef5d77..9438bf45 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -11,6 +11,7 @@ local dns = require "net.dns"; local log = require "util.logger".init("adns"); +local t_insert, t_remove = table.insert, table.remove; local coroutine, tostring, pcall = coroutine, tostring, pcall; module "adns" @@ -41,18 +42,31 @@ function cancel(handle, call_handler) end end -function new_async_socket(sock) - local newconn = {}; +function new_async_socket(sock, resolver) + local newconn, peername = {}, "<unknown>"; local listener = {}; function listener.incoming(conn, data) dns.feed(sock, data); end - function listener.disconnect() + function listener.disconnect(conn, err) + log("warn", "DNS socket for %s disconnected: %s", peername, err); + local servers = resolver.server; + if resolver.socketset[newconn.handler] == resolver.best_server and resolver.best_server == #servers then + log("error", "Exhausted all %d configured DNS servers, next lookup will try %s again", #servers, servers[1]); + end + + resolver:servfail(conn); -- Let the magic commence end newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener); + if not newconn.handler then + log("warn", "handler is nil"); + end + if not newconn._socket then + log("warn", "socket is nil"); + end newconn.handler.settimeout = function () end newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end - newconn.handler.setpeername = function (_, ...) local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end + newconn.handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end newconn.handler.connect = function (_, ...) return sock:connect(...) end newconn.handler.send = function (_, data) _.write(data); return _.sendbuffer(); end return newconn.handler; |