|
|
|
@ -55,11 +55,6 @@ |
|
|
|
|
#include "src/core/lib/surface/api_trace.h" |
|
|
|
|
#include "src/core/lib/surface/server.h" |
|
|
|
|
|
|
|
|
|
typedef struct pending_handshake_manager_node { |
|
|
|
|
grpc_handshake_manager *handshake_mgr; |
|
|
|
|
struct pending_handshake_manager_node *next; |
|
|
|
|
} pending_handshake_manager_node; |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
grpc_server *server; |
|
|
|
|
grpc_tcp_server *tcp_server; |
|
|
|
@ -68,7 +63,7 @@ typedef struct { |
|
|
|
|
bool shutdown; |
|
|
|
|
grpc_closure tcp_server_shutdown_complete; |
|
|
|
|
grpc_closure *server_destroy_listener_done; |
|
|
|
|
pending_handshake_manager_node *pending_handshake_mgrs; |
|
|
|
|
grpc_handshake_manager *pending_handshake_mgrs; |
|
|
|
|
} server_state; |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
@ -78,44 +73,6 @@ typedef struct { |
|
|
|
|
grpc_handshake_manager *handshake_mgr; |
|
|
|
|
} server_connection_state; |
|
|
|
|
|
|
|
|
|
static void pending_handshake_manager_add_locked( |
|
|
|
|
server_state *state, grpc_handshake_manager *handshake_mgr) { |
|
|
|
|
pending_handshake_manager_node *node = gpr_malloc(sizeof(*node)); |
|
|
|
|
node->handshake_mgr = handshake_mgr; |
|
|
|
|
node->next = state->pending_handshake_mgrs; |
|
|
|
|
state->pending_handshake_mgrs = node; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void pending_handshake_manager_remove_locked( |
|
|
|
|
server_state *state, grpc_handshake_manager *handshake_mgr) { |
|
|
|
|
pending_handshake_manager_node **prev_node = &state->pending_handshake_mgrs; |
|
|
|
|
for (pending_handshake_manager_node *node = state->pending_handshake_mgrs; |
|
|
|
|
node != NULL; node = node->next) { |
|
|
|
|
if (node->handshake_mgr == handshake_mgr) { |
|
|
|
|
*prev_node = node->next; |
|
|
|
|
gpr_free(node); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
prev_node = &node->next; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void pending_handshake_manager_shutdown_locked(grpc_exec_ctx *exec_ctx, |
|
|
|
|
server_state *state, |
|
|
|
|
grpc_error *why) { |
|
|
|
|
pending_handshake_manager_node *prev_node = NULL; |
|
|
|
|
for (pending_handshake_manager_node *node = state->pending_handshake_mgrs; |
|
|
|
|
node != NULL; node = node->next) { |
|
|
|
|
grpc_handshake_manager_shutdown(exec_ctx, node->handshake_mgr, |
|
|
|
|
GRPC_ERROR_REF(why)); |
|
|
|
|
gpr_free(prev_node); |
|
|
|
|
prev_node = node; |
|
|
|
|
} |
|
|
|
|
gpr_free(prev_node); |
|
|
|
|
state->pending_handshake_mgrs = NULL; |
|
|
|
|
GRPC_ERROR_UNREF(why); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|
grpc_error *error) { |
|
|
|
|
grpc_handshaker_args *args = arg; |
|
|
|
@ -153,7 +110,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|
grpc_channel_args_destroy(exec_ctx, args->args); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
pending_handshake_manager_remove_locked(connection_state->server_state, |
|
|
|
|
grpc_handshake_manager_pending_list_remove( |
|
|
|
|
&connection_state->server_state->pending_handshake_mgrs, |
|
|
|
|
connection_state->handshake_mgr); |
|
|
|
|
gpr_mu_unlock(&connection_state->server_state->mu); |
|
|
|
|
grpc_handshake_manager_destroy(exec_ctx, connection_state->handshake_mgr); |
|
|
|
@ -174,7 +132,8 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp, |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
grpc_handshake_manager *handshake_mgr = grpc_handshake_manager_create(); |
|
|
|
|
pending_handshake_manager_add_locked(state, handshake_mgr); |
|
|
|
|
grpc_handshake_manager_pending_list_add(&state->pending_handshake_mgrs, |
|
|
|
|
handshake_mgr); |
|
|
|
|
gpr_mu_unlock(&state->mu); |
|
|
|
|
grpc_tcp_server_ref(state->tcp_server); |
|
|
|
|
server_connection_state *connection_state = |
|
|
|
@ -213,8 +172,8 @@ static void tcp_server_shutdown_complete(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|
gpr_mu_lock(&state->mu); |
|
|
|
|
grpc_closure *destroy_done = state->server_destroy_listener_done; |
|
|
|
|
GPR_ASSERT(state->shutdown); |
|
|
|
|
pending_handshake_manager_shutdown_locked(exec_ctx, state, |
|
|
|
|
GRPC_ERROR_REF(error)); |
|
|
|
|
grpc_handshake_manager_pending_list_shutdown_all( |
|
|
|
|
exec_ctx, state->pending_handshake_mgrs, GRPC_ERROR_REF(error)); |
|
|
|
|
gpr_mu_unlock(&state->mu); |
|
|
|
|
// Flush queued work before destroying handshaker factory, since that
|
|
|
|
|
// may do a synchronous unref.
|
|
|
|
|