1 // 2 // Copyright 2015 gRPC authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H 18 #define GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include "src/core/lib/channel/channel_args.h" 23 #include "src/core/lib/channel/channelz.h" 24 #include "src/core/lib/gprpp/orphanable.h" 25 #include "src/core/lib/gprpp/ref_counted_ptr.h" 26 #include "src/core/lib/gprpp/time.h" 27 #include "src/core/lib/iomgr/closure.h" 28 #include "src/core/lib/iomgr/error.h" 29 #include "src/core/lib/iomgr/iomgr_fwd.h" 30 #include "src/core/lib/iomgr/resolved_address.h" 31 #include "src/core/lib/transport/transport.h" 32 #include "src/core/lib/transport/transport_fwd.h" 33 34 namespace grpc_core { 35 36 // Interface for connection-establishment functionality. 37 // Each transport that supports client channels (e.g., not inproc) must 38 // supply an implementation of this. 39 class SubchannelConnector : public InternallyRefCounted<SubchannelConnector> { 40 public: 41 struct Args { 42 // Address to connect to. 43 grpc_resolved_address* address; 44 // Set of pollsets interested in this connection. 45 grpc_pollset_set* interested_parties; 46 // Deadline for connection. 47 Timestamp deadline; 48 // Channel args to be passed to handshakers and transport. 49 ChannelArgs channel_args; 50 }; 51 52 struct Result { 53 // The connected transport. 54 grpc_transport* transport = nullptr; 55 // Channel args to be passed to filters. 56 ChannelArgs channel_args; 57 // Channelz socket node of the connected transport, if any. 58 RefCountedPtr<channelz::SocketNode> socket_node; 59 ResetResult60 void Reset() { 61 if (transport != nullptr) { 62 grpc_transport_destroy(transport); 63 transport = nullptr; 64 } 65 channel_args = ChannelArgs(); 66 socket_node.reset(); 67 } 68 }; 69 70 // Attempts to connect. 71 // When complete, populates *result and invokes notify. 72 // Only one connection attempt may be in progress at any one time. 73 virtual void Connect(const Args& args, Result* result, 74 grpc_closure* notify) = 0; 75 76 // Cancels any in-flight connection attempt and shuts down the 77 // connector. 78 virtual void Shutdown(grpc_error_handle error) = 0; 79 Orphan()80 void Orphan() override { 81 Shutdown(GRPC_ERROR_CREATE("Subchannel disconnected")); 82 Unref(); 83 } 84 }; 85 86 } // namespace grpc_core 87 88 #endif // GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CONNECTOR_H 89