Comparison

net/adns.lua @ 9731:47121e8dc5b1

net.adns: Silence individual luacheck warnings instead of ignoring entire file
author Kim Alvefur <zash@zash.se>
date Mon, 24 Dec 2018 03:00:27 +0100
parent 8555:4f0f5b49bb03
child 10112:b327f2870382
comparison
equal deleted inserted replaced
9730:69ef22961b7d 9731:47121e8dc5b1
12 local log = require "util.logger".init("adns"); 12 local log = require "util.logger".init("adns");
13 13
14 local coroutine, tostring, pcall = coroutine, tostring, pcall; 14 local coroutine, tostring, pcall = coroutine, tostring, pcall;
15 local setmetatable = setmetatable; 15 local setmetatable = setmetatable;
16 16
17 local function dummy_send(sock, data, i, j) return (j-i)+1; end 17 local function dummy_send(sock, data, i, j) return (j-i)+1; end -- luacheck: ignore 212
18 18
19 local _ENV = nil; 19 local _ENV = nil;
20 -- luacheck: std none 20 -- luacheck: std none
21 21
22 local async_resolver_methods = {}; 22 local async_resolver_methods = {};
27 27
28 local function new_async_socket(sock, resolver) 28 local function new_async_socket(sock, resolver)
29 local peername = "<unknown>"; 29 local peername = "<unknown>";
30 local listener = {}; 30 local listener = {};
31 local handler = {}; 31 local handler = {};
32 local err; 32 function listener.onincoming(conn, data) -- luacheck: ignore 212/conn
33 function listener.onincoming(conn, data)
34 if data then 33 if data then
35 resolver:feed(handler, data); 34 resolver:feed(handler, data);
36 end 35 end
37 end 36 end
38 function listener.ondisconnect(conn, err) 37 function listener.ondisconnect(conn, err)
44 end 43 end
45 44
46 resolver:servfail(conn); -- Let the magic commence 45 resolver:servfail(conn); -- Let the magic commence
47 end 46 end
48 end 47 end
49 handler, err = server.wrapclient(sock, "dns", 53, listener); 48 do
50 if not handler then 49 local err;
51 return nil, err; 50 handler, err = server.wrapclient(sock, "dns", 53, listener);
51 if not handler then
52 return nil, err;
53 end
52 end 54 end
53 55
54 handler.settimeout = function () end 56 handler.settimeout = function () end
55 handler.setsockname = function (_, ...) return sock:setsockname(...); end 57 handler.setsockname = function (_, ...) return sock:setsockname(...); end
56 handler.setpeername = function (_, ...) peername = (...); local ret, err = sock:setpeername(...); _:set_send(dummy_send); return ret, err; end 58 handler.setpeername = function (_, ...) peername = (...); local ret, err = sock:setpeername(...); _:set_send(dummy_send); return ret, err; end
87 log("error", "Error in DNS response handler: %s", tostring(err)); 89 log("error", "Error in DNS response handler: %s", tostring(err));
88 end 90 end
89 end)(resolver:peek(qname, qtype, qclass)); 91 end)(resolver:peek(qname, qtype, qclass));
90 end 92 end
91 93
92 function query_methods:cancel(call_handler, reason) 94 function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason
93 log("warn", "Cancelling DNS lookup for %s", tostring(self[4])); 95 log("warn", "Cancelling DNS lookup for %s", tostring(self[4]));
94 self[1].cancel(self[2], self[3], self[4], self[5], call_handler); 96 self[1].cancel(self[2], self[3], self[4], self[5], call_handler);
95 end 97 end
96 98
97 local function new_async_resolver() 99 local function new_async_resolver()