GRPC C++  1.39.1
grpc_ares_wrapper.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H
21 
23 
24 #include <ares.h>
25 
31 
32 #define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS 120000
33 
35 
37 
38 #define GRPC_CARES_TRACE_LOG(format, ...) \
39  do { \
40  if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_resolver)) { \
41  gpr_log(GPR_DEBUG, "(c-ares resolver) " format, __VA_ARGS__); \
42  } \
43  } while (0)
44 
46 
47 /* Asynchronously resolve \a name. Use \a default_port if a port isn't
48  designated in \a name, otherwise use the port in \a name. grpc_ares_init()
49  must be called at least once before this function. \a on_done may be
50  called directly in this function without being scheduled with \a exec_ctx,
51  so it must not try to acquire locks that are being held by the caller. */
52 extern void (*grpc_resolve_address_ares)(const char* name,
53  const char* default_port,
54  grpc_pollset_set* interested_parties,
55  grpc_closure* on_done,
56  grpc_resolved_addresses** addresses);
57 
58 /* Asynchronously resolve \a name. It will try to resolve grpclb SRV records in
59  addition to the normal address records. For normal address records, it uses
60  \a default_port if a port isn't designated in \a name, otherwise it uses the
61  port in \a name. grpc_ares_init() must be called at least once before this
62  function. \a on_done may be called directly in this function without being
63  scheduled with \a exec_ctx, so it must not try to acquire locks that are
64  being held by the caller. The returned grpc_ares_request object is owned
65  by the caller and it is safe to free after on_done is called back. */
66 extern grpc_ares_request* (*grpc_dns_lookup_ares_locked)(
67  const char* dns_server, const char* name, const char* default_port,
68  grpc_pollset_set* interested_parties, grpc_closure* on_done,
69  std::unique_ptr<grpc_core::ServerAddressList>* addresses,
70  std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses,
71  char** service_config_json, int query_timeout_ms,
72  std::shared_ptr<grpc_core::WorkSerializer> work_serializer);
73 
74 /* Cancel the pending grpc_ares_request \a request */
75 extern void (*grpc_cancel_ares_request_locked)(grpc_ares_request* request);
76 
77 /* Initialize gRPC ares wrapper. Must be called at least once before
78  grpc_resolve_address_ares(). */
80 
81 /* Uninitialized gRPC ares wrapper. If there was more than one previous call to
82  grpc_ares_init(), this function uninitializes the gRPC ares wrapper only if
83  it has been called the same number of times as grpc_ares_init(). */
84 void grpc_ares_cleanup(void);
85 
89 
90 /* Indicates whether or not AAAA queries should be attempted. */
91 /* E.g., return false if ipv6 is known to not be available. */
93 
94 /* Sorts destinations in lb_addrs according to RFC 6724. */
96  const grpc_ares_request* request, grpc_core::ServerAddressList* addresses);
97 
98 /* Exposed in this header for C-core tests only */
99 extern void (*grpc_ares_test_only_inject_config)(ares_channel channel);
100 
101 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H \
102  */
Definition: trace.h:61
void(* grpc_cancel_ares_request_locked)(grpc_ares_request *request)
bool grpc_ares_query_ipv6()
void grpc_cares_wrapper_address_sorting_sort(const grpc_ares_request *request, grpc_core::ServerAddressList *addresses)
void(* grpc_resolve_address_ares)(const char *name, const char *default_port, grpc_pollset_set *interested_parties, grpc_closure *on_done, grpc_resolved_addresses **addresses)
grpc_error_handle grpc_ares_init(void)
void(* grpc_ares_test_only_inject_config)(ares_channel channel)
grpc_core::TraceFlag grpc_trace_cares_resolver
grpc_core::TraceFlag grpc_trace_cares_address_sorting
struct grpc_ares_request grpc_ares_request
Definition: grpc_ares_wrapper.h:45
void grpc_ares_cleanup(void)
void grpc_ares_complete_request_locked(grpc_ares_request *request)
Schedules the desired callback for request completion and destroys the grpc_ares_request.
absl::InlinedVector< ServerAddress, 1 > ServerAddressList
Definition: server_address.h:111
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
Definition: error_internal.h:41
Definition: resolve_address.h:48