|
|
@ -55,7 +55,7 @@ typedef struct listener { |
|
|
|
|
|
|
|
|
|
|
|
typedef struct call_data call_data; |
|
|
|
typedef struct call_data call_data; |
|
|
|
typedef struct channel_data channel_data; |
|
|
|
typedef struct channel_data channel_data; |
|
|
|
typedef struct registered_method_t registered_method_t; |
|
|
|
typedef struct registered_method registered_method; |
|
|
|
|
|
|
|
|
|
|
|
typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; |
|
|
|
typedef enum { BATCH_CALL, REGISTERED_CALL } requested_call_type; |
|
|
|
|
|
|
|
|
|
|
@ -76,7 +76,7 @@ typedef struct requested_call { |
|
|
|
grpc_call_details *details; |
|
|
|
grpc_call_details *details; |
|
|
|
} batch; |
|
|
|
} batch; |
|
|
|
struct { |
|
|
|
struct { |
|
|
|
registered_method_t *registered_method; |
|
|
|
registered_method *method; |
|
|
|
gpr_timespec *deadline; |
|
|
|
gpr_timespec *deadline; |
|
|
|
grpc_byte_buffer **optional_payload; |
|
|
|
grpc_byte_buffer **optional_payload; |
|
|
|
} registered; |
|
|
|
} registered; |
|
|
@ -84,7 +84,7 @@ typedef struct requested_call { |
|
|
|
} requested_call; |
|
|
|
} requested_call; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct channel_registered_method { |
|
|
|
typedef struct channel_registered_method { |
|
|
|
registered_method_t *server_registered_method; |
|
|
|
registered_method *server_registered_method; |
|
|
|
uint32_t flags; |
|
|
|
uint32_t flags; |
|
|
|
bool has_host; |
|
|
|
bool has_host; |
|
|
|
grpc_slice method; |
|
|
|
grpc_slice method; |
|
|
@ -123,7 +123,7 @@ typedef enum { |
|
|
|
ZOMBIED |
|
|
|
ZOMBIED |
|
|
|
} call_state; |
|
|
|
} call_state; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct request_matcher_t request_matcher_t; |
|
|
|
typedef struct request_matcher request_matcher; |
|
|
|
|
|
|
|
|
|
|
|
struct call_data { |
|
|
|
struct call_data { |
|
|
|
grpc_call *call; |
|
|
|
grpc_call *call; |
|
|
@ -145,7 +145,7 @@ struct call_data { |
|
|
|
uint32_t recv_initial_metadata_flags; |
|
|
|
uint32_t recv_initial_metadata_flags; |
|
|
|
grpc_metadata_array initial_metadata; |
|
|
|
grpc_metadata_array initial_metadata; |
|
|
|
|
|
|
|
|
|
|
|
request_matcher_t *request_matcher; |
|
|
|
request_matcher *matcher; |
|
|
|
grpc_byte_buffer *payload; |
|
|
|
grpc_byte_buffer *payload; |
|
|
|
|
|
|
|
|
|
|
|
grpc_closure got_initial_metadata; |
|
|
|
grpc_closure got_initial_metadata; |
|
|
@ -158,21 +158,21 @@ struct call_data { |
|
|
|
call_data *pending_next; |
|
|
|
call_data *pending_next; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct request_matcher_t { |
|
|
|
struct request_matcher { |
|
|
|
grpc_server *server; |
|
|
|
grpc_server *server; |
|
|
|
call_data *pending_head; |
|
|
|
call_data *pending_head; |
|
|
|
call_data *pending_tail; |
|
|
|
call_data *pending_tail; |
|
|
|
gpr_stack_lockfree **requests_per_cq; |
|
|
|
gpr_stack_lockfree **requests_per_cq; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct registered_method_t { |
|
|
|
struct registered_method { |
|
|
|
char *method; |
|
|
|
char *method; |
|
|
|
char *host; |
|
|
|
char *host; |
|
|
|
grpc_server_register_method_payload_handling payload_handling; |
|
|
|
grpc_server_register_method_payload_handling payload_handling; |
|
|
|
uint32_t flags; |
|
|
|
uint32_t flags; |
|
|
|
/* one request matcher per method */ |
|
|
|
/* one request matcher per method */ |
|
|
|
request_matcher_t request_matcher; |
|
|
|
request_matcher matcher; |
|
|
|
registered_method_t *next; |
|
|
|
registered_method *next; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
typedef struct { |
|
|
@ -204,9 +204,9 @@ struct grpc_server { |
|
|
|
bool starting; |
|
|
|
bool starting; |
|
|
|
gpr_cv starting_cv; |
|
|
|
gpr_cv starting_cv; |
|
|
|
|
|
|
|
|
|
|
|
registered_method_t *registered_methods; |
|
|
|
registered_method *registered_methods; |
|
|
|
/** one request matcher for unregistered methods */ |
|
|
|
/** one request matcher for unregistered methods */ |
|
|
|
request_matcher_t unregistered_request_matcher; |
|
|
|
request_matcher unregistered_request_matcher; |
|
|
|
/** free list of available requested_calls_per_cq indices */ |
|
|
|
/** free list of available requested_calls_per_cq indices */ |
|
|
|
gpr_stack_lockfree **request_freelist_per_cq; |
|
|
|
gpr_stack_lockfree **request_freelist_per_cq; |
|
|
|
/** requested call backing data */ |
|
|
|
/** requested call backing data */ |
|
|
@ -313,7 +313,7 @@ static void channel_broadcaster_shutdown(grpc_exec_ctx *exec_ctx, |
|
|
|
* request_matcher |
|
|
|
* request_matcher |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_init(request_matcher_t *rm, size_t entries, |
|
|
|
static void request_matcher_init(request_matcher *rm, size_t entries, |
|
|
|
grpc_server *server) { |
|
|
|
grpc_server *server) { |
|
|
|
memset(rm, 0, sizeof(*rm)); |
|
|
|
memset(rm, 0, sizeof(*rm)); |
|
|
|
rm->server = server; |
|
|
|
rm->server = server; |
|
|
@ -324,7 +324,7 @@ static void request_matcher_init(request_matcher_t *rm, size_t entries, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_destroy(request_matcher_t *rm) { |
|
|
|
static void request_matcher_destroy(request_matcher *rm) { |
|
|
|
for (size_t i = 0; i < rm->server->cq_count; i++) { |
|
|
|
for (size_t i = 0; i < rm->server->cq_count; i++) { |
|
|
|
GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests_per_cq[i]) == -1); |
|
|
|
GPR_ASSERT(gpr_stack_lockfree_pop(rm->requests_per_cq[i]) == -1); |
|
|
|
gpr_stack_lockfree_destroy(rm->requests_per_cq[i]); |
|
|
|
gpr_stack_lockfree_destroy(rm->requests_per_cq[i]); |
|
|
@ -338,7 +338,7 @@ static void kill_zombie(grpc_exec_ctx *exec_ctx, void *elem, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx, |
|
|
|
static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx, |
|
|
|
request_matcher_t *rm) { |
|
|
|
request_matcher *rm) { |
|
|
|
while (rm->pending_head) { |
|
|
|
while (rm->pending_head) { |
|
|
|
call_data *calld = rm->pending_head; |
|
|
|
call_data *calld = rm->pending_head; |
|
|
|
rm->pending_head = calld->pending_next; |
|
|
|
rm->pending_head = calld->pending_next; |
|
|
@ -355,7 +355,7 @@ static void request_matcher_zombify_all_pending_calls(grpc_exec_ctx *exec_ctx, |
|
|
|
|
|
|
|
|
|
|
|
static void request_matcher_kill_requests(grpc_exec_ctx *exec_ctx, |
|
|
|
static void request_matcher_kill_requests(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_server *server, |
|
|
|
grpc_server *server, |
|
|
|
request_matcher_t *rm, |
|
|
|
request_matcher *rm, |
|
|
|
grpc_error *error) { |
|
|
|
grpc_error *error) { |
|
|
|
int request_id; |
|
|
|
int request_id; |
|
|
|
for (size_t i = 0; i < server->cq_count; i++) { |
|
|
|
for (size_t i = 0; i < server->cq_count; i++) { |
|
|
@ -378,7 +378,7 @@ static void server_ref(grpc_server *server) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) { |
|
|
|
static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) { |
|
|
|
registered_method_t *rm; |
|
|
|
registered_method *rm; |
|
|
|
size_t i; |
|
|
|
size_t i; |
|
|
|
grpc_channel_args_destroy(exec_ctx, server->channel_args); |
|
|
|
grpc_channel_args_destroy(exec_ctx, server->channel_args); |
|
|
|
gpr_mu_destroy(&server->mu_global); |
|
|
|
gpr_mu_destroy(&server->mu_global); |
|
|
@ -387,7 +387,7 @@ static void server_delete(grpc_exec_ctx *exec_ctx, grpc_server *server) { |
|
|
|
while ((rm = server->registered_methods) != NULL) { |
|
|
|
while ((rm = server->registered_methods) != NULL) { |
|
|
|
server->registered_methods = rm->next; |
|
|
|
server->registered_methods = rm->next; |
|
|
|
if (server->started) { |
|
|
|
if (server->started) { |
|
|
|
request_matcher_destroy(&rm->request_matcher); |
|
|
|
request_matcher_destroy(&rm->matcher); |
|
|
|
} |
|
|
|
} |
|
|
|
gpr_free(rm->method); |
|
|
|
gpr_free(rm->method); |
|
|
|
gpr_free(rm->host); |
|
|
|
gpr_free(rm->host); |
|
|
@ -519,7 +519,7 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
grpc_call_element *call_elem = (grpc_call_element *)arg; |
|
|
|
grpc_call_element *call_elem = (grpc_call_element *)arg; |
|
|
|
call_data *calld = (call_data *)call_elem->call_data; |
|
|
|
call_data *calld = (call_data *)call_elem->call_data; |
|
|
|
channel_data *chand = (channel_data *)call_elem->channel_data; |
|
|
|
channel_data *chand = (channel_data *)call_elem->channel_data; |
|
|
|
request_matcher_t *rm = calld->request_matcher; |
|
|
|
request_matcher *rm = calld->matcher; |
|
|
|
grpc_server *server = rm->server; |
|
|
|
grpc_server *server = rm->server; |
|
|
|
|
|
|
|
|
|
|
|
if (error != GRPC_ERROR_NONE || gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
|
if (error != GRPC_ERROR_NONE || gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
@ -569,7 +569,7 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg, |
|
|
|
|
|
|
|
|
|
|
|
static void finish_start_new_rpc( |
|
|
|
static void finish_start_new_rpc( |
|
|
|
grpc_exec_ctx *exec_ctx, grpc_server *server, grpc_call_element *elem, |
|
|
|
grpc_exec_ctx *exec_ctx, grpc_server *server, grpc_call_element *elem, |
|
|
|
request_matcher_t *rm, |
|
|
|
request_matcher *rm, |
|
|
|
grpc_server_register_method_payload_handling payload_handling) { |
|
|
|
grpc_server_register_method_payload_handling payload_handling) { |
|
|
|
call_data *calld = (call_data *)elem->call_data; |
|
|
|
call_data *calld = (call_data *)elem->call_data; |
|
|
|
|
|
|
|
|
|
|
@ -583,7 +583,7 @@ static void finish_start_new_rpc( |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
calld->request_matcher = rm; |
|
|
|
calld->matcher = rm; |
|
|
|
|
|
|
|
|
|
|
|
switch (payload_handling) { |
|
|
|
switch (payload_handling) { |
|
|
|
case GRPC_SRM_PAYLOAD_NONE: |
|
|
|
case GRPC_SRM_PAYLOAD_NONE: |
|
|
@ -629,7 +629,7 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
finish_start_new_rpc(exec_ctx, server, elem, |
|
|
|
finish_start_new_rpc(exec_ctx, server, elem, |
|
|
|
&rm->server_registered_method->request_matcher, |
|
|
|
&rm->server_registered_method->matcher, |
|
|
|
rm->server_registered_method->payload_handling); |
|
|
|
rm->server_registered_method->payload_handling); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -647,7 +647,7 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
finish_start_new_rpc(exec_ctx, server, elem, |
|
|
|
finish_start_new_rpc(exec_ctx, server, elem, |
|
|
|
&rm->server_registered_method->request_matcher, |
|
|
|
&rm->server_registered_method->matcher, |
|
|
|
rm->server_registered_method->payload_handling); |
|
|
|
rm->server_registered_method->payload_handling); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -689,11 +689,11 @@ static void kill_pending_work_locked(grpc_exec_ctx *exec_ctx, |
|
|
|
GRPC_ERROR_REF(error)); |
|
|
|
GRPC_ERROR_REF(error)); |
|
|
|
request_matcher_zombify_all_pending_calls( |
|
|
|
request_matcher_zombify_all_pending_calls( |
|
|
|
exec_ctx, &server->unregistered_request_matcher); |
|
|
|
exec_ctx, &server->unregistered_request_matcher); |
|
|
|
for (registered_method_t *rm = server->registered_methods; rm; |
|
|
|
for (registered_method *rm = server->registered_methods; rm; |
|
|
|
rm = rm->next) { |
|
|
|
rm = rm->next) { |
|
|
|
request_matcher_kill_requests(exec_ctx, server, &rm->request_matcher, |
|
|
|
request_matcher_kill_requests(exec_ctx, server, &rm->matcher, |
|
|
|
GRPC_ERROR_REF(error)); |
|
|
|
GRPC_ERROR_REF(error)); |
|
|
|
request_matcher_zombify_all_pending_calls(exec_ctx, &rm->request_matcher); |
|
|
|
request_matcher_zombify_all_pending_calls(exec_ctx, &rm->matcher); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
|
GRPC_ERROR_UNREF(error); |
|
|
@ -1036,7 +1036,7 @@ void *grpc_server_register_method( |
|
|
|
grpc_server *server, const char *method, const char *host, |
|
|
|
grpc_server *server, const char *method, const char *host, |
|
|
|
grpc_server_register_method_payload_handling payload_handling, |
|
|
|
grpc_server_register_method_payload_handling payload_handling, |
|
|
|
uint32_t flags) { |
|
|
|
uint32_t flags) { |
|
|
|
registered_method_t *m; |
|
|
|
registered_method *m; |
|
|
|
GRPC_API_TRACE( |
|
|
|
GRPC_API_TRACE( |
|
|
|
"grpc_server_register_method(server=%p, method=%s, host=%s, " |
|
|
|
"grpc_server_register_method(server=%p, method=%s, host=%s, " |
|
|
|
"flags=0x%08x)", |
|
|
|
"flags=0x%08x)", |
|
|
@ -1058,7 +1058,7 @@ void *grpc_server_register_method( |
|
|
|
flags); |
|
|
|
flags); |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
m = (registered_method_t *)gpr_zalloc(sizeof(registered_method_t)); |
|
|
|
m = (registered_method *)gpr_zalloc(sizeof(registered_method)); |
|
|
|
m->method = gpr_strdup(method); |
|
|
|
m->method = gpr_strdup(method); |
|
|
|
m->host = gpr_strdup(host); |
|
|
|
m->host = gpr_strdup(host); |
|
|
|
m->next = server->registered_methods; |
|
|
|
m->next = server->registered_methods; |
|
|
@ -1113,9 +1113,8 @@ void grpc_server_start(grpc_server *server) { |
|
|
|
} |
|
|
|
} |
|
|
|
request_matcher_init(&server->unregistered_request_matcher, |
|
|
|
request_matcher_init(&server->unregistered_request_matcher, |
|
|
|
(size_t)server->max_requested_calls_per_cq, server); |
|
|
|
(size_t)server->max_requested_calls_per_cq, server); |
|
|
|
for (registered_method_t *rm = server->registered_methods; rm; |
|
|
|
for (registered_method *rm = server->registered_methods; rm; rm = rm->next) { |
|
|
|
rm = rm->next) { |
|
|
|
request_matcher_init(&rm->matcher, |
|
|
|
request_matcher_init(&rm->request_matcher, |
|
|
|
|
|
|
|
(size_t)server->max_requested_calls_per_cq, server); |
|
|
|
(size_t)server->max_requested_calls_per_cq, server); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1142,7 +1141,7 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, |
|
|
|
const grpc_channel_args *args) { |
|
|
|
const grpc_channel_args *args) { |
|
|
|
size_t num_registered_methods; |
|
|
|
size_t num_registered_methods; |
|
|
|
size_t alloc; |
|
|
|
size_t alloc; |
|
|
|
registered_method_t *rm; |
|
|
|
registered_method *rm; |
|
|
|
channel_registered_method *crm; |
|
|
|
channel_registered_method *crm; |
|
|
|
grpc_channel *channel; |
|
|
|
grpc_channel *channel; |
|
|
|
channel_data *chand; |
|
|
|
channel_data *chand; |
|
|
@ -1371,7 +1370,7 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx, |
|
|
|
grpc_server *server, size_t cq_idx, |
|
|
|
grpc_server *server, size_t cq_idx, |
|
|
|
requested_call *rc) { |
|
|
|
requested_call *rc) { |
|
|
|
call_data *calld = NULL; |
|
|
|
call_data *calld = NULL; |
|
|
|
request_matcher_t *rm = NULL; |
|
|
|
request_matcher *rm = NULL; |
|
|
|
int request_id; |
|
|
|
int request_id; |
|
|
|
if (gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
|
if (gpr_atm_acq_load(&server->shutdown_flag)) { |
|
|
|
fail_call(exec_ctx, server, cq_idx, rc, |
|
|
|
fail_call(exec_ctx, server, cq_idx, rc, |
|
|
@ -1392,7 +1391,7 @@ static grpc_call_error queue_call_request(grpc_exec_ctx *exec_ctx, |
|
|
|
rm = &server->unregistered_request_matcher; |
|
|
|
rm = &server->unregistered_request_matcher; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case REGISTERED_CALL: |
|
|
|
case REGISTERED_CALL: |
|
|
|
rm = &rc->data.registered.registered_method->request_matcher; |
|
|
|
rm = &rc->data.registered.method->matcher; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
server->requested_calls_per_cq[cq_idx][request_id] = *rc; |
|
|
|
server->requested_calls_per_cq[cq_idx][request_id] = *rc; |
|
|
@ -1483,7 +1482,7 @@ grpc_call_error grpc_server_request_registered_call( |
|
|
|
grpc_call_error error; |
|
|
|
grpc_call_error error; |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
|
|
|
requested_call *rc = (requested_call *)gpr_malloc(sizeof(*rc)); |
|
|
|
requested_call *rc = (requested_call *)gpr_malloc(sizeof(*rc)); |
|
|
|
registered_method_t *rm = (registered_method_t *)rmp; |
|
|
|
registered_method *rm = (registered_method *)rmp; |
|
|
|
GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); |
|
|
|
GRPC_STATS_INC_SERVER_REQUESTED_CALLS(&exec_ctx); |
|
|
|
GRPC_API_TRACE( |
|
|
|
GRPC_API_TRACE( |
|
|
|
"grpc_server_request_registered_call(" |
|
|
|
"grpc_server_request_registered_call(" |
|
|
@ -1521,7 +1520,7 @@ grpc_call_error grpc_server_request_registered_call( |
|
|
|
rc->tag = tag; |
|
|
|
rc->tag = tag; |
|
|
|
rc->cq_bound_to_call = cq_bound_to_call; |
|
|
|
rc->cq_bound_to_call = cq_bound_to_call; |
|
|
|
rc->call = call; |
|
|
|
rc->call = call; |
|
|
|
rc->data.registered.registered_method = rm; |
|
|
|
rc->data.registered.method = rm; |
|
|
|
rc->data.registered.deadline = deadline; |
|
|
|
rc->data.registered.deadline = deadline; |
|
|
|
rc->initial_metadata = initial_metadata; |
|
|
|
rc->initial_metadata = initial_metadata; |
|
|
|
rc->data.registered.optional_payload = optional_payload; |
|
|
|
rc->data.registered.optional_payload = optional_payload; |
|
|
|