From 8ec7c988a3e56ebb596449d3e857fe7acb9990bd Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 29 Dec 2017 21:20:16 -0700 Subject: [PATCH] ircd::net: Add mass-resolution function. --- include/ircd/net/remote.h | 4 +++- ircd/net.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/ircd/net/remote.h b/include/ircd/net/remote.h index d9edd249c..996e58d71 100644 --- a/include/ircd/net/remote.h +++ b/include/ircd/net/remote.h @@ -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; @@ -109,6 +110,7 @@ struct ircd::net::resolve resolve(const hostport &, callback_many); resolve(const hostport &, ctx::future &); resolve(const hostport &, ctx::future> &); + resolve(const vector_view &in, const vector_view &out); }; /// This lightweight structure holds an IP address and port in native byte diff --git a/ircd/net.cc b/ircd/net.cc index 0065bcf6c..12a15eadc 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -1686,6 +1686,32 @@ ircd::net::resolve::resolve(const hostport &hostport, }); } +ircd::net::resolve::resolve(const vector_view &in, + const vector_view &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) {