Annotate

net/resolvers/chain.lua @ 12479:4d36fbcdd210 0.12

core.moduleapi: Fix 'global' property via :context() - #1748 The 'global' property should reflect whether the module API instance represents the global context or a VirtualHost or Component context. However the module:context() method did not override this, leading the property of the previous module shining trough, leading to bugs in code relying on the 'global' property. See also #1736
author Kim Alvefur <zash@zash.se>
date Wed, 27 Apr 2022 17:18:46 +0200
parent 12204:7c397a49d163
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12204
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local methods = {};
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local resolver_mt = { __index = methods };
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- Find the next target to connect to, and
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- pass it to cb()
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 function methods:next(cb)
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 if self.resolvers then
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 if not self.resolver then
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 if #self.resolvers == 0 then
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 cb(nil);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 return;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local next_resolver = table.remove(self.resolvers, 1);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 self.resolver = next_resolver;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 self.resolver:next(function (...)
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 if self.resolver then
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 self.last_error = self.resolver.last_error;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 if ... == nil then
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 self.resolver = nil;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 self:next(cb);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 else
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 cb(...);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 return;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 local function new(resolvers)
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 return setmetatable({ resolvers = resolvers }, resolver_mt);
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 return {
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 new = new;
7c397a49d163 net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 };