diff options
Diffstat (limited to 'src/core/channel/channel_stack.c')
-rw-r--r-- | src/core/channel/channel_stack.c | 187 |
1 files changed, 94 insertions, 93 deletions
diff --git a/src/core/channel/channel_stack.c b/src/core/channel/channel_stack.c index 67ab2c535f..abd7f719e7 100644 --- a/src/core/channel/channel_stack.c +++ b/src/core/channel/channel_stack.c @@ -59,20 +59,21 @@ int grpc_trace_channel = 0; #define ROUND_UP_TO_ALIGNMENT_SIZE(x) \ (((x) + GPR_MAX_ALIGNMENT - 1u) & ~(GPR_MAX_ALIGNMENT - 1u)) -size_t -grpc_channel_stack_size (const grpc_channel_filter ** filters, size_t filter_count) -{ +size_t grpc_channel_stack_size(const grpc_channel_filter **filters, + size_t filter_count) { /* always need the header, and size for the channel elements */ - size_t size = ROUND_UP_TO_ALIGNMENT_SIZE (sizeof (grpc_channel_stack)) + ROUND_UP_TO_ALIGNMENT_SIZE (filter_count * sizeof (grpc_channel_element)); + size_t size = + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_channel_stack)) + + ROUND_UP_TO_ALIGNMENT_SIZE(filter_count * sizeof(grpc_channel_element)); size_t i; - GPR_ASSERT ((GPR_MAX_ALIGNMENT & (GPR_MAX_ALIGNMENT - 1)) == 0 && "GPR_MAX_ALIGNMENT must be a power of two"); + GPR_ASSERT((GPR_MAX_ALIGNMENT & (GPR_MAX_ALIGNMENT - 1)) == 0 && + "GPR_MAX_ALIGNMENT must be a power of two"); /* add the size for each filter */ - for (i = 0; i < filter_count; i++) - { - size += ROUND_UP_TO_ALIGNMENT_SIZE (filters[i]->sizeof_channel_data); - } + for (i = 0; i < filter_count; i++) { + size += ROUND_UP_TO_ALIGNMENT_SIZE(filters[i]->sizeof_channel_data); + } return size; } @@ -85,142 +86,142 @@ grpc_channel_stack_size (const grpc_channel_filter ** filters, size_t filter_cou ((grpc_call_element *)((char *)(stk) + \ ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)))) -grpc_channel_element * -grpc_channel_stack_element (grpc_channel_stack * channel_stack, size_t index) -{ - return CHANNEL_ELEMS_FROM_STACK (channel_stack) + index; +grpc_channel_element *grpc_channel_stack_element( + grpc_channel_stack *channel_stack, size_t index) { + return CHANNEL_ELEMS_FROM_STACK(channel_stack) + index; } -grpc_channel_element * -grpc_channel_stack_last_element (grpc_channel_stack * channel_stack) -{ - return grpc_channel_stack_element (channel_stack, channel_stack->count - 1); +grpc_channel_element *grpc_channel_stack_last_element( + grpc_channel_stack *channel_stack) { + return grpc_channel_stack_element(channel_stack, channel_stack->count - 1); } -grpc_call_element * -grpc_call_stack_element (grpc_call_stack * call_stack, size_t index) -{ - return CALL_ELEMS_FROM_STACK (call_stack) + index; +grpc_call_element *grpc_call_stack_element(grpc_call_stack *call_stack, + size_t index) { + return CALL_ELEMS_FROM_STACK(call_stack) + index; } -void -grpc_channel_stack_init (grpc_exec_ctx * exec_ctx, const grpc_channel_filter ** filters, size_t filter_count, grpc_channel * master, const grpc_channel_args * args, grpc_mdctx * metadata_context, grpc_channel_stack * stack) -{ - size_t call_size = ROUND_UP_TO_ALIGNMENT_SIZE (sizeof (grpc_call_stack)) + ROUND_UP_TO_ALIGNMENT_SIZE (filter_count * sizeof (grpc_call_element)); +void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, + const grpc_channel_filter **filters, + size_t filter_count, grpc_channel *master, + const grpc_channel_args *args, + grpc_mdctx *metadata_context, + grpc_channel_stack *stack) { + size_t call_size = + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)) + + ROUND_UP_TO_ALIGNMENT_SIZE(filter_count * sizeof(grpc_call_element)); grpc_channel_element *elems; char *user_data; size_t i; stack->count = filter_count; - elems = CHANNEL_ELEMS_FROM_STACK (stack); - user_data = ((char *) elems) + ROUND_UP_TO_ALIGNMENT_SIZE (filter_count * sizeof (grpc_channel_element)); + elems = CHANNEL_ELEMS_FROM_STACK(stack); + user_data = + ((char *)elems) + + ROUND_UP_TO_ALIGNMENT_SIZE(filter_count * sizeof(grpc_channel_element)); /* init per-filter data */ - for (i = 0; i < filter_count; i++) - { - elems[i].filter = filters[i]; - elems[i].channel_data = user_data; - elems[i].filter->init_channel_elem (exec_ctx, &elems[i], master, args, metadata_context, i == 0, i == (filter_count - 1)); - user_data += ROUND_UP_TO_ALIGNMENT_SIZE (filters[i]->sizeof_channel_data); - call_size += ROUND_UP_TO_ALIGNMENT_SIZE (filters[i]->sizeof_call_data); - } - - GPR_ASSERT (user_data > (char *) stack); - GPR_ASSERT ((gpr_uintptr) (user_data - (char *) stack) == grpc_channel_stack_size (filters, filter_count)); + for (i = 0; i < filter_count; i++) { + elems[i].filter = filters[i]; + elems[i].channel_data = user_data; + elems[i].filter->init_channel_elem(exec_ctx, &elems[i], master, args, + metadata_context, i == 0, + i == (filter_count - 1)); + user_data += ROUND_UP_TO_ALIGNMENT_SIZE(filters[i]->sizeof_channel_data); + call_size += ROUND_UP_TO_ALIGNMENT_SIZE(filters[i]->sizeof_call_data); + } + + GPR_ASSERT(user_data > (char *)stack); + GPR_ASSERT((gpr_uintptr)(user_data - (char *)stack) == + grpc_channel_stack_size(filters, filter_count)); stack->call_stack_size = call_size; } -void -grpc_channel_stack_destroy (grpc_exec_ctx * exec_ctx, grpc_channel_stack * stack) -{ - grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK (stack); +void grpc_channel_stack_destroy(grpc_exec_ctx *exec_ctx, + grpc_channel_stack *stack) { + grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK(stack); size_t count = stack->count; size_t i; /* destroy per-filter data */ - for (i = 0; i < count; i++) - { - channel_elems[i].filter->destroy_channel_elem (exec_ctx, &channel_elems[i]); - } + for (i = 0; i < count; i++) { + channel_elems[i].filter->destroy_channel_elem(exec_ctx, &channel_elems[i]); + } } -void -grpc_call_stack_init (grpc_exec_ctx * exec_ctx, grpc_channel_stack * channel_stack, const void *transport_server_data, grpc_transport_stream_op * initial_op, grpc_call_stack * call_stack) -{ - grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK (channel_stack); +void grpc_call_stack_init(grpc_exec_ctx *exec_ctx, + grpc_channel_stack *channel_stack, + const void *transport_server_data, + grpc_transport_stream_op *initial_op, + grpc_call_stack *call_stack) { + grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK(channel_stack); size_t count = channel_stack->count; grpc_call_element *call_elems; char *user_data; size_t i; call_stack->count = count; - call_elems = CALL_ELEMS_FROM_STACK (call_stack); - user_data = ((char *) call_elems) + ROUND_UP_TO_ALIGNMENT_SIZE (count * sizeof (grpc_call_element)); + call_elems = CALL_ELEMS_FROM_STACK(call_stack); + user_data = ((char *)call_elems) + + ROUND_UP_TO_ALIGNMENT_SIZE(count * sizeof(grpc_call_element)); /* init per-filter data */ - for (i = 0; i < count; i++) - { - call_elems[i].filter = channel_elems[i].filter; - call_elems[i].channel_data = channel_elems[i].channel_data; - call_elems[i].call_data = user_data; - call_elems[i].filter->init_call_elem (exec_ctx, &call_elems[i], transport_server_data, initial_op); - user_data += ROUND_UP_TO_ALIGNMENT_SIZE (call_elems[i].filter->sizeof_call_data); - } + for (i = 0; i < count; i++) { + call_elems[i].filter = channel_elems[i].filter; + call_elems[i].channel_data = channel_elems[i].channel_data; + call_elems[i].call_data = user_data; + call_elems[i].filter->init_call_elem(exec_ctx, &call_elems[i], + transport_server_data, initial_op); + user_data += + ROUND_UP_TO_ALIGNMENT_SIZE(call_elems[i].filter->sizeof_call_data); + } } -void -grpc_call_stack_destroy (grpc_exec_ctx * exec_ctx, grpc_call_stack * stack) -{ - grpc_call_element *elems = CALL_ELEMS_FROM_STACK (stack); +void grpc_call_stack_destroy(grpc_exec_ctx *exec_ctx, grpc_call_stack *stack) { + grpc_call_element *elems = CALL_ELEMS_FROM_STACK(stack); size_t count = stack->count; size_t i; /* destroy per-filter data */ - for (i = 0; i < count; i++) - { - elems[i].filter->destroy_call_elem (exec_ctx, &elems[i]); - } + for (i = 0; i < count; i++) { + elems[i].filter->destroy_call_elem(exec_ctx, &elems[i]); + } } -void -grpc_call_next_op (grpc_exec_ctx * exec_ctx, grpc_call_element * elem, grpc_transport_stream_op * op) -{ +void grpc_call_next_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_transport_stream_op *op) { grpc_call_element *next_elem = elem + 1; - next_elem->filter->start_transport_stream_op (exec_ctx, next_elem, op); + next_elem->filter->start_transport_stream_op(exec_ctx, next_elem, op); } -char * -grpc_call_next_get_peer (grpc_exec_ctx * exec_ctx, grpc_call_element * elem) -{ +char *grpc_call_next_get_peer(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem) { grpc_call_element *next_elem = elem + 1; - return next_elem->filter->get_peer (exec_ctx, next_elem); + return next_elem->filter->get_peer(exec_ctx, next_elem); } -void -grpc_channel_next_op (grpc_exec_ctx * exec_ctx, grpc_channel_element * elem, grpc_transport_op * op) -{ +void grpc_channel_next_op(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, + grpc_transport_op *op) { grpc_channel_element *next_elem = elem + 1; - next_elem->filter->start_transport_op (exec_ctx, next_elem, op); + next_elem->filter->start_transport_op(exec_ctx, next_elem, op); } -grpc_channel_stack * -grpc_channel_stack_from_top_element (grpc_channel_element * elem) -{ - return (grpc_channel_stack *) ((char *) (elem) - ROUND_UP_TO_ALIGNMENT_SIZE (sizeof (grpc_channel_stack))); +grpc_channel_stack *grpc_channel_stack_from_top_element( + grpc_channel_element *elem) { + return (grpc_channel_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( + sizeof(grpc_channel_stack))); } -grpc_call_stack * -grpc_call_stack_from_top_element (grpc_call_element * elem) -{ - return (grpc_call_stack *) ((char *) (elem) - ROUND_UP_TO_ALIGNMENT_SIZE (sizeof (grpc_call_stack))); +grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) { + return (grpc_call_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( + sizeof(grpc_call_stack))); } -void -grpc_call_element_send_cancel (grpc_exec_ctx * exec_ctx, grpc_call_element * cur_elem) -{ +void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, + grpc_call_element *cur_elem) { grpc_transport_stream_op op; - memset (&op, 0, sizeof (op)); + memset(&op, 0, sizeof(op)); op.cancel_with_status = GRPC_STATUS_CANCELLED; - grpc_call_next_op (exec_ctx, cur_elem, &op); + grpc_call_next_op(exec_ctx, cur_elem, &op); } |