1 // Copyright 2022 The gRPC Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 #ifndef GRPC_SRC_CORE_LIB_IOMGR_EVENT_ENGINE_SHIMS_ENDPOINT_H 15 #define GRPC_SRC_CORE_LIB_IOMGR_EVENT_ENGINE_SHIMS_ENDPOINT_H 16 #include <grpc/event_engine/event_engine.h> 17 #include <grpc/support/port_platform.h> 18 19 #include <memory> 20 21 #include "src/core/lib/iomgr/endpoint.h" 22 23 namespace grpc_event_engine { 24 namespace experimental { 25 26 /// Creates an internal grpc_endpoint struct from an EventEngine Endpoint. 27 /// Server code needs to create grpc_endpoints after the EventEngine has made 28 /// connections. 29 grpc_endpoint* grpc_event_engine_endpoint_create( 30 std::unique_ptr<EventEngine::Endpoint> ee_endpoint); 31 32 /// Returns true if the passed endpoint is an event engine shim endpoint. 33 bool grpc_is_event_engine_endpoint(grpc_endpoint* ep); 34 35 /// Returns the wrapped event engine endpoint if the given grpc_endpoint is an 36 /// event engine shim endpoint. Otherwise it returns nullptr. 37 EventEngine::Endpoint* grpc_get_wrapped_event_engine_endpoint( 38 grpc_endpoint* ep); 39 40 /// Transfers ownership of the wrapped event engine endpoint if the given 41 /// grpc_endpoint is an event engine shim endpoint. Otherwise it returns 42 /// nullptr. If the passed ep wraps an event_engine endpoint, then after this 43 /// call, the memory location holding by the passed ep is free'ed. 44 /// Its safe to call this function only when there are no pending reads/writes 45 /// on the endpoint. 46 std::unique_ptr<EventEngine::Endpoint> grpc_take_wrapped_event_engine_endpoint( 47 grpc_endpoint* ep); 48 49 /// Destroys the passed in event engine shim endpoint and schedules the 50 /// asynchronous execution of the on_release_fd callback. The int pointer fd is 51 /// set to the underlying endpoint's file descriptor. 52 void grpc_event_engine_endpoint_destroy_and_release_fd( 53 grpc_endpoint* ep, int* fd, grpc_closure* on_release_fd); 54 55 } // namespace experimental 56 } // namespace grpc_event_engine 57 58 #endif // GRPC_SRC_CORE_LIB_IOMGR_EVENT_ENGINE_SHIMS_ENDPOINT_H 59