mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::net::dns: Deduplicate requests at resolve() entry.
This commit is contained in:
parent
47204888d6
commit
83c58cf42e
1 changed files with 18 additions and 3 deletions
|
@ -108,21 +108,36 @@ ircd::net::dns::resolve(const hostport &hp,
|
|||
const opts &opts,
|
||||
callback cb)
|
||||
{
|
||||
assert(ctx::current);
|
||||
if(unlikely(!opts.qtype))
|
||||
throw error
|
||||
{
|
||||
"A query type is required; not specified; cannot be deduced here."
|
||||
};
|
||||
|
||||
if(opts.cache_check)
|
||||
// Try to satisfy from the cache first. This requires a ctx.
|
||||
if(likely(ctx::current && opts.cache_check))
|
||||
if(cache::get(hp, opts, cb))
|
||||
return;
|
||||
|
||||
// Remote query will be made; register this callback as waiting for reply
|
||||
if(cb)
|
||||
cache::waiting.emplace_back(hp, opts, std::move(cb));
|
||||
|
||||
resolver_call(hp, opts);
|
||||
// Check if there is already someone else waiting on the same query
|
||||
const auto count
|
||||
{
|
||||
!cb? 1: std::count_if(begin(cache::waiting), end(cache::waiting), []
|
||||
(const auto &a)
|
||||
{
|
||||
const auto &b(cache::waiting.back());
|
||||
return a.opts.qtype == b.opts.qtype && a.key != b.key;
|
||||
})
|
||||
};
|
||||
|
||||
// When nobody else is already waiting on this query we have to submit it.
|
||||
assert(count >= 1);
|
||||
if(count == 1)
|
||||
resolver_call(hp, opts);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue