Software /
code /
prosody
Diff
net/adns.lua @ 2243:bd17dd75b4a5
Merged with tip.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Fri, 27 Nov 2009 00:19:56 +0100 |
parent | 2232:aa8db84ae69d |
child | 2556:50d1ba86a959 |
line wrap: on
line diff
--- a/net/adns.lua Thu Nov 26 23:18:26 2009 +0100 +++ b/net/adns.lua Fri Nov 27 00:19:56 2009 +0100 @@ -43,33 +43,32 @@ end function new_async_socket(sock, resolver) - local newconn, peername = {}, "<unknown>"; + local peername = "<unknown>"; local listener = {}; + local handler = {}; function listener.onincoming(conn, data) - dns.feed(sock, data); + dns.feed(handler, data); end function listener.ondisconnect(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 + if resolver.socketset[conn] == 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 + handler = server.wrapclient(sock, "dns", 53, listener); + if not 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 (_, ...) 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; + + handler.settimeout = function () end + handler.setsockname = function (_, ...) return sock:setsockname(...); end + handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _:set_send(sock.send); return ret; end + handler.connect = function (_, ...) return sock:connect(...) end + handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end + return handler; end dns:socket_wrapper_set(new_async_socket);