Software /
code /
prosody
Annotate
net/adns.lua @ 13227:58083329903d
mod_muc_mam: Use period option method
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 Jul 2023 12:33:51 +0200 |
parent | 12974:ba409c67353b |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1208
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2710
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2710
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5730
diff
changeset
|
4 -- |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1208
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1208
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1208
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1208
diff
changeset
|
8 |
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11267
diff
changeset
|
9 local server = require "prosody.net.server"; |
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11267
diff
changeset
|
10 local new_resolver = require "prosody.net.dns".resolver; |
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11267
diff
changeset
|
11 local promise = require "prosody.util.promise"; |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
12974
ba409c67353b
net: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11267
diff
changeset
|
13 local log = require "prosody.util.logger".init("adns"); |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
10974
3b9d533da8fe
util.dependencies: Tone down lua-unbound dependency for now
Kim Alvefur <zash@zash.se>
parents:
10966
diff
changeset
|
15 log("debug", "Using legacy DNS API (missing lua-unbound?)"); -- TODO write docs about luaunbound |
3b9d533da8fe
util.dependencies: Tone down lua-unbound dependency for now
Kim Alvefur <zash@zash.se>
parents:
10966
diff
changeset
|
16 -- TODO Raise log level once packages are available |
10966
97de279ca01a
net.adns: Log a warning if loaded (because net.unbound wasn't)
Kim Alvefur <zash@zash.se>
parents:
10614
diff
changeset
|
17 |
10114
2f7628804db6
net.adns: Remove unused local [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10112
diff
changeset
|
18 local coroutine, pcall = coroutine, pcall; |
8280
9ca0e3128b62
net.adns: Import setmetatable into a local (fixes traceback on Lua 5.2)
Kim Alvefur <zash@zash.se>
parents:
8266
diff
changeset
|
19 local setmetatable = setmetatable; |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
9731
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
21 local function dummy_send(sock, data, i, j) return (j-i)+1; end -- luacheck: ignore 212 |
2558
0a65fc0c7bee
net.adns: Use different flavour of voodoo to make UDP sockets work smoothly with libevent (no packet merging)
Matthew Wild <mwild1@gmail.com>
parents:
2556
diff
changeset
|
22 |
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6510
diff
changeset
|
23 local _ENV = nil; |
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8280
diff
changeset
|
24 -- luacheck: std none |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
26 local async_resolver_methods = {}; |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
27 local async_resolver_mt = { __index = async_resolver_methods }; |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
29 local query_methods = {}; |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
30 local query_mt = { __index = query_methods }; |
1203
23725bfdeed5
net.adns: Add support for cancelling a non-blocking lookup, optionally calling the handler
Matthew Wild <mwild1@gmail.com>
parents:
1005
diff
changeset
|
31 |
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6510
diff
changeset
|
32 local function new_async_socket(sock, resolver) |
2232
aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
Matthew Wild <mwild1@gmail.com>
parents:
2128
diff
changeset
|
33 local peername = "<unknown>"; |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local listener = {}; |
2232
aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
Matthew Wild <mwild1@gmail.com>
parents:
2128
diff
changeset
|
35 local handler = {}; |
9731
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
36 function listener.onincoming(conn, data) -- luacheck: ignore 212/conn |
2652
cbc58fc170ad
net.adns: Fix potential traceback on DNS responses with libevent enabled (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2578
diff
changeset
|
37 if data then |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
38 resolver:feed(handler, data); |
2652
cbc58fc170ad
net.adns: Fix potential traceback on DNS responses with libevent enabled (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2578
diff
changeset
|
39 end |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
2128
f107f0205793
net.adns: Update for new net.server API (doesn't work with libevent yet)
Matthew Wild <mwild1@gmail.com>
parents:
1901
diff
changeset
|
41 function listener.ondisconnect(conn, err) |
2661
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
42 if err then |
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
43 log("warn", "DNS socket for %s disconnected: %s", peername, err); |
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
44 local servers = resolver.server; |
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
45 if resolver.socketset[conn] == resolver.best_server and resolver.best_server == #servers then |
11217
65ce1178d655
net.adns: Reduce 'Exhausted all servers' message to warning
Matthew Wild <mwild1@gmail.com>
parents:
10974
diff
changeset
|
46 log("warn", "Exhausted all %d configured DNS servers, next lookup will try %s again", #servers, servers[1]); |
2661
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
47 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5730
diff
changeset
|
48 |
2661
be4b1e796bd2
net.adns: Don't treat locally-initiated disconnects as fatal with libevent backend in use (thanks Flo)
Matthew Wild <mwild1@gmail.com>
parents:
2652
diff
changeset
|
49 resolver:servfail(conn); -- Let the magic commence |
1787
c4dff34f3d32
net.adns: Utilise new net.dns API to handle DNS network errors
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
50 end |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
9731
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
52 do |
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
53 local err; |
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
54 handler, err = server.wrapclient(sock, "dns", 53, listener); |
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
55 if not handler then |
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
56 return nil, err; |
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
57 end |
1787
c4dff34f3d32
net.adns: Utilise new net.dns API to handle DNS network errors
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
58 end |
11266
2115496e8251
net.adns: Prevent empty packets from being sent on "connect" (fix #1619)
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
59 if handler.set then |
2115496e8251
net.adns: Prevent empty packets from being sent on "connect" (fix #1619)
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
60 -- server_epoll: only watch for incoming data |
2115496e8251
net.adns: Prevent empty packets from being sent on "connect" (fix #1619)
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
61 -- avoids sending empty packet on first 'onwritable' event |
2115496e8251
net.adns: Prevent empty packets from being sent on "connect" (fix #1619)
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
62 handler:set(true, false); |
2115496e8251
net.adns: Prevent empty packets from being sent on "connect" (fix #1619)
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
63 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5730
diff
changeset
|
64 |
2232
aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
Matthew Wild <mwild1@gmail.com>
parents:
2128
diff
changeset
|
65 handler.settimeout = function () end |
aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
Matthew Wild <mwild1@gmail.com>
parents:
2128
diff
changeset
|
66 handler.setsockname = function (_, ...) return sock:setsockname(...); end |
6506
f869eec511c8
net.adns: Preserve error from setpeername
Kim Alvefur <zash@zash.se>
parents:
6287
diff
changeset
|
67 handler.setpeername = function (_, ...) peername = (...); local ret, err = sock:setpeername(...); _:set_send(dummy_send); return ret, err; end |
2556
50d1ba86a959
net.adns: Trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2232
diff
changeset
|
68 handler.connect = function (_, ...) return sock:connect(...) end |
2558
0a65fc0c7bee
net.adns: Use different flavour of voodoo to make UDP sockets work smoothly with libevent (no packet merging)
Matthew Wild <mwild1@gmail.com>
parents:
2556
diff
changeset
|
69 --handler.send = function (_, data) _:write(data); return _.sendbuffer and _.sendbuffer(); end |
3990
764922062c38
net.adns: Log the DNS server that a query is sent to
Matthew Wild <mwild1@gmail.com>
parents:
3956
diff
changeset
|
70 handler.send = function (_, data) |
6507
84ca02c6a47e
net.adns: Log peername recorded from wrapped setpeername instead of calling sock:getpeername, it exists and throws an error on unconnected sockets (thanks wirehack7)
Kim Alvefur <zash@zash.se>
parents:
6506
diff
changeset
|
71 log("debug", "Sending DNS query to %s", peername); |
3990
764922062c38
net.adns: Log the DNS server that a query is sent to
Matthew Wild <mwild1@gmail.com>
parents:
3956
diff
changeset
|
72 return sock:send(data); |
764922062c38
net.adns: Log the DNS server that a query is sent to
Matthew Wild <mwild1@gmail.com>
parents:
3956
diff
changeset
|
73 end |
2232
aa8db84ae69d
net.adns: Some cleanup, happens to also make it compatible with libevent
Matthew Wild <mwild1@gmail.com>
parents:
2128
diff
changeset
|
74 return handler; |
870
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 end |
4fd5d8f1657c
net.adns: Add helper module for performing non-blocking DNS lookups
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
77 function async_resolver_methods:lookup(handler, qname, qtype, qclass) |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
78 local resolver = self._resolver; |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
79 return coroutine.wrap(function (peek) |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
80 if peek then |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
81 log("debug", "Records for %s already cached, using those...", qname); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
82 handler(peek); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
83 return; |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
84 end |
10112
b327f2870382
net.*: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
9731
diff
changeset
|
85 log("debug", "Records for %s not in cache, sending query (%s)...", qname, coroutine.running()); |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
86 local ok, err = resolver:query(qname, qtype, qclass); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
87 if ok then |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
88 coroutine.yield(setmetatable({ resolver, qclass or "IN", qtype or "A", qname, coroutine.running()}, query_mt)); -- Wait for reply |
10112
b327f2870382
net.*: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
9731
diff
changeset
|
89 log("debug", "Reply for %s (%s)", qname, coroutine.running()); |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
90 end |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
91 if ok then |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
92 ok, err = pcall(handler, resolver:peek(qname, qtype, qclass)); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
93 else |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
94 log("error", "Error sending DNS query: %s", err); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
95 ok, err = pcall(handler, nil, err); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
96 end |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
97 if not ok then |
10112
b327f2870382
net.*: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
9731
diff
changeset
|
98 log("error", "Error in DNS response handler: %s", err); |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
99 end |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
100 end)(resolver:peek(qname, qtype, qclass)); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
101 end |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
102 |
10614
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
103 function async_resolver_methods:lookup_promise(qname, qtype, qclass) |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
104 return promise.new(function (resolve, reject) |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
105 local function handler(answer) |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
106 if not answer then |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
107 return reject(); |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
108 end |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
109 resolve(answer); |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
110 end |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
111 self:lookup(handler, qname, qtype, qclass); |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
112 end); |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
113 end |
431511e190bc
net.adns: Add :lookup_promise() method
Matthew Wild <mwild1@gmail.com>
parents:
10114
diff
changeset
|
114 |
9731
47121e8dc5b1
net.adns: Silence individual luacheck warnings instead of ignoring entire file
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
115 function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason |
10112
b327f2870382
net.*: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents:
9731
diff
changeset
|
116 log("warn", "Cancelling DNS lookup for %s", self[4]); |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
117 self[1].cancel(self[2], self[3], self[4], self[5], call_handler); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
118 end |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
119 |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
120 local function new_async_resolver() |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
121 local resolver = new_resolver(); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
122 resolver:socket_wrapper_set(new_async_socket); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
123 return setmetatable({ _resolver = resolver}, async_resolver_mt); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
124 end |
872 | 125 |
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6510
diff
changeset
|
126 return { |
8266
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
127 lookup = function (...) |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
128 return new_async_resolver():lookup(...); |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
129 end; |
9a97dd174ec9
net.adns: Restructure to allow creating separate resolver objects, like net.dns
Matthew Wild <mwild1@gmail.com>
parents:
7475
diff
changeset
|
130 resolver = new_async_resolver; |
6780
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6510
diff
changeset
|
131 new_async_socket = new_async_socket; |
647adfd8f738
net.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6510
diff
changeset
|
132 }; |