From 0960818e546f63131522def31838848370467c25 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Nov 2016 15:43:56 -0800 Subject: [PATCH] bm_fullstack runs --- .../chttp2/transport/incoming_metadata.c | 13 ++-- src/core/lib/channel/http_server_filter.c | 14 ++-- src/core/lib/surface/call.c | 71 +++---------------- src/core/lib/transport/metadata_batch.c | 1 + 4 files changed, 23 insertions(+), 76 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index 9922dd87e16..910afea9ca0 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -80,16 +80,11 @@ void grpc_chttp2_incoming_metadata_buffer_publish( buffer->published = 1; if (buffer->count > 0) { size_t i; - for (i = 1; i < buffer->count; i++) { - buffer->elems[i].prev = &buffer->elems[i - 1]; - } - for (i = 0; i < buffer->count - 1; i++) { - buffer->elems[i].next = &buffer->elems[i + 1]; + for (i = 0; i < buffer->count; i++) { + GRPC_LOG_IF_ERROR( + "grpc_chttp2_incoming_metadata_buffer_publish", + grpc_metadata_batch_link_tail(batch, &buffer->elems[i])); } - buffer->elems[0].prev = NULL; - buffer->elems[buffer->count - 1].next = NULL; - batch->list.head = &buffer->elems[0]; - batch->list.tail = &buffer->elems[buffer->count - 1]; } else { batch->list.head = batch->list.tail = NULL; } diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 10b386a2f07..07c67e54c1c 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -99,7 +99,11 @@ static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, static void add_error(const char *error_name, grpc_error **cumulative, grpc_error *new) { - abort(); + if (new == GRPC_ERROR_NONE) return; + if (*cumulative == GRPC_ERROR_NONE) { + *cumulative = GRPC_ERROR_CREATE(error_name); + } + *cumulative = grpc_error_add_child(*cumulative, new); } static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, @@ -145,12 +149,12 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } if (b->idx.named.scheme != NULL) { - if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTP) && - !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTPS) && - !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_GRPC)) { + if (!grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTP) && + !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTPS) && + !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_GRPC)) { add_error(error_name, &error, grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), - b->idx.named.te->md)); + b->idx.named.scheme->md)); } grpc_metadata_batch_remove(b, b->idx.named.scheme); } else { diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index a0bcac22a3b..d5e90ccdda1 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -623,73 +623,19 @@ static int prepare_application_metadata( if (call->send_extra_metadata_count == 0) { prepend_extra_metadata = 0; } else { - for (i = 1; i < call->send_extra_metadata_count; i++) { - call->send_extra_metadata[i].prev = &call->send_extra_metadata[i - 1]; - } - for (i = 0; i < call->send_extra_metadata_count - 1; i++) { - call->send_extra_metadata[i].next = &call->send_extra_metadata[i + 1]; + for (i = 0; i < call->send_extra_metadata_count; i++) { + GRPC_LOG_IF_ERROR("prepare_application_metadata", + grpc_metadata_batch_link_tail( + batch, &call->send_extra_metadata[i])); } } } - for (i = 1; i < total_count; i++) { - grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - grpc_metadata *prev_md = - get_md_elem(metadata, additional_metadata, i - 1, count); - linked_from_md(md)->prev = linked_from_md(prev_md); - } - for (i = 0; i < total_count - 1; i++) { + for (i = 0; i < total_count; i++) { grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - grpc_metadata *next_md = - get_md_elem(metadata, additional_metadata, i + 1, count); - linked_from_md(md)->next = linked_from_md(next_md); - } - - switch (prepend_extra_metadata * 2 + (total_count != 0)) { - case 0: - /* no prepend, no metadata => nothing to do */ - batch->list.head = batch->list.tail = NULL; - break; - case 1: { - /* metadata, but no prepend */ - grpc_metadata *first_md = - get_md_elem(metadata, additional_metadata, 0, count); - grpc_metadata *last_md = - get_md_elem(metadata, additional_metadata, total_count - 1, count); - batch->list.head = linked_from_md(first_md); - batch->list.tail = linked_from_md(last_md); - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - break; - } - case 2: - /* prepend, but no md */ - batch->list.head = &call->send_extra_metadata[0]; - batch->list.tail = - &call->send_extra_metadata[call->send_extra_metadata_count - 1]; - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - call->send_extra_metadata_count = 0; - break; - case 3: { - /* prepend AND md */ - grpc_metadata *first_md = - get_md_elem(metadata, additional_metadata, 0, count); - grpc_metadata *last_md = - get_md_elem(metadata, additional_metadata, total_count - 1, count); - batch->list.head = &call->send_extra_metadata[0]; - call->send_extra_metadata[call->send_extra_metadata_count - 1].next = - linked_from_md(first_md); - linked_from_md(first_md)->prev = - &call->send_extra_metadata[call->send_extra_metadata_count - 1]; - batch->list.tail = linked_from_md(last_md); - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - call->send_extra_metadata_count = 0; - break; - } - default: - GPR_UNREACHABLE_CODE(return 0); + GRPC_LOG_IF_ERROR("prepare_application_metadata", + grpc_metadata_batch_link_tail(batch, linked_from_md(md))); } + call->send_extra_metadata_count = 0; return 1; } @@ -936,6 +882,7 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, int is_trailing) { + if (b->list.count == 0) return; GPR_TIMER_BEGIN("publish_app_metadata", 0); grpc_metadata_array *dest; grpc_metadata *mdusr; diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 2bbd5ba6aa1..c41d28d9f7e 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -194,6 +194,7 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { list->head = storage; } list->tail = storage; + list->count++; assert_valid_list(list); }