Software /
code /
prosody
Comparison
net/adns.lua @ 1788:45779d67c26c
Merge with 0.5
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 18 Sep 2009 02:48:52 +0100 |
parent | 1715:3a5b6cd6b8c9 |
parent | 1787:c4dff34f3d32 |
child | 1901:3c52b949e472 |
comparison
equal
deleted
inserted
replaced
1784:b2bfd3b93da6 | 1788:45779d67c26c |
---|---|
9 local server = require "net.server"; | 9 local server = require "net.server"; |
10 local dns = require "net.dns"; | 10 local dns = require "net.dns"; |
11 | 11 |
12 local log = require "util.logger".init("adns"); | 12 local log = require "util.logger".init("adns"); |
13 | 13 |
14 local t_insert, t_remove = table.insert, table.remove; | |
14 local coroutine, tostring, pcall = coroutine, tostring, pcall; | 15 local coroutine, tostring, pcall = coroutine, tostring, pcall; |
15 | 16 |
16 module "adns" | 17 module "adns" |
17 | 18 |
18 function lookup(handler, qname, qtype, qclass) | 19 function lookup(handler, qname, qtype, qclass) |
39 if call_handler then | 40 if call_handler then |
40 coroutine.resume(handle[4]); | 41 coroutine.resume(handle[4]); |
41 end | 42 end |
42 end | 43 end |
43 | 44 |
44 function new_async_socket(sock) | 45 function new_async_socket(sock, resolver) |
45 local newconn = {}; | 46 local newconn, peername = {}, "<unknown>"; |
46 local listener = {}; | 47 local listener = {}; |
47 function listener.incoming(conn, data) | 48 function listener.incoming(conn, data) |
48 dns.feed(sock, data); | 49 dns.feed(sock, data); |
49 end | 50 end |
50 function listener.disconnect() | 51 function listener.disconnect(conn, err) |
52 log("warn", "DNS socket for %s disconnected: %s", peername, err); | |
53 local servers = resolver.server; | |
54 if resolver.socketset[newconn.handler] == resolver.best_server and resolver.best_server == #servers then | |
55 log("error", "Exhausted all %d configured DNS servers, next lookup will try %s again", #servers, servers[1]); | |
56 end | |
57 | |
58 resolver:servfail(conn); -- Let the magic commence | |
51 end | 59 end |
52 newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener); | 60 newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener); |
53 if not newconn.handler then | 61 if not newconn.handler then |
54 log("warn", "handler is nil"); | 62 log("warn", "handler is nil"); |
55 end | 63 end |
56 if not newconn._socket then | 64 if not newconn._socket then |
57 log("warn", "socket is nil"); | 65 log("warn", "socket is nil"); |
58 end | 66 end |
59 newconn.handler.settimeout = function () end | 67 newconn.handler.settimeout = function () end |
60 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end | 68 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end |
61 newconn.handler.setpeername = function (_, ...) local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end | 69 newconn.handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end |
62 newconn.handler.connect = function (_, ...) return sock:connect(...) end | 70 newconn.handler.connect = function (_, ...) return sock:connect(...) end |
63 newconn.handler.send = function (_, data) _.write(data); return _.sendbuffer(); end | 71 newconn.handler.send = function (_, data) _.write(data); return _.sendbuffer(); end |
64 return newconn.handler; | 72 return newconn.handler; |
65 end | 73 end |
66 | 74 |