[event_engine] Move DNS resolution executor usage to event engine (#31230)

* [event_engine] Move DNS resolution executor usage to event engine

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/31301/head
Craig Tiller 2 years ago committed by GitHub
parent c59211166d
commit 8ed649f576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      src/core/lib/iomgr/resolve_address_posix.cc

@ -47,35 +47,22 @@
namespace grpc_core { namespace grpc_core {
namespace { namespace {
class NativeDNSRequest { void NativeDNSRequest(
public: std::string name, std::string default_port,
NativeDNSRequest( std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)>
absl::string_view name, absl::string_view default_port, on_done) {
std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)> grpc_event_engine::experimental::GetDefaultEventEngine()->Run(
on_done) [name = std::move(name), default_port = std::move(default_port),
: name_(name), default_port_(default_port), on_done_(std::move(on_done)) { on_done = std::move(on_done)]() mutable {
GRPC_CLOSURE_INIT(&request_closure_, DoRequestThread, this, nullptr); ApplicationCallbackExecCtx callback_exec_ctx;
Executor::Run(&request_closure_, absl::OkStatus(), ExecutorType::RESOLVER); ExecCtx exec_ctx;
} auto result =
GetDNSResolver()->LookupHostnameBlocking(name, default_port);
private: // running inline is safe since we've already been scheduled on the
// Callback to be passed to grpc Executor to asynch-ify // executor
// LookupHostnameBlocking on_done(std::move(result));
static void DoRequestThread(void* rp, grpc_error_handle /*error*/) { });
NativeDNSRequest* r = static_cast<NativeDNSRequest*>(rp); }
auto result =
GetDNSResolver()->LookupHostnameBlocking(r->name_, r->default_port_);
// running inline is safe since we've already been scheduled on the executor
r->on_done_(std::move(result));
delete r;
}
const std::string name_;
const std::string default_port_;
const std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)>
on_done_;
grpc_closure request_closure_;
};
} // namespace } // namespace
@ -85,8 +72,8 @@ DNSResolver::TaskHandle NativeDNSResolver::LookupHostname(
absl::string_view name, absl::string_view default_port, absl::string_view name, absl::string_view default_port,
Duration /* timeout */, grpc_pollset_set* /* interested_parties */, Duration /* timeout */, grpc_pollset_set* /* interested_parties */,
absl::string_view /* name_server */) { absl::string_view /* name_server */) {
// self-deleting class NativeDNSRequest(std::string(name), std::string(default_port),
new NativeDNSRequest(name, default_port, std::move(on_done)); std::move(on_done));
return kNullHandle; return kNullHandle;
} }

Loading…
Cancel
Save