Software /
code /
prosody
Comparison
net/unbound.lua @ 10967:67aabf83230b
net.unbound: Strip support for legacy net.server APIs
These are not needed since the watchfd API is provided by all net.server
backends.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Jun 2020 17:56:48 +0200 |
parent | 10962:92f30e8ecdfc |
child | 10968:23ae55cbbeaf |
comparison
equal
deleted
inserted
replaced
10966:97de279ca01a | 10967:67aabf83230b |
---|---|
10 local t_concat = table.concat; | 10 local t_concat = table.concat; |
11 local s_format = string.format; | 11 local s_format = string.format; |
12 local s_lower = string.lower; | 12 local s_lower = string.lower; |
13 local s_upper = string.upper; | 13 local s_upper = string.upper; |
14 local noop = function() end; | 14 local noop = function() end; |
15 local zero = function() return 0 end; | |
16 local truop = function() return true; end; | |
17 | 15 |
18 local log = require "util.logger".init("unbound"); | 16 local log = require "util.logger".init("unbound"); |
19 local net_server = require "net.server"; | 17 local net_server = require "net.server"; |
20 local libunbound = require"lunbound"; | 18 local libunbound = require"lunbound"; |
21 local have_promise, promise = pcall(require, "util.promise"); | 19 local have_promise, promise = pcall(require, "util.promise"); |
45 end); | 43 end); |
46 end | 44 end |
47 -- Note: libunbound will default to using root hints if resolvconf is unset | 45 -- Note: libunbound will default to using root hints if resolvconf is unset |
48 | 46 |
49 local function connect_server(unbound, server) | 47 local function connect_server(unbound, server) |
50 if server.watchfd then | 48 return server.watchfd(unbound, function () |
51 return server.watchfd(unbound, function () | 49 unbound:process() |
52 unbound:process() | 50 end); |
53 end); | |
54 elseif server.event and server.addevent then | |
55 local EV_READ = server.event.EV_READ; | |
56 local function event_callback() | |
57 unbound:process(); | |
58 return EV_READ; | |
59 end | |
60 return server.addevent(unbound:getfd(), EV_READ, event_callback) | |
61 elseif server.wrapclient then | |
62 local conn = { | |
63 getfd = function() | |
64 return unbound:getfd(); | |
65 end, | |
66 | |
67 send = zero, | |
68 receive = noop, | |
69 settimeout = noop, | |
70 close = truop, | |
71 } | |
72 | |
73 local function process() | |
74 unbound:process(); | |
75 end | |
76 local listener = { | |
77 onincoming = process, | |
78 | |
79 onconnect = noop, | |
80 ondisconnect = noop, | |
81 onreadtimeout = truop, | |
82 }; | |
83 return server.wrapclient(conn, "dns", 0, listener, "*a" ); | |
84 end | |
85 end | 51 end |
86 | 52 |
87 local unbound = libunbound.new(unbound_config); | 53 local unbound = libunbound.new(unbound_config); |
88 | 54 |
89 local server_conn = connect_server(unbound, net_server); | 55 local server_conn = connect_server(unbound, net_server); |