mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 05:07:42 +03:00
net.resolvers.chain: A resolver for combining other resolvers
Say if you wanted to try both _xmpp and _xmpps services
This commit is contained in:
parent
991e6531ab
commit
f31762a075
1 changed files with 38 additions and 0 deletions
38
net/resolvers/chain.lua
Normal file
38
net/resolvers/chain.lua
Normal file
|
@ -0,0 +1,38 @@
|
|||
|
||||
local methods = {};
|
||||
local resolver_mt = { __index = methods };
|
||||
|
||||
-- Find the next target to connect to, and
|
||||
-- pass it to cb()
|
||||
function methods:next(cb)
|
||||
if self.resolvers then
|
||||
if not self.resolver then
|
||||
if #self.resolvers == 0 then
|
||||
cb(nil);
|
||||
return;
|
||||
end
|
||||
local next_resolver = table.remove(self.resolvers, 1);
|
||||
self.resolver = next_resolver;
|
||||
end
|
||||
self.resolver:next(function (...)
|
||||
if self.resolver then
|
||||
self.last_error = self.resolver.last_error;
|
||||
end
|
||||
if ... == nil then
|
||||
self.resolver = nil;
|
||||
self:next(cb);
|
||||
else
|
||||
cb(...);
|
||||
end
|
||||
end);
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
local function new(resolvers)
|
||||
return setmetatable({ resolvers = resolvers }, resolver_mt);
|
||||
end
|
||||
|
||||
return {
|
||||
new = new;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue