Comparison

net/adns.lua @ 2128:f107f0205793

net.adns: Update for new net.server API (doesn't work with libevent yet)
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Nov 2009 04:42:47 +0000
parent 1901:3c52b949e472
child 2232:aa8db84ae69d
comparison
equal deleted inserted replaced
2127:be3c906f4770 2128:f107f0205793
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 newconn, peername = {}, "<unknown>";
47 local listener = {}; 47 local listener = {};
48 function listener.incoming(conn, data) 48 function listener.onincoming(conn, data)
49 dns.feed(sock, data); 49 dns.feed(sock, data);
50 end 50 end
51 function listener.disconnect(conn, err) 51 function listener.ondisconnect(conn, err)
52 log("warn", "DNS socket for %s disconnected: %s", peername, err); 52 log("warn", "DNS socket for %s disconnected: %s", peername, err);
53 local servers = resolver.server; 53 local servers = resolver.server;
54 if resolver.socketset[newconn.handler] == resolver.best_server and resolver.best_server == #servers then 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]); 55 log("error", "Exhausted all %d configured DNS servers, next lookup will try %s again", #servers, servers[1]);
56 end 56 end
66 end 66 end
67 newconn.handler.settimeout = function () end 67 newconn.handler.settimeout = function () end
68 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end 68 newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end
69 newconn.handler.setpeername = function (_, ...) peername = (...); 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
70 newconn.handler.connect = function (_, ...) return sock:connect(...) end 70 newconn.handler.connect = function (_, ...) return sock:connect(...) end
71 newconn.handler.send = function (_, data) _.write(data); return _.sendbuffer(); end 71 newconn.handler.send = function (_, data) _.write(_, data); return _.sendbuffer(); end
72 return newconn.handler; 72 return newconn.handler;
73 end 73 end
74 74
75 dns:socket_wrapper_set(new_async_socket); 75 dns:socket_wrapper_set(new_async_socket);
76 76