0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-30 20:58:51 +02:00

ircd::net: Add mass-resolution function.

This commit is contained in:
Jason Volk 2017-12-29 21:20:16 -07:00
parent 0eb16673ee
commit 8ec7c988a3
2 changed files with 29 additions and 1 deletions

View file

@ -98,8 +98,9 @@ struct ircd::net::hostport
friend std::ostream &operator<<(std::ostream &, const hostport &);
};
/// DNS resolution section
/// DNS resolution suite.
///
/// There are plenty of ways to resolve plenty of things. Still more to come.
struct ircd::net::resolve
{
using callback_one = std::function<void (std::exception_ptr, const ipport &)>;
@ -109,6 +110,7 @@ struct ircd::net::resolve
resolve(const hostport &, callback_many);
resolve(const hostport &, ctx::future<ipport> &);
resolve(const hostport &, ctx::future<std::vector<ipport>> &);
resolve(const vector_view<hostport> &in, const vector_view<ipport> &out);
};
/// This lightweight structure holds an IP address and port in native byte

View file

@ -1686,6 +1686,32 @@ ircd::net::resolve::resolve(const hostport &hostport,
});
}
ircd::net::resolve::resolve(const vector_view<hostport> &in,
const vector_view<ipport> &out)
{
assert(in.size() == out.size());
const size_t count
{
std::min(in.size(), out.size())
};
size_t a{0}, b{0};
ctx::ctx &c{ctx::cur()};
for(; a < count; ++a) resolve
{
in[a], [&b, &c, &count, &ret(out[a])]
(std::exception_ptr eptr, const ipport &ip) noexcept
{
ret = ip;
if(++b >= count)
notify(c);
}
};
while(b < count)
ctx::wait();
}
ircd::net::resolve::resolve(const hostport &hostport,
callback_many callback)
{