Skip to content
Snippets Groups Projects
Commit cc527cf0 authored by Mark D. Roth's avatar Mark D. Roth
Browse files

Provide a way to exit handshaking early without an error.

parent bc4403ad
No related branches found
No related tags found
No related merge requests found
...@@ -153,12 +153,21 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, ...@@ -153,12 +153,21 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
gpr_free(args->read_buffer); gpr_free(args->read_buffer);
} }
} else { } else {
grpc_transport *transport = if (args->endpoint != NULL) {
grpc_create_chttp2_transport(exec_ctx, args->args, args->endpoint, 0); grpc_transport *transport =
grpc_server_setup_transport( grpc_create_chttp2_transport(exec_ctx, args->args, args->endpoint, 0);
exec_ctx, connection_state->server_state->server, transport, grpc_server_setup_transport(
connection_state->accepting_pollset, args->args); exec_ctx, connection_state->server_state->server, transport,
grpc_chttp2_transport_start_reading(exec_ctx, transport, args->read_buffer); connection_state->accepting_pollset, args->args);
grpc_chttp2_transport_start_reading(exec_ctx, transport,
args->read_buffer);
} else {
// If the handshaking succeeded but there is no endpoint, then the
// handshaker may have handed off the connection to some external
// code, so we can just clean up here without creating a transport.
grpc_slice_buffer_destroy(args->read_buffer);
gpr_free(args->read_buffer);
}
grpc_channel_args_destroy(args->args); grpc_channel_args_destroy(args->args);
} }
pending_handshake_manager_remove_locked(connection_state->server_state, pending_handshake_manager_remove_locked(connection_state->server_state,
......
...@@ -157,10 +157,11 @@ static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx, ...@@ -157,10 +157,11 @@ static bool call_next_handshaker_locked(grpc_exec_ctx* exec_ctx,
grpc_handshake_manager* mgr, grpc_handshake_manager* mgr,
grpc_error* error) { grpc_error* error) {
GPR_ASSERT(mgr->index <= mgr->count); GPR_ASSERT(mgr->index <= mgr->count);
// If we got an error or we've been shut down or we've finished the last // If we got an error or we've been shut down or we're exiting early or
// handshaker, invoke the on_handshake_done callback. Otherwise, call the // we've finished the last handshaker, invoke the on_handshake_done
// next handshaker. // callback. Otherwise, call the next handshaker.
if (error != GRPC_ERROR_NONE || mgr->shutdown || mgr->index == mgr->count) { if (error != GRPC_ERROR_NONE || mgr->shutdown || mgr->args.exit_early ||
mgr->index == mgr->count) {
// Cancel deadline timer, since we're invoking the on_handshake_done // Cancel deadline timer, since we're invoking the on_handshake_done
// callback now. // callback now.
grpc_timer_cancel(exec_ctx, &mgr->deadline_timer); grpc_timer_cancel(exec_ctx, &mgr->deadline_timer);
......
...@@ -72,6 +72,9 @@ typedef struct { ...@@ -72,6 +72,9 @@ typedef struct {
grpc_endpoint* endpoint; grpc_endpoint* endpoint;
grpc_channel_args* args; grpc_channel_args* args;
grpc_slice_buffer* read_buffer; grpc_slice_buffer* read_buffer;
// A handshaker may set this to true before invoking on_handshake_done
// to indicate that subsequent handshakers should be skipped.
bool exit_early;
// User data passed through the handshake manager. Not used by // User data passed through the handshake manager. Not used by
// individual handshakers. // individual handshakers.
void* user_data; void* user_data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment