resolve_address.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
20 #define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
21 
23 
24 #include <stddef.h>
25 
26 #include "absl/status/statusor.h"
27 
29 
34 
35 #define GRPC_MAX_SOCKADDR_SIZE 128
36 
37 namespace grpc_core {
38 extern const char* kDefaultSecurePort;
39 constexpr int kDefaultSecurePortInt = 443;
40 
41 // A singleton class used for async and blocking DNS resolution
42 class DNSResolver {
43  public:
44  using TaskHandle = ::grpc_event_engine::experimental::EventEngine::
45  DNSResolver::LookupTaskHandle;
46  static constexpr TaskHandle kNullHandle{0, 0};
47 
48  virtual ~DNSResolver() {}
49 
51 
52  // Asynchronously resolve name. Use \a default_port if a port isn't designated
53  // in \a name, otherwise use the port in \a name. On completion, \a on_done is
54  // invoked with the result.
55  //
56  // Note for implementations: calls may acquire locks in \a on_done which
57  // were previously held while starting the request. Therefore,
58  // implementations must not invoke \a on_done inline from the call site that
59  // starts the request. The DNSCallbackExecCtxScheduler utility may help
60  // address this.
61  //
62  // \a interested_parties may be deleted after a request is cancelled.
63  virtual TaskHandle ResolveName(
65  grpc_pollset_set* interested_parties,
66  std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)>
67  on_done) = 0;
68 
69  // Resolve name in a blocking fashion. Use \a default_port if a port isn't
70  // designated in \a name, otherwise use the port in \a name.
73  absl::string_view default_port) = 0;
74 
75  // This shares the same semantics with \a EventEngine::Cancel: successfully
76  // cancelled lookups will not have their callbacks executed, and this
77  // method returns true. If a TaskHandle is unknown, this method should return
78  // false.
79  virtual bool Cancel(TaskHandle handle) = 0;
80 };
81 
82 // Override the active DNS resolver which should be used for all DNS
83 // resolution in gRPC. Note this should only be used during library
84 // initialization or within tests.
85 void SetDNSResolver(DNSResolver* resolver);
86 
87 // Get the singleton DNS resolver instance which should be used for all
88 // DNS resolution in gRPC.
89 DNSResolver* GetDNSResolver();
90 
91 } // namespace grpc_core
92 
93 #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */
grpc_core::kDefaultSecurePort
const char * kDefaultSecurePort
Definition: resolve_address.cc:28
orphanable.h
grpc_core
Definition: call_metric_recorder.h:31
event_engine.h
grpc_pollset_set
struct grpc_pollset_set grpc_pollset_set
Definition: iomgr_fwd.h:23
grpc_core::DNSResolver
Definition: resolve_address.h:42
absl::string_view
Definition: abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
setup.name
name
Definition: setup.py:542
resolved_address.h
grpc_core::DNSResolver::kNullHandle
static constexpr TaskHandle kNullHandle
Definition: resolve_address.h:46
grpc_core::DNSResolver::~DNSResolver
virtual ~DNSResolver()
Definition: resolve_address.h:48
pollset_set.h
grpc_event_engine::experimental::EventEngine::DNSResolver::LookupTaskHandle
Task handle for DNS Resolution requests.
Definition: event_engine.h:292
grpc_core::DNSResolver::TaskHandle
::grpc_event_engine::experimental::EventEngine::DNSResolver::LookupTaskHandle TaskHandle
Definition: resolve_address.h:45
grpc_core::GetDNSResolver
DNSResolver * GetDNSResolver()
Definition: resolve_address.cc:38
port.h
grpc_core::DNSResolver::ResolveName
virtual TaskHandle ResolveName(absl::string_view name, absl::string_view default_port, grpc_pollset_set *interested_parties, std::function< void(absl::StatusOr< std::vector< grpc_resolved_address >>)> on_done)=0
grpc_core::SetDNSResolver
void SetDNSResolver(DNSResolver *resolver)
Definition: resolve_address.cc:36
grpc_core::kDefaultSecurePortInt
constexpr int kDefaultSecurePortInt
Definition: resolve_address.h:39
grpc_core::DNSResolver::HandleToString
static std::string HandleToString(TaskHandle handle)
Definition: resolve_address.cc:40
grpc_core::DNSResolver::Cancel
virtual bool Cancel(TaskHandle handle)=0
handle
static csh handle
Definition: test_arm_regression.c:16
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
function
std::function< bool(GrpcTool *, int, const char **, const CliCredentials &, GrpcToolOutputCallback)> function
Definition: grpc_tool.cc:250
grpc_core::DNSResolver::ResolveNameBlocking
virtual absl::StatusOr< std::vector< grpc_resolved_address > > ResolveNameBlocking(absl::string_view name, absl::string_view default_port)=0
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:10