1 local server = require "net.server";
2 local dns = require "net.dns2";
4 local log = require "util.logger".init("adns");
6 local coroutine, tostring = coroutine, tostring;
10 function lookup(handler, qname, qtype, qclass)
11 return dns.peek(qname, qtype, qclass) or
12 coroutine.wrap(function ()
13 log("debug", "Records for "..qname.." not in cache, sending query (%s)...", tostring(coroutine.running()));
14 dns.query(qname, qtype, qclass);
15 coroutine.yield(nil); -- Wait for reply
16 log("debug", "Reply for "..qname.." (%s)", tostring(coroutine.running()));
17 handler(dns.peek(qname, qtype, qclass));
21 function new_async_socket(sock)
24 function listener.incoming(conn, data)
27 function listener.disconnect()
29 newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener);
30 newconn.handler.settimeout = function () end
31 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end
32 newconn.handler.setpeername = function (_, ...) return sock:setpeername(...); end
33 newconn.handler.connect = function (_, ...) return sock:connect(...) end
34 newconn.handler.send = function (_, data) return _.write(data) end
35 return newconn.handler;
38 dns:socket_wrapper_set(new_async_socket);