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_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H 20 #define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <grpc/slice.h> 25 26 #include "src/core/lib/channel/channel_args.h" 27 #include "src/core/lib/channel/channelz.h" 28 #include "src/core/lib/debug/trace.h" 29 #include "src/core/lib/gprpp/ref_counted_ptr.h" 30 #include "src/core/lib/iomgr/buffer_list.h" 31 #include "src/core/lib/iomgr/closure.h" 32 #include "src/core/lib/iomgr/endpoint.h" 33 #include "src/core/lib/iomgr/error.h" 34 #include "src/core/lib/transport/transport_fwd.h" 35 36 extern grpc_core::TraceFlag grpc_keepalive_trace; 37 extern grpc_core::TraceFlag grpc_trace_http2_stream_state; 38 extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount; 39 extern grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_hpack_parser; 40 41 /// Creates a CHTTP2 Transport. This takes ownership of a \a resource_user ref 42 /// from the caller; if the caller still needs the resource_user after creating 43 /// a transport, the caller must take another ref. 44 grpc_transport* grpc_create_chttp2_transport( 45 const grpc_core::ChannelArgs& channel_args, grpc_endpoint* ep, 46 bool is_client); 47 48 grpc_core::RefCountedPtr<grpc_core::channelz::SocketNode> 49 grpc_chttp2_transport_get_socket_node(grpc_transport* transport); 50 51 /// Takes ownership of \a read_buffer, which (if non-NULL) contains 52 /// leftover bytes previously read from the endpoint (e.g., by handshakers). 53 /// If non-null, \a notify_on_receive_settings will be scheduled when 54 /// HTTP/2 settings are received from the peer. 55 void grpc_chttp2_transport_start_reading( 56 grpc_transport* transport, grpc_slice_buffer* read_buffer, 57 grpc_closure* notify_on_receive_settings, grpc_closure* notify_on_close); 58 59 namespace grpc_core { 60 typedef void (*TestOnlyGlobalHttp2TransportInitCallback)(); 61 typedef void (*TestOnlyGlobalHttp2TransportDestructCallback)(); 62 63 void TestOnlySetGlobalHttp2TransportInitCallback( 64 TestOnlyGlobalHttp2TransportInitCallback callback); 65 66 void TestOnlySetGlobalHttp2TransportDestructCallback( 67 TestOnlyGlobalHttp2TransportDestructCallback callback); 68 69 // If \a disable is true, the HTTP2 transport will not update the connectivity 70 // state tracker to TRANSIENT_FAILURE when a goaway is received. This prevents 71 // the watchers (eg. client_channel) from noticing the GOAWAY, thereby allowing 72 // us to test the racy behavior when a call is sent down the stack around the 73 // same time that a GOAWAY is received. 74 void TestOnlyGlobalHttp2TransportDisableTransientFailureStateNotification( 75 bool disable); 76 77 typedef void (*WriteTimestampsCallback)(void*, Timestamps*, 78 grpc_error_handle error); 79 typedef void* (*CopyContextFn)(void*); 80 81 void GrpcHttp2SetWriteTimestampsCallback(WriteTimestampsCallback fn); 82 void GrpcHttp2SetCopyContextFn(CopyContextFn fn); 83 84 WriteTimestampsCallback GrpcHttp2GetWriteTimestampsCallback(); 85 CopyContextFn GrpcHttp2GetCopyContextFn(); 86 87 // Interprets the passed arg as a ContextList type and for each entry in the 88 // passed ContextList, it executes the function set using 89 // GrpcHttp2SetWriteTimestampsCallback method with each context in the list 90 // and \a ts. It also deletes/frees up the passed ContextList after this 91 // operation. 92 void ForEachContextListEntryExecute(void* arg, Timestamps* ts, 93 grpc_error_handle error); 94 95 } // namespace grpc_core 96 97 #endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H 98