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_SRC_CORE_LIB_IOMGR_TCP_CLIENT_H 20 #define GRPC_SRC_CORE_LIB_IOMGR_TCP_CLIENT_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <grpc/event_engine/endpoint_config.h> 25 #include <grpc/impl/grpc_types.h> 26 #include <grpc/support/time.h> 27 28 #include "src/core/lib/iomgr/endpoint.h" 29 #include "src/core/lib/iomgr/pollset_set.h" 30 #include "src/core/lib/iomgr/resolve_address.h" 31 #include "src/core/lib/resource_quota/memory_quota.h" 32 33 typedef struct grpc_tcp_client_vtable { 34 int64_t (*connect)( 35 grpc_closure* on_connect, grpc_endpoint** endpoint, 36 grpc_pollset_set* interested_parties, 37 const grpc_event_engine::experimental::EndpointConfig& config, 38 const grpc_resolved_address* addr, grpc_core::Timestamp deadline); 39 bool (*cancel_connect)(int64_t connection_handle); 40 } grpc_tcp_client_vtable; 41 42 // Asynchronously connect to an address (specified as (addr, len)), and call 43 // cb with arg and the completed connection when done (or call cb with arg and 44 // NULL on failure). 45 // interested_parties points to a set of pollsets that would be interested 46 // in this connection being established (in order to continue their work). It 47 // returns a handle to the connect operation which can be used to cancel the 48 // connection attempt. 49 int64_t grpc_tcp_client_connect( 50 grpc_closure* on_connect, grpc_endpoint** endpoint, 51 grpc_pollset_set* interested_parties, 52 const grpc_event_engine::experimental::EndpointConfig& config, 53 const grpc_resolved_address* addr, grpc_core::Timestamp deadline); 54 55 // Returns true if a connect attempt corresponding to the provided handle 56 // is successfully cancelled. Otherwise it returns false. If the connect 57 // attempt is successfully cancelled, then the on_connect closure passed to 58 // grpc_tcp_client_connect will not be executed. Its upto the caller to free 59 // up any resources that may have been allocated to create the closure. 60 bool grpc_tcp_client_cancel_connect(int64_t connection_handle); 61 62 extern void grpc_tcp_client_global_init(); 63 64 void grpc_set_tcp_client_impl(grpc_tcp_client_vtable* impl); 65 66 #endif // GRPC_SRC_CORE_LIB_IOMGR_TCP_CLIENT_H 67