GRPC C++  1.39.1
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 
28 namespace grpc_core {
29 
30 /* A wrapped fd that integrates with the grpc iomgr of the current platform.
31  * A GrpcPolledFd knows how to create grpc platform-specific iomgr endpoints
32  * from "ares_socket_t" sockets, and then sign up for readability/writeability
33  * with that poller, and do shutdown and destruction. */
34 class GrpcPolledFd {
35  public:
36  virtual ~GrpcPolledFd() {}
37  /* Called when c-ares library is interested and there's no pending callback */
38  virtual void RegisterForOnReadableLocked(grpc_closure* read_closure) = 0;
39  /* Called when c-ares library is interested and there's no pending callback */
40  virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure) = 0;
41  /* Indicates if there is data left even after just being read from */
42  virtual bool IsFdStillReadableLocked() = 0;
43  /* Called once and only once. Must cause cancellation of any pending
44  * read/write callbacks. */
46  /* Get the underlying ares_socket_t that this was created from */
47  virtual ares_socket_t GetWrappedAresSocketLocked() = 0;
48  /* A unique name, for logging */
49  virtual const char* GetName() = 0;
50 };
51 
52 /* A GrpcPolledFdFactory is 1-to-1 with and owned by the
53  * ares event driver. It knows how to create GrpcPolledFd's
54  * for the current platform, and the ares driver uses it for all of
55  * its fd's. */
57  public:
58  virtual ~GrpcPolledFdFactory() {}
59  /* Creates a new wrapped fd for the current platform */
61  ares_socket_t as, grpc_pollset_set* driver_pollset_set,
62  std::shared_ptr<grpc_core::WorkSerializer> work_serializer) = 0;
63  /* Optionally configures the ares channel after creation */
64  virtual void ConfigureAresChannelLocked(ares_channel channel) = 0;
65 };
66 
67 std::unique_ptr<GrpcPolledFdFactory> NewGrpcPolledFdFactory(
68  std::shared_ptr<grpc_core::WorkSerializer> work_serializer);
69 
70 } // namespace grpc_core
71 
72 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \
73  */
Definition: grpc_ares_ev_driver.h:56
virtual GrpcPolledFd * NewGrpcPolledFdLocked(ares_socket_t as, grpc_pollset_set *driver_pollset_set, std::shared_ptr< grpc_core::WorkSerializer > work_serializer)=0
virtual ~GrpcPolledFdFactory()
Definition: grpc_ares_ev_driver.h:58
virtual void ConfigureAresChannelLocked(ares_channel channel)=0
Definition: grpc_ares_ev_driver.h:34
virtual void RegisterForOnWriteableLocked(grpc_closure *write_closure)=0
virtual const char * GetName()=0
virtual bool IsFdStillReadableLocked()=0
virtual void ShutdownLocked(grpc_error_handle error)=0
virtual ~GrpcPolledFd()
Definition: grpc_ares_ev_driver.h:36
virtual ares_socket_t GetWrappedAresSocketLocked()=0
virtual void RegisterForOnReadableLocked(grpc_closure *read_closure)=0
grpc_error_handle error
Definition: lame_client.cc:54
Round Robin Policy.
Definition: backend_metric.cc:26
std::unique_ptr< GrpcPolledFdFactory > NewGrpcPolledFdFactory(std::shared_ptr< grpc_core::WorkSerializer > work_serializer)
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