Software /
code /
prosody
Comparison
net/adns.lua @ 2232:aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 26 Nov 2009 22:08:10 +0000 |
parent | 2128:f107f0205793 |
child | 2556:50d1ba86a959 |
comparison
equal
deleted
inserted
replaced
2231:288832cdec52 | 2232:aa8db84ae69d |
---|---|
41 coroutine.resume(handle[4]); | 41 coroutine.resume(handle[4]); |
42 end | 42 end |
43 end | 43 end |
44 | 44 |
45 function new_async_socket(sock, resolver) | 45 function new_async_socket(sock, resolver) |
46 local newconn, peername = {}, "<unknown>"; | 46 local peername = "<unknown>"; |
47 local listener = {}; | 47 local listener = {}; |
48 local handler = {}; | |
48 function listener.onincoming(conn, data) | 49 function listener.onincoming(conn, data) |
49 dns.feed(sock, data); | 50 dns.feed(handler, data); |
50 end | 51 end |
51 function listener.ondisconnect(conn, err) | 52 function listener.ondisconnect(conn, err) |
52 log("warn", "DNS socket for %s disconnected: %s", peername, err); | 53 log("warn", "DNS socket for %s disconnected: %s", peername, err); |
53 local servers = resolver.server; | 54 local servers = resolver.server; |
54 if resolver.socketset[newconn.handler] == resolver.best_server and resolver.best_server == #servers then | 55 if resolver.socketset[conn] == 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 log("error", "Exhausted all %d configured DNS servers, next lookup will try %s again", #servers, servers[1]); |
56 end | 57 end |
57 | 58 |
58 resolver:servfail(conn); -- Let the magic commence | 59 resolver:servfail(conn); -- Let the magic commence |
59 end | 60 end |
60 newconn.handler, newconn._socket = server.wrapclient(sock, "dns", 53, listener); | 61 handler = server.wrapclient(sock, "dns", 53, listener); |
61 if not newconn.handler then | 62 if not handler then |
62 log("warn", "handler is nil"); | 63 log("warn", "handler is nil"); |
63 end | 64 end |
64 if not newconn._socket then | 65 |
65 log("warn", "socket is nil"); | 66 handler.settimeout = function () end |
66 end | 67 handler.setsockname = function (_, ...) return sock:setsockname(...); end |
67 newconn.handler.settimeout = function () end | 68 handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _:set_send(sock.send); return ret; end |
68 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end | 69 handler.connect = function (_, ...) return sock:connect(...) end |
69 newconn.handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end | 70 handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end |
70 newconn.handler.connect = function (_, ...) return sock:connect(...) end | 71 return handler; |
71 newconn.handler.send = function (_, data) _.write(_, data); return _.sendbuffer(); end | |
72 return newconn.handler; | |
73 end | 72 end |
74 | 73 |
75 dns:socket_wrapper_set(new_async_socket); | 74 dns:socket_wrapper_set(new_async_socket); |
76 | 75 |
77 return _M; | 76 return _M; |