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_TRANSPORT_TRANSPORT_IMPL_H 20 #define GRPC_SRC_CORE_LIB_TRANSPORT_TRANSPORT_IMPL_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <stddef.h> 25 26 #include "absl/strings/string_view.h" 27 28 #include "src/core/lib/iomgr/closure.h" 29 #include "src/core/lib/iomgr/endpoint.h" 30 #include "src/core/lib/iomgr/iomgr_fwd.h" 31 #include "src/core/lib/promise/arena_promise.h" 32 #include "src/core/lib/resource_quota/arena.h" 33 #include "src/core/lib/transport/transport.h" 34 #include "src/core/lib/transport/transport_fwd.h" 35 36 typedef struct grpc_transport_vtable { 37 // Memory required for a single stream element - this is allocated by upper 38 // layers and initialized by the transport 39 size_t sizeof_stream; // = sizeof(transport stream) 40 41 // HACK: inproc does not handle stream op batch callbacks correctly (receive 42 // ops are required to complete prior to on_complete triggering). 43 // This flag is used to disable coalescing of batches in connected_channel for 44 // that specific transport. 45 // TODO(ctiller): This ought not be necessary once we have promises complete. 46 bool hacky_disable_stream_op_batch_coalescing_in_connected_channel; 47 48 // name of this transport implementation 49 const char* name; 50 51 // implementation of grpc_transport_init_stream 52 int (*init_stream)(grpc_transport* self, grpc_stream* stream, 53 grpc_stream_refcount* refcount, const void* server_data, 54 grpc_core::Arena* arena); 55 56 // Create a promise to execute one client call. 57 // If this is non-null, it may be used in preference to 58 // perform_stream_op. 59 // If this is used in preference to perform_stream_op, the 60 // following can be omitted also: 61 // - calling init_stream, destroy_stream, set_pollset, set_pollset_set 62 // - allocation of memory for call data (sizeof_stream may be ignored) 63 // There is an on-going migration to move all filters to providing this, and 64 // then to drop perform_stream_op. 65 grpc_core::ArenaPromise<grpc_core::ServerMetadataHandle> (*make_call_promise)( 66 grpc_transport* self, grpc_core::CallArgs call_args); 67 68 // implementation of grpc_transport_set_pollset 69 void (*set_pollset)(grpc_transport* self, grpc_stream* stream, 70 grpc_pollset* pollset); 71 72 // implementation of grpc_transport_set_pollset 73 void (*set_pollset_set)(grpc_transport* self, grpc_stream* stream, 74 grpc_pollset_set* pollset_set); 75 76 // implementation of grpc_transport_perform_stream_op 77 void (*perform_stream_op)(grpc_transport* self, grpc_stream* stream, 78 grpc_transport_stream_op_batch* op); 79 80 // implementation of grpc_transport_perform_op 81 void (*perform_op)(grpc_transport* self, grpc_transport_op* op); 82 83 // implementation of grpc_transport_destroy_stream 84 void (*destroy_stream)(grpc_transport* self, grpc_stream* stream, 85 grpc_closure* then_schedule_closure); 86 87 // implementation of grpc_transport_destroy 88 void (*destroy)(grpc_transport* self); 89 90 // implementation of grpc_transport_get_endpoint 91 grpc_endpoint* (*get_endpoint)(grpc_transport* self); 92 } grpc_transport_vtable; 93 94 // an instance of a grpc transport 95 struct grpc_transport { 96 struct RawPointerChannelArgTag {}; ChannelArgNamegrpc_transport97 static absl::string_view ChannelArgName() { return GRPC_ARG_TRANSPORT; } 98 // pointer to a vtable defining operations on this transport 99 const grpc_transport_vtable* vtable; 100 }; 101 102 #endif // GRPC_SRC_CORE_LIB_TRANSPORT_TRANSPORT_IMPL_H 103