| 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_CORE_LIB_TRANSPORT_TRANSPORT_H |
| 20 |
#define GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H |
| 21 |
|
| 22 |
#include <grpc/support/port_platform.h> |
| 23 |
|
| 24 |
#include <stddef.h> |
| 25 |
#include <stdint.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include <functional> |
| 29 |
#include <string> |
| 30 |
#include <utility> |
| 31 |
|
| 32 |
#include "absl/status/status.h" |
| 33 |
#include "absl/strings/string_view.h" |
| 34 |
#include "absl/types/optional.h" |
| 35 |
|
| 36 |
#include <grpc/impl/codegen/connectivity_state.h> |
| 37 |
#include <grpc/slice.h> |
| 38 |
#include <grpc/status.h> |
| 39 |
#include <grpc/support/atm.h> |
| 40 |
#include <grpc/support/log.h> |
| 41 |
|
| 42 |
#include "src/core/lib/channel/context.h" |
| 43 |
#include "src/core/lib/debug/trace.h" |
| 44 |
#include "src/core/lib/gprpp/debug_location.h" |
| 45 |
#include "src/core/lib/gprpp/orphanable.h" |
| 46 |
#include "src/core/lib/gprpp/ref_counted.h" |
| 47 |
#include "src/core/lib/iomgr/call_combiner.h" |
| 48 |
#include "src/core/lib/iomgr/closure.h" |
| 49 |
#include "src/core/lib/iomgr/endpoint.h" |
| 50 |
#include "src/core/lib/iomgr/error.h" |
| 51 |
#include "src/core/lib/iomgr/iomgr_fwd.h" |
| 52 |
#include "src/core/lib/iomgr/polling_entity.h" |
| 53 |
#include "src/core/lib/promise/arena_promise.h" |
| 54 |
#include "src/core/lib/promise/detail/status.h" |
| 55 |
#include "src/core/lib/promise/latch.h" |
| 56 |
#include "src/core/lib/promise/pipe.h" |
| 57 |
#include "src/core/lib/resource_quota/arena.h" |
| 58 |
#include "src/core/lib/slice/slice_buffer.h" |
| 59 |
#include "src/core/lib/transport/connectivity_state.h" |
| 60 |
#include "src/core/lib/transport/metadata_batch.h" |
| 61 |
#include "src/core/lib/transport/transport_fwd.h" |
| 62 |
|
| 63 |
/* Minimum and maximum protocol accepted versions. */ |
| 64 |
#define GRPC_PROTOCOL_VERSION_MAX_MAJOR 2 |
| 65 |
#define GRPC_PROTOCOL_VERSION_MAX_MINOR 1 |
| 66 |
#define GRPC_PROTOCOL_VERSION_MIN_MAJOR 2 |
| 67 |
#define GRPC_PROTOCOL_VERSION_MIN_MINOR 1 |
| 68 |
|
| 69 |
#define GRPC_ARG_TRANSPORT "grpc.internal.transport" |
| 70 |
|
| 71 |
/** Internal bit flag for grpc_begin_message's \a flags signaling the use of |
| 72 |
* compression for the message. (Does not apply for stream compression.) */ |
| 73 |
#define GRPC_WRITE_INTERNAL_COMPRESS (0x80000000u) |
| 74 |
/** Internal bit flag for determining whether the message was compressed and had |
| 75 |
* to be decompressed by the message_decompress filter. (Does not apply for |
| 76 |
* stream compression.) */ |
| 77 |
#define GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED (0x40000000u) |
| 78 |
/** Mask of all valid internal flags. */ |
| 79 |
#define GRPC_WRITE_INTERNAL_USED_MASK \ |
| 80 |
(GRPC_WRITE_INTERNAL_COMPRESS | GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED) |
| 81 |
|
| 82 |
namespace grpc_core { |
| 83 |
|
| 84 |
// Server metadata type |
| 85 |
// TODO(ctiller): This should be a bespoke instance of MetadataMap<> |
| 86 |
using ServerMetadata = grpc_metadata_batch; |
| 87 |
using ServerMetadataHandle = Arena::PoolPtr<ServerMetadata>; |
| 88 |
|
| 89 |
// Client initial metadata type |
| 90 |
// TODO(ctiller): This should be a bespoke instance of MetadataMap<> |
| 91 |
using ClientMetadata = grpc_metadata_batch; |
| 92 |
using ClientMetadataHandle = Arena::PoolPtr<ClientMetadata>; |
| 93 |
|
| 94 |
class Message { |
| 95 |
public: |
| 96 |
Message() = default; |
| 97 |
~Message() = default; |
| 98 |
Message(SliceBuffer payload, uint32_t flags) |
| 99 |
: payload_(std::move(payload)), flags_(flags) {} |
| 100 |
Message(const Message&) = delete; |
| 101 |
Message& operator=(const Message&) = delete; |
| 102 |
|
| 103 |
uint32_t flags() const { return flags_; } |
| 104 |
uint32_t& mutable_flags() { return flags_; } |
| 105 |
SliceBuffer* payload() { return &payload_; } |
| 106 |
const SliceBuffer* payload() const { return &payload_; } |
| 107 |
|
| 108 |
private: |
| 109 |
SliceBuffer payload_; |
| 110 |
uint32_t flags_ = 0; |
| 111 |
}; |
| 112 |
|
| 113 |
using MessageHandle = Arena::PoolPtr<Message>; |
| 114 |
|
| 115 |
// Ok/not-ok check for trailing metadata, so that it can be used as result types |
| 116 |
// for TrySeq. |
| 117 |
inline bool IsStatusOk(const ServerMetadataHandle& m) { |
| 118 |
return m->get(GrpcStatusMetadata()).value_or(GRPC_STATUS_UNKNOWN) == |
| 119 |
GRPC_STATUS_OK; |
| 120 |
} |
| 121 |
|
| 122 |
ServerMetadataHandle ServerMetadataFromStatus(const absl::Status& status); |
| 123 |
|
| 124 |
template <> |
| 125 |
struct StatusCastImpl<ServerMetadataHandle, absl::Status> { |
| 126 |
static ServerMetadataHandle Cast(const absl::Status& m) { |
| 127 |
return ServerMetadataFromStatus(m); |
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
template <> |
| 132 |
struct StatusCastImpl<ServerMetadataHandle, const absl::Status&> { |
| 133 |
static ServerMetadataHandle Cast(const absl::Status& m) { |
| 134 |
return ServerMetadataFromStatus(m); |
| 135 |
} |
| 136 |
}; |
| 137 |
|
| 138 |
struct CallArgs { |
| 139 |
// Initial metadata from the client to the server. |
| 140 |
// During promise setup this can be manipulated by filters (and then |
| 141 |
// passed on to the next filter). |
| 142 |
ClientMetadataHandle client_initial_metadata; |
| 143 |
// Initial metadata from the server to the client. |
| 144 |
// Set once when it's available. |
| 145 |
// During promise setup filters can substitute their own latch for this |
| 146 |
// and consequently intercept the sent value and mutate/observe it. |
| 147 |
Latch<ServerMetadata*>* server_initial_metadata; |
| 148 |
// Messages travelling from the application to the transport. |
| 149 |
PipeReceiver<MessageHandle>* outgoing_messages; |
| 150 |
// Messages travelling from the transport to the application. |
| 151 |
PipeSender<MessageHandle>* incoming_messages; |
| 152 |
}; |
| 153 |
|
| 154 |
using NextPromiseFactory = |
| 155 |
std::function<ArenaPromise<ServerMetadataHandle>(CallArgs)>; |
| 156 |
|
| 157 |
} // namespace grpc_core |
| 158 |
|
| 159 |
/* forward declarations */ |
| 160 |
|
| 161 |
/* grpc_stream doesn't actually exist. It's used as a typesafe |
| 162 |
opaque pointer for whatever data the transport wants to track |
| 163 |
for a stream. */ |
| 164 |
typedef struct grpc_stream grpc_stream; |
| 165 |
|
| 166 |
extern grpc_core::DebugOnlyTraceFlag grpc_trace_stream_refcount; |
| 167 |
|
| 168 |
typedef struct grpc_stream_refcount { |
| 169 |
grpc_core::RefCount refs; |
| 170 |
grpc_closure destroy; |
| 171 |
#ifndef NDEBUG |
| 172 |
const char* object_type; |
| 173 |
#endif |
| 174 |
} grpc_stream_refcount; |
| 175 |
|
| 176 |
#ifndef NDEBUG |
| 177 |
void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, |
| 178 |
grpc_iomgr_cb_func cb, void* cb_arg, |
| 179 |
const char* object_type); |
| 180 |
#define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ |
| 181 |
grpc_stream_ref_init(rc, ir, cb, cb_arg, objtype) |
| 182 |
#else |
| 183 |
void grpc_stream_ref_init(grpc_stream_refcount* refcount, int initial_refs, |
| 184 |
grpc_iomgr_cb_func cb, void* cb_arg); |
| 185 |
#define GRPC_STREAM_REF_INIT(rc, ir, cb, cb_arg, objtype) \ |
| 186 |
do { \ |
| 187 |
grpc_stream_ref_init(rc, ir, cb, cb_arg); \ |
| 188 |
(void)(objtype); \ |
| 189 |
} while (0) |
| 190 |
#endif |
| 191 |
|
| 192 |
#ifndef NDEBUG |
| 193 |
inline void grpc_stream_ref(grpc_stream_refcount* refcount, |
| 194 |
const char* reason) { |
| 195 |
if (grpc_trace_stream_refcount.enabled()) { |
| 196 |
gpr_log(GPR_DEBUG, "%s %p:%p REF %s", refcount->object_type, refcount, |
| 197 |
refcount->destroy.cb_arg, reason); |
| 198 |
} |
| 199 |
refcount->refs.RefNonZero(DEBUG_LOCATION, reason); |
| 200 |
} |
| 201 |
#else |
| 202 |
inline void grpc_stream_ref(grpc_stream_refcount* refcount) { |
| 203 |
refcount->refs.RefNonZero(); |
| 204 |
} |
| 205 |
#endif |
| 206 |
|
| 207 |
void grpc_stream_destroy(grpc_stream_refcount* refcount); |
| 208 |
|
| 209 |
#ifndef NDEBUG |
| 210 |
inline void grpc_stream_unref(grpc_stream_refcount* refcount, |
| 211 |
const char* reason) { |
| 212 |
if (grpc_trace_stream_refcount.enabled()) { |
| 213 |
gpr_log(GPR_DEBUG, "%s %p:%p UNREF %s", refcount->object_type, refcount, |
| 214 |
refcount->destroy.cb_arg, reason); |
| 215 |
} |
| 216 |
if (GPR_UNLIKELY(refcount->refs.Unref(DEBUG_LOCATION, reason))) { |
| 217 |
grpc_stream_destroy(refcount); |
| 218 |
} |
| 219 |
} |
| 220 |
#else |
| 221 |
inline void grpc_stream_unref(grpc_stream_refcount* refcount) { |
| 222 |
if (GPR_UNLIKELY(refcount->refs.Unref())) { |
| 223 |
grpc_stream_destroy(refcount); |
| 224 |
} |
| 225 |
} |
| 226 |
#endif |
| 227 |
|
| 228 |
/* Wrap a buffer that is owned by some stream object into a slice that shares |
| 229 |
the same refcount */ |
| 230 |
grpc_slice grpc_slice_from_stream_owned_buffer(grpc_stream_refcount* refcount, |
| 231 |
void* buffer, size_t length); |
| 232 |
|
| 233 |
struct grpc_transport_one_way_stats { |
| 234 |
uint64_t framing_bytes = 0; |
| 235 |
uint64_t data_bytes = 0; |
| 236 |
uint64_t header_bytes = 0; |
| 237 |
}; |
| 238 |
|
| 239 |
struct grpc_transport_stream_stats { |
| 240 |
grpc_transport_one_way_stats incoming; |
| 241 |
grpc_transport_one_way_stats outgoing; |
| 242 |
}; |
| 243 |
|
| 244 |
void grpc_transport_move_one_way_stats(grpc_transport_one_way_stats* from, |
| 245 |
grpc_transport_one_way_stats* to); |
| 246 |
|
| 247 |
void grpc_transport_move_stats(grpc_transport_stream_stats* from, |
| 248 |
grpc_transport_stream_stats* to); |
| 249 |
|
| 250 |
// This struct (which is present in both grpc_transport_stream_op_batch |
| 251 |
// and grpc_transport_op_batch) is a convenience to allow filters or |
| 252 |
// transports to schedule a closure related to a particular batch without |
| 253 |
// having to allocate memory. The general pattern is to initialize the |
| 254 |
// closure with the callback arg set to the batch and extra_arg set to |
| 255 |
// whatever state is associated with the handler (e.g., the call element |
| 256 |
// or the transport stream object). |
| 257 |
// |
| 258 |
// Note that this can only be used by the current handler of a given |
| 259 |
// batch on the way down the stack (i.e., whichever filter or transport is |
| 260 |
// currently handling the batch). Once a filter or transport passes control |
| 261 |
// of the batch to the next handler, it cannot depend on the contents of |
| 262 |
// this struct anymore, because the next handler may reuse it. |
| 263 |
struct grpc_handler_private_op_data { |
| 264 |
void* extra_arg = nullptr; |
| 265 |
grpc_closure closure; |
| 266 |
grpc_handler_private_op_data() { memset(&closure, 0, sizeof(closure)); } |
| 267 |
}; |
| 268 |
|
| 269 |
typedef struct grpc_transport_stream_op_batch_payload |
| 270 |
grpc_transport_stream_op_batch_payload; |
| 271 |
|
| 272 |
/* Transport stream op: a set of operations to perform on a transport |
| 273 |
against a single stream */ |
| 274 |
struct grpc_transport_stream_op_batch { |
| 275 |
grpc_transport_stream_op_batch() |
| 276 |
: send_initial_metadata(false), |
| 277 |
send_trailing_metadata(false), |
| 278 |
send_message(false), |
| 279 |
recv_initial_metadata(false), |
| 280 |
recv_message(false), |
| 281 |
recv_trailing_metadata(false), |
| 282 |
cancel_stream(false), |
| 283 |
is_traced(false) {} |
| 284 |
|
| 285 |
/** Should be scheduled when all of the non-recv operations in the batch |
| 286 |
are complete. |
| 287 |
|
| 288 |
The recv ops (recv_initial_metadata, recv_message, and |
| 289 |
recv_trailing_metadata) each have their own callbacks. If a batch |
| 290 |
contains both recv ops and non-recv ops, on_complete should be |
| 291 |
scheduled as soon as the non-recv ops are complete, regardless of |
| 292 |
whether or not the recv ops are complete. If a batch contains |
| 293 |
only recv ops, on_complete can be null. */ |
| 294 |
grpc_closure* on_complete = nullptr; |
| 295 |
|
| 296 |
/** Values for the stream op (fields set are determined by flags above) */ |
| 297 |
grpc_transport_stream_op_batch_payload* payload = nullptr; |
| 298 |
|
| 299 |
/** Send initial metadata to the peer, from the provided metadata batch. */ |
| 300 |
bool send_initial_metadata : 1; |
| 301 |
|
| 302 |
/** Send trailing metadata to the peer, from the provided metadata batch. */ |
| 303 |
bool send_trailing_metadata : 1; |
| 304 |
|
| 305 |
/** Send message data to the peer, from the provided byte stream. */ |
| 306 |
bool send_message : 1; |
| 307 |
|
| 308 |
/** Receive initial metadata from the stream, into provided metadata batch. */ |
| 309 |
bool recv_initial_metadata : 1; |
| 310 |
|
| 311 |
/** Receive message data from the stream, into provided byte stream. */ |
| 312 |
bool recv_message : 1; |
| 313 |
|
| 314 |
/** Receive trailing metadata from the stream, into provided metadata batch. |
| 315 |
*/ |
| 316 |
bool recv_trailing_metadata : 1; |
| 317 |
|
| 318 |
/** Cancel this stream with the provided error */ |
| 319 |
bool cancel_stream : 1; |
| 320 |
|
| 321 |
/** Is this stream traced */ |
| 322 |
bool is_traced : 1; |
| 323 |
|
| 324 |
/*************************************************************************** |
| 325 |
* remaining fields are initialized and used at the discretion of the |
| 326 |
* current handler of the op */ |
| 327 |
|
| 328 |
grpc_handler_private_op_data handler_private; |
| 329 |
}; |
| 330 |
|
| 331 |
struct grpc_transport_stream_op_batch_payload { |
| 332 |
explicit grpc_transport_stream_op_batch_payload( |
| 333 |
grpc_call_context_element* context) |
| 334 |
: context(context) {} |
| 335 |
struct { |
| 336 |
grpc_metadata_batch* send_initial_metadata = nullptr; |
| 337 |
// If non-NULL, will be set by the transport to the peer string (a char*). |
| 338 |
// The transport retains ownership of the string. |
| 339 |
// Note: This pointer may be used by the transport after the |
| 340 |
// send_initial_metadata op is completed. It must remain valid |
| 341 |
// until the call is destroyed. |
| 342 |
gpr_atm* peer_string = nullptr; |
| 343 |
} send_initial_metadata; |
| 344 |
|
| 345 |
struct { |
| 346 |
grpc_metadata_batch* send_trailing_metadata = nullptr; |
| 347 |
// Set by the transport to true if the stream successfully wrote the |
| 348 |
// trailing metadata. If this is not set but there was a send trailing |
| 349 |
// metadata op present, this can indicate that a server call can be marked |
| 350 |
// as a cancellation (since the stream was write-closed before status could |
| 351 |
// be delivered). |
| 352 |
bool* sent = nullptr; |
| 353 |
} send_trailing_metadata; |
| 354 |
|
| 355 |
struct { |
| 356 |
// The transport (or a filter that decides to return a failure before |
| 357 |
// the op gets down to the transport) takes ownership. |
| 358 |
// The batch's on_complete will not be called until after the byte |
| 359 |
// stream is orphaned. |
| 360 |
grpc_core::SliceBuffer* send_message; |
| 361 |
uint32_t flags = 0; |
| 362 |
// Set by the transport if the stream has been closed for writes. If this |
| 363 |
// is set and send message op is present, we set the operation to be a |
| 364 |
// failure without sending a cancel OP down the stack. This is so that the |
| 365 |
// status of the call does not get overwritten by the Cancel OP, which would |
| 366 |
// be especially problematic if we had received a valid status from the |
| 367 |
// server. |
| 368 |
// For send_initial_metadata, it is fine for the status to be overwritten |
| 369 |
// because at that point, the client will not have received a status. |
| 370 |
// For send_trailing_metadata, we might overwrite the status if we have |
| 371 |
// non-zero metadata to send. This is fine because the API does not allow |
| 372 |
// the client to send trailing metadata. |
| 373 |
bool stream_write_closed = false; |
| 374 |
} send_message; |
| 375 |
|
| 376 |
struct { |
| 377 |
grpc_metadata_batch* recv_initial_metadata = nullptr; |
| 378 |
/** Should be enqueued when initial metadata is ready to be processed. */ |
| 379 |
grpc_closure* recv_initial_metadata_ready = nullptr; |
| 380 |
// If not NULL, will be set to true if trailing metadata is |
| 381 |
// immediately available. This may be a signal that we received a |
| 382 |
// Trailers-Only response. The retry filter checks this to know whether to |
| 383 |
// defer the decision to commit the call or not. The C++ callback API also |
| 384 |
// uses this to set the success flag of OnReadInitialMetadataDone() |
| 385 |
// callback. |
| 386 |
bool* trailing_metadata_available = nullptr; |
| 387 |
// If non-NULL, will be set by the transport to the peer string (a char*). |
| 388 |
// The transport retains ownership of the string. |
| 389 |
// Note: This pointer may be used by the transport after the |
| 390 |
// recv_initial_metadata op is completed. It must remain valid |
| 391 |
// until the call is destroyed. |
| 392 |
gpr_atm* peer_string = nullptr; |
| 393 |
} recv_initial_metadata; |
| 394 |
|
| 395 |
struct { |
| 396 |
// Will be set by the transport to point to the byte stream containing a |
| 397 |
// received message. Will be nullopt if trailing metadata is received |
| 398 |
// instead of a message. |
| 399 |
absl::optional<grpc_core::SliceBuffer>* recv_message = nullptr; |
| 400 |
uint32_t* flags = nullptr; |
| 401 |
// Was this recv_message failed for reasons other than a clean end-of-stream |
| 402 |
bool* call_failed_before_recv_message = nullptr; |
| 403 |
/** Should be enqueued when one message is ready to be processed. */ |
| 404 |
grpc_closure* recv_message_ready = nullptr; |
| 405 |
} recv_message; |
| 406 |
|
| 407 |
struct { |
| 408 |
grpc_metadata_batch* recv_trailing_metadata = nullptr; |
| 409 |
grpc_transport_stream_stats* collect_stats = nullptr; |
| 410 |
/** Should be enqueued when trailing metadata is ready to be processed. */ |
| 411 |
grpc_closure* recv_trailing_metadata_ready = nullptr; |
| 412 |
} recv_trailing_metadata; |
| 413 |
|
| 414 |
/** Forcefully close this stream. |
| 415 |
The HTTP2 semantics should be: |
| 416 |
- server side: if cancel_error has |
| 417 |
grpc_core::StatusIntProperty::kRpcStatus, and trailing metadata has not |
| 418 |
been sent, send trailing metadata with status and message from cancel_error |
| 419 |
(use grpc_error_get_status) followed by a RST_STREAM with |
| 420 |
error=GRPC_CHTTP2_NO_ERROR to force a full close |
| 421 |
- at all other times: use grpc_error_get_status to get a status code, and |
| 422 |
convert to a HTTP2 error code using |
| 423 |
grpc_chttp2_grpc_status_to_http2_error. Send a RST_STREAM with this |
| 424 |
error. */ |
| 425 |
struct { |
| 426 |
// Error contract: the transport that gets this op must cause cancel_error |
| 427 |
// to be unref'ed after processing it |
| 428 |
grpc_error_handle cancel_error; |
| 429 |
} cancel_stream; |
| 430 |
|
| 431 |
/* Indexes correspond to grpc_context_index enum values */ |
| 432 |
grpc_call_context_element* context; |
| 433 |
}; |
| 434 |
|
| 435 |
/** Transport op: a set of operations to perform on a transport as a whole */ |
| 436 |
typedef struct grpc_transport_op { |
| 437 |
/** Called when processing of this op is done. */ |
| 438 |
grpc_closure* on_consumed = nullptr; |
| 439 |
/** connectivity monitoring - set connectivity_state to NULL to unsubscribe */ |
| 440 |
grpc_core::OrphanablePtr<grpc_core::ConnectivityStateWatcherInterface> |
| 441 |
start_connectivity_watch; |
| 442 |
grpc_connectivity_state start_connectivity_watch_state = GRPC_CHANNEL_IDLE; |
| 443 |
grpc_core::ConnectivityStateWatcherInterface* stop_connectivity_watch = |
| 444 |
nullptr; |
| 445 |
/** should the transport be disconnected |
| 446 |
* Error contract: the transport that gets this op must cause |
| 447 |
* disconnect_with_error to be unref'ed after processing it */ |
| 448 |
grpc_error_handle disconnect_with_error; |
| 449 |
/** what should the goaway contain? |
| 450 |
* Error contract: the transport that gets this op must cause |
| 451 |
* goaway_error to be unref'ed after processing it */ |
| 452 |
grpc_error_handle goaway_error; |
| 453 |
/** set the callback for accepting new streams; |
| 454 |
this is a permanent callback, unlike the other one-shot closures. |
| 455 |
If true, the callback is set to set_accept_stream_fn, with its |
| 456 |
user_data argument set to set_accept_stream_user_data */ |
| 457 |
bool set_accept_stream = false; |
| 458 |
void (*set_accept_stream_fn)(void* user_data, grpc_transport* transport, |
| 459 |
const void* server_data) = nullptr; |
| 460 |
void* set_accept_stream_user_data = nullptr; |
| 461 |
/** set the callback for accepting new streams based upon promises; |
| 462 |
this is a permanent callback, unlike the other one-shot closures. |
| 463 |
If true, the callback is set to set_make_promise_fn, with its |
| 464 |
user_data argument set to set_make_promise_data */ |
| 465 |
bool set_make_promise = false; |
| 466 |
void (*set_make_promise_fn)(void* user_data, grpc_transport* transport, |
| 467 |
const void* server_data) = nullptr; |
| 468 |
void* set_make_promise_user_data = nullptr; |
| 469 |
/** add this transport to a pollset */ |
| 470 |
grpc_pollset* bind_pollset = nullptr; |
| 471 |
/** add this transport to a pollset_set */ |
| 472 |
grpc_pollset_set* bind_pollset_set = nullptr; |
| 473 |
/** send a ping, if either on_initiate or on_ack is not NULL */ |
| 474 |
struct { |
| 475 |
/** Ping may be delayed by the transport, on_initiate callback will be |
| 476 |
called when the ping is actually being sent. */ |
| 477 |
grpc_closure* on_initiate = nullptr; |
| 478 |
/** Called when the ping ack is received */ |
| 479 |
grpc_closure* on_ack = nullptr; |
| 480 |
} send_ping; |
| 481 |
// If true, will reset the channel's connection backoff. |
| 482 |
bool reset_connect_backoff = false; |
| 483 |
|
| 484 |
/*************************************************************************** |
| 485 |
* remaining fields are initialized and used at the discretion of the |
| 486 |
* transport implementation */ |
| 487 |
|
| 488 |
grpc_handler_private_op_data handler_private; |
| 489 |
} grpc_transport_op; |
| 490 |
|
| 491 |
/* Returns the amount of memory required to store a grpc_stream for this |
| 492 |
transport */ |
| 493 |
size_t grpc_transport_stream_size(grpc_transport* transport); |
| 494 |
|
| 495 |
/* Initialize transport data for a stream. |
| 496 |
|
| 497 |
Returns 0 on success, any other (transport-defined) value for failure. |
| 498 |
May assume that stream contains all-zeros. |
| 499 |
|
| 500 |
Arguments: |
| 501 |
transport - the transport on which to create this stream |
| 502 |
stream - a pointer to uninitialized memory to initialize |
| 503 |
server_data - either NULL for a client initiated stream, or a pointer |
| 504 |
supplied from the accept_stream callback function */ |
| 505 |
int grpc_transport_init_stream(grpc_transport* transport, grpc_stream* stream, |
| 506 |
grpc_stream_refcount* refcount, |
| 507 |
const void* server_data, |
| 508 |
grpc_core::Arena* arena); |
| 509 |
|
| 510 |
void grpc_transport_set_pops(grpc_transport* transport, grpc_stream* stream, |
| 511 |
grpc_polling_entity* pollent); |
| 512 |
|
| 513 |
/* Destroy transport data for a stream. |
| 514 |
|
| 515 |
Requires: a recv_batch with final_state == GRPC_STREAM_CLOSED has been |
| 516 |
received by the up-layer. Must not be called in the same call stack as |
| 517 |
recv_frame. |
| 518 |
|
| 519 |
Arguments: |
| 520 |
transport - the transport on which to create this stream |
| 521 |
stream - the grpc_stream to destroy (memory is still owned by the |
| 522 |
caller, but any child memory must be cleaned up) */ |
| 523 |
void grpc_transport_destroy_stream(grpc_transport* transport, |
| 524 |
grpc_stream* stream, |
| 525 |
grpc_closure* then_schedule_closure); |
| 526 |
|
| 527 |
void grpc_transport_stream_op_batch_finish_with_failure( |
| 528 |
grpc_transport_stream_op_batch* batch, grpc_error_handle error, |
| 529 |
grpc_core::CallCombiner* call_combiner); |
| 530 |
void grpc_transport_stream_op_batch_queue_finish_with_failure( |
| 531 |
grpc_transport_stream_op_batch* batch, grpc_error_handle error, |
| 532 |
grpc_core::CallCombinerClosureList* closures); |
| 533 |
// Fail a batch from within the transport (i.e. without the activity lock/call |
| 534 |
// combiner taken). |
| 535 |
void grpc_transport_stream_op_batch_finish_with_failure_from_transport( |
| 536 |
grpc_transport_stream_op_batch* batch, grpc_error_handle error); |
| 537 |
|
| 538 |
std::string grpc_transport_stream_op_batch_string( |
| 539 |
grpc_transport_stream_op_batch* op); |
| 540 |
std::string grpc_transport_op_string(grpc_transport_op* op); |
| 541 |
|
| 542 |
/* Send a batch of operations on a transport |
| 543 |
|
| 544 |
Takes ownership of any objects contained in ops. |
| 545 |
|
| 546 |
Arguments: |
| 547 |
transport - the transport on which to initiate the stream |
| 548 |
stream - the stream on which to send the operations. This must be |
| 549 |
non-NULL and previously initialized by the same transport. |
| 550 |
op - a grpc_transport_stream_op_batch specifying the op to perform |
| 551 |
*/ |
| 552 |
void grpc_transport_perform_stream_op(grpc_transport* transport, |
| 553 |
grpc_stream* stream, |
| 554 |
grpc_transport_stream_op_batch* op); |
| 555 |
|
| 556 |
void grpc_transport_perform_op(grpc_transport* transport, |
| 557 |
grpc_transport_op* op); |
| 558 |
|
| 559 |
/* Send a ping on a transport |
| 560 |
|
| 561 |
Calls cb with user data when a response is received. */ |
| 562 |
void grpc_transport_ping(grpc_transport* transport, grpc_closure* cb); |
| 563 |
|
| 564 |
/* Advise peer of pending connection termination. */ |
| 565 |
void grpc_transport_goaway(grpc_transport* transport, grpc_status_code status, |
| 566 |
grpc_slice debug_data); |
| 567 |
|
| 568 |
/* Destroy the transport */ |
| 569 |
void grpc_transport_destroy(grpc_transport* transport); |
| 570 |
|
| 571 |
/* Get the endpoint used by \a transport */ |
| 572 |
grpc_endpoint* grpc_transport_get_endpoint(grpc_transport* transport); |
| 573 |
|
| 574 |
/* Allocate a grpc_transport_op, and preconfigure the on_complete closure to |
| 575 |
\a on_complete and then delete the returned transport op */ |
| 576 |
grpc_transport_op* grpc_make_transport_op(grpc_closure* on_complete); |
| 577 |
/* Allocate a grpc_transport_stream_op_batch, and preconfigure the on_complete |
| 578 |
closure |
| 579 |
to \a on_complete and then delete the returned transport op */ |
| 580 |
grpc_transport_stream_op_batch* grpc_make_transport_stream_op( |
| 581 |
grpc_closure* on_complete); |
| 582 |
|
| 583 |
namespace grpc_core { |
| 584 |
// This is the key to be used for loading/storing keepalive_throttling in the |
| 585 |
// absl::Status object. |
| 586 |
constexpr const char* kKeepaliveThrottlingKey = |
| 587 |
"grpc.internal.keepalive_throttling"; |
| 588 |
} // namespace grpc_core |
| 589 |
|
| 590 |
#endif /* GRPC_CORE_LIB_TRANSPORT_TRANSPORT_H */ |