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