From 5682a52cee47d6bbdd71bf1426cd603b306cc2b7 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 20 Jul 2016 09:54:41 -0700 Subject: [PATCH] Add acceptor parameter. --- .../chttp2/client/insecure/channel_create.c | 2 +- .../chttp2/client/secure/secure_channel_create.c | 4 ++-- .../chttp2/server/insecure/server_chttp2.c | 3 ++- .../chttp2/server/secure/server_secure_chttp2.c | 2 +- src/core/lib/channel/handshaker.c | 13 +++++++++---- src/core/lib/channel/handshaker.h | 12 +++++++++--- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c index 162cc6bd6ab..645a011748d 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c @@ -116,7 +116,7 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { } else { grpc_handshake_manager_do_handshake( exec_ctx, c->handshake_mgr, tcp, c->args.channel_args, - c->args.deadline, on_handshake_done, c); + c->args.deadline, NULL /* acceptor */, on_handshake_done, c); } } else { memset(c->result, 0, sizeof(*c->result)); diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c index dde35f253dd..01d949add3a 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c @@ -142,7 +142,7 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg, connector *c = arg; grpc_handshake_manager_do_handshake( exec_ctx, c->handshake_mgr, c->connecting_endpoint, c->args.channel_args, - c->args.deadline, on_handshake_done, c); + c->args.deadline, NULL /* acceptor */, on_handshake_done, c); } static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { @@ -164,7 +164,7 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { } else { grpc_handshake_manager_do_handshake( exec_ctx, c->handshake_mgr, tcp, c->args.channel_args, - c->args.deadline, on_handshake_done, c); + c->args.deadline, NULL /* acceptor */, on_handshake_done, c); } } else { memset(c->result, 0, sizeof(*c->result)); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c index b8d816c1279..8dac63c33bc 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c @@ -90,7 +90,8 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *server, grpc_endpoint *tcp, gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(120, GPR_TIMESPAN)); grpc_handshake_manager_do_handshake(exec_ctx, state->handshake_mgr, tcp, grpc_server_get_channel_args(server), - deadline, on_handshake_done, state); + deadline, acceptor, on_handshake_done, + state); } /* Server callback: start listening on our ports */ diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c index bc714f4e5bc..2b25fa09e64 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c @@ -158,7 +158,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *statep, grpc_endpoint *tcp, grpc_handshake_manager_do_handshake( exec_ctx, state->handshake_mgr, tcp, grpc_server_get_channel_args(state->state->server), state->deadline, - on_handshake_done, state); + acceptor, on_handshake_done, state); } /* Server callback: start listening on our ports */ diff --git a/src/core/lib/channel/handshaker.c b/src/core/lib/channel/handshaker.c index 9191ae63395..9db04440ee8 100644 --- a/src/core/lib/channel/handshaker.c +++ b/src/core/lib/channel/handshaker.c @@ -63,9 +63,10 @@ void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, grpc_endpoint* endpoint, grpc_channel_args* args, gpr_timespec deadline, + grpc_tcp_server_acceptor *acceptor, grpc_handshaker_done_cb cb, void* user_data) { handshaker->vtable->do_handshake(exec_ctx, handshaker, endpoint, args, - deadline, cb, user_data); + deadline, acceptor, cb, user_data); } // @@ -78,6 +79,8 @@ struct grpc_handshaker_state { size_t index; // The deadline for all handshakers. gpr_timespec deadline; + // The acceptor to call the handshakers with. + grpc_tcp_server_acceptor *acceptor; // The final callback and user_data to invoke after the last handshaker. grpc_handshaker_done_cb final_cb; void* final_user_data; @@ -142,8 +145,8 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx, } // Invoke handshaker. grpc_handshaker_do_handshake(exec_ctx, mgr->handshakers[mgr->state->index], - endpoint, args, mgr->state->deadline, cb, - user_data); + endpoint, args, mgr->state->deadline, + mgr->state->acceptor, cb, user_data); ++mgr->state->index; // If this is the last handshaker, clean up state. if (mgr->state->index == mgr->count) { @@ -155,7 +158,8 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx, void grpc_handshake_manager_do_handshake( grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, grpc_endpoint* endpoint, const grpc_channel_args* args, - gpr_timespec deadline, grpc_handshaker_done_cb cb, void* user_data) { + gpr_timespec deadline, grpc_tcp_server_acceptor *acceptor, + grpc_handshaker_done_cb cb, void* user_data) { grpc_channel_args* args_copy = grpc_channel_args_copy(args); if (mgr->count == 0) { // No handshakers registered, so we just immediately call the done @@ -166,6 +170,7 @@ void grpc_handshake_manager_do_handshake( mgr->state = gpr_malloc(sizeof(struct grpc_handshaker_state)); memset(mgr->state, 0, sizeof(*mgr->state)); mgr->state->deadline = deadline; + mgr->state->acceptor = acceptor; mgr->state->final_cb = cb; mgr->state->final_user_data = user_data; call_next_handshaker(exec_ctx, endpoint, args_copy, mgr); diff --git a/src/core/lib/channel/handshaker.h b/src/core/lib/channel/handshaker.h index b8aa78c2454..b1e91dba4f2 100644 --- a/src/core/lib/channel/handshaker.h +++ b/src/core/lib/channel/handshaker.h @@ -40,6 +40,7 @@ #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/tcp_server.h" /// Handshakers are used to perform initial handshakes on a connection /// before the client sends the initial request. Some examples of what @@ -71,10 +72,12 @@ struct grpc_handshaker_vtable { /// Performs handshaking. When finished, calls \a cb with \a user_data. /// Takes ownership of \a args. + /// \a acceptor will be NULL for client-side handshakers. void (*do_handshake)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker, grpc_endpoint* endpoint, grpc_channel_args* args, - gpr_timespec deadline, grpc_handshaker_done_cb cb, - void* user_data); + gpr_timespec deadline, + grpc_tcp_server_acceptor* acceptor, + grpc_handshaker_done_cb cb, void* user_data); }; /// Base struct. To subclass, make this the first member of the @@ -99,6 +102,7 @@ void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx, grpc_endpoint* endpoint, grpc_channel_args* args, gpr_timespec deadline, + grpc_tcp_server_acceptor* acceptor, grpc_handshaker_done_cb cb, void* user_data); /// @@ -129,11 +133,13 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx, /// Invokes handshakers in the order they were added. /// Does NOT take ownership of \a args. Instead, makes a copy before /// invoking the first handshaker. +/// \a acceptor will be NULL for client-side handshakers. /// If successful, invokes \a cb with \a user_data after all handshakers /// have completed. void grpc_handshake_manager_do_handshake( grpc_exec_ctx* exec_ctx, grpc_handshake_manager* mgr, grpc_endpoint* endpoint, const grpc_channel_args* args, - gpr_timespec deadline, grpc_handshaker_done_cb cb, void* user_data); + gpr_timespec deadline, grpc_tcp_server_acceptor* acceptor, + grpc_handshaker_done_cb cb, void* user_data); #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_H */