GRPC Core  9.0.0
connector.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_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H
21 
23 
29 
30 namespace grpc_core {
31 
32 // Interface for connection-establishment functionality.
33 // Each transport that supports client channels (e.g., not inproc) must
34 // supply an implementation of this.
35 class SubchannelConnector : public InternallyRefCounted<SubchannelConnector> {
36  public:
37  struct Args {
38  // Set of pollsets interested in this connection.
40  // Deadline for connection.
42  // Channel args to be passed to handshakers and transport.
44  };
45 
46  struct Result {
47  // The connected transport.
49  // Channel args to be passed to filters.
50  const grpc_channel_args* channel_args = nullptr;
51  // Channelz socket node of the connected transport, if any.
53 
54  void Reset() {
55  transport = nullptr;
56  channel_args = nullptr;
57  socket_node.reset();
58  }
59  };
60 
61  // Attempts to connect.
62  // When complete, populates *result and invokes notify.
63  // Only one connection attempt may be in progress at any one time.
64  virtual void Connect(const Args& args, Result* result,
65  grpc_closure* notify) = 0;
66 
67  // Cancels any in-flight connection attempt and shuts down the
68  // connector.
69  virtual void Shutdown(grpc_error* error) = 0;
70 
71  void Orphan() override {
72  Shutdown(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Subchannel disconnected"));
73  Unref();
74  }
75 };
76 
77 } // namespace grpc_core
78 
79 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H */
int64_t grpc_millis
Definition: exec_ctx.h:35
An array of arguments that can be passed around.
Definition: grpc_types.h:132
virtual void Shutdown(grpc_error *error)=0
grpc_transport * transport
Definition: connector.h:48
virtual void Connect(const Args &args, Result *result, grpc_closure *notify)=0
const grpc_channel_args * channel_args
Definition: connector.h:50
Definition: error_internal.h:39
Definition: orphanable.h:77
Round Robin Policy.
Definition: backend_metric.cc:24
RefCountedPtr< channelz::SocketNode > socket_node
Definition: connector.h:52
const grpc_channel_args * channel_args
Definition: connector.h:43
Definition: connector.h:35
void Orphan() override
Definition: connector.h:71
Definition: ref_counted_ptr.h:35
struct grpc_pollset_set grpc_pollset_set
Definition: pollset_set.h:31
A closure over a grpc_iomgr_cb_func.
Definition: closure.h:56
void Reset()
Definition: connector.h:54
Definition: connector.h:46
#define GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc)
Create an error (this is the preferred way of generating an error that is not due to a system call - ...
Definition: error.h:155
Definition: connector.h:37
grpc_pollset_set * interested_parties
Definition: connector.h:39
Definition: transport_impl.h:66
grpc_millis deadline
Definition: connector.h:41