GRPC Core  9.0.0
grpc_ares_ev_driver.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_EV_DRIVER_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
21 
23 
24 #include <ares.h>
27 
29 
30 /* Start \a ev_driver. It will keep working until all IO on its ares_channel is
31  done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks
32  bound to its ares_channel when necessary. */
34 
35 /* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to
36  \a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the
37  query. */
39  grpc_ares_ev_driver* ev_driver);
40 
41 /* Creates a new grpc_ares_ev_driver. Returns GRPC_ERROR_NONE if \a ev_driver is
42  created successfully. */
44  grpc_pollset_set* pollset_set,
45  int query_timeout_ms,
46  grpc_core::Combiner* combiner,
47  grpc_ares_request* request);
48 
49 /* Called back when all DNS lookups have completed. */
51  grpc_ares_ev_driver* ev_driver);
52 
53 /* Shutdown all the grpc_fds used by \a ev_driver */
55 
56 /* Exposed in this header for C-core tests only */
57 extern void (*grpc_ares_test_only_inject_config)(ares_channel channel);
58 
59 namespace grpc_core {
60 
61 /* A wrapped fd that integrates with the grpc iomgr of the current platform.
62  * A GrpcPolledFd knows how to create grpc platform-specific iomgr endpoints
63  * from "ares_socket_t" sockets, and then sign up for readability/writeability
64  * with that poller, and do shutdown and destruction. */
65 class GrpcPolledFd {
66  public:
67  virtual ~GrpcPolledFd() {}
68  /* Called when c-ares library is interested and there's no pending callback */
69  virtual void RegisterForOnReadableLocked(grpc_closure* read_closure) = 0;
70  /* Called when c-ares library is interested and there's no pending callback */
71  virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure) = 0;
72  /* Indicates if there is data left even after just being read from */
73  virtual bool IsFdStillReadableLocked() = 0;
74  /* Called once and only once. Must cause cancellation of any pending
75  * read/write callbacks. */
76  virtual void ShutdownLocked(grpc_error* error) = 0;
77  /* Get the underlying ares_socket_t that this was created from */
78  virtual ares_socket_t GetWrappedAresSocketLocked() = 0;
79  /* A unique name, for logging */
80  virtual const char* GetName() = 0;
81 };
82 
83 /* A GrpcPolledFdFactory is 1-to-1 with and owned by the
84  * ares event driver. It knows how to create GrpcPolledFd's
85  * for the current platform, and the ares driver uses it for all of
86  * its fd's. */
88  public:
89  virtual ~GrpcPolledFdFactory() {}
90  /* Creates a new wrapped fd for the current platform */
92  ares_socket_t as, grpc_pollset_set* driver_pollset_set,
93  Combiner* combiner) = 0;
94  /* Optionally configures the ares channel after creation */
95  virtual void ConfigureAresChannelLocked(ares_channel channel) = 0;
96 };
97 
98 std::unique_ptr<GrpcPolledFdFactory> NewGrpcPolledFdFactory(Combiner* combiner);
99 
100 } // namespace grpc_core
101 
102 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \
103  */
void(* grpc_ares_test_only_inject_config)(ares_channel channel)
virtual void RegisterForOnReadableLocked(grpc_closure *read_closure)=0
virtual ares_socket_t GetWrappedAresSocketLocked()=0
struct grpc_ares_ev_driver grpc_ares_ev_driver
Definition: grpc_ares_ev_driver.h:28
virtual ~GrpcPolledFd()
Definition: grpc_ares_ev_driver.h:67
Definition: error_internal.h:39
virtual GrpcPolledFd * NewGrpcPolledFdLocked(ares_socket_t as, grpc_pollset_set *driver_pollset_set, Combiner *combiner)=0
grpc_error * grpc_ares_ev_driver_create_locked(grpc_ares_ev_driver **ev_driver, grpc_pollset_set *pollset_set, int query_timeout_ms, grpc_core::Combiner *combiner, grpc_ares_request *request)
void grpc_ares_ev_driver_shutdown_locked(grpc_ares_ev_driver *ev_driver)
Round Robin Policy.
Definition: backend_metric.cc:24
Definition: combiner.h:33
Definition: grpc_ares_ev_driver.h:87
void grpc_ares_ev_driver_on_queries_complete_locked(grpc_ares_ev_driver *ev_driver)
std::unique_ptr< GrpcPolledFdFactory > NewGrpcPolledFdFactory(Combiner *combiner)
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
virtual ~GrpcPolledFdFactory()
Definition: grpc_ares_ev_driver.h:89
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
virtual void ConfigureAresChannelLocked(ares_channel channel)=0
virtual void ShutdownLocked(grpc_error *error)=0
Definition: grpc_ares_wrapper_fallback.cc:25
ares_channel * grpc_ares_ev_driver_get_channel_locked(grpc_ares_ev_driver *ev_driver)
Definition: grpc_ares_ev_driver.h:65
virtual const char * GetName()=0
void grpc_ares_ev_driver_start_locked(grpc_ares_ev_driver *ev_driver)
virtual void RegisterForOnWriteableLocked(grpc_closure *write_closure)=0
virtual bool IsFdStillReadableLocked()=0