From 5945ee1a75083777ddd8fe4f49531f6f3e307d7a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sat, 27 Jun 2015 10:36:09 -0700 Subject: [PATCH] Request/response path starting to work --- src/core/channel/http_client_filter.c | 1 - src/core/client_config/subchannel.c | 32 +++++++++++++++++++-------- src/core/surface/channel_create.c | 6 ++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/core/channel/http_client_filter.c b/src/core/channel/http_client_filter.c index 6928a59c38a..5dec734c8cd 100644 --- a/src/core/channel/http_client_filter.c +++ b/src/core/channel/http_client_filter.c @@ -179,7 +179,6 @@ static void init_channel_elem(grpc_channel_element *elem, /* The first and the last filters tend to be implemented differently to handle the case that there's no 'next' filter to call on the up or down path */ - GPR_ASSERT(!is_first); GPR_ASSERT(!is_last); /* initialize members */ diff --git a/src/core/client_config/subchannel.c b/src/core/client_config/subchannel.c index c2044c9e706..b489ce04a5d 100644 --- a/src/core/client_config/subchannel.c +++ b/src/core/client_config/subchannel.c @@ -64,7 +64,7 @@ struct grpc_subchannel { /** non-transport related channel filters */ const grpc_channel_filter **filters; - size_t filter_count; + size_t num_filters; /** channel arguments */ grpc_channel_args *args; /** address to connect to */ @@ -144,11 +144,10 @@ grpc_subchannel *grpc_subchannel_create(grpc_connector *connector, gpr_ref_init(&c->refs, 1); c->connector = connector; grpc_connector_ref(c->connector); - c->filter_count = args->filter_count + 1; - c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * c->filter_count); + c->num_filters = args->filter_count; + c->filters = gpr_malloc(sizeof(grpc_channel_filter *) * c->num_filters); memcpy(c->filters, args->filters, - sizeof(grpc_channel_filter *) * args->filter_count); - c->filters[c->filter_count - 1] = &grpc_connected_channel_filter; + sizeof(grpc_channel_filter *) * c->num_filters); c->addr = gpr_malloc(args->addr_len); memcpy(c->addr, args->addr, args->addr_len); c->addr_len = args->addr_len; @@ -249,13 +248,26 @@ void grpc_subchannel_notify_on_state_change(grpc_subchannel *c, } static void publish_transport(grpc_subchannel *c) { - size_t channel_stack_size = grpc_channel_stack_size(c->filters, c->filter_count); - connection *con = gpr_malloc(sizeof(connection) + channel_stack_size); - grpc_channel_stack *stk = (grpc_channel_stack *)(con + 1); + size_t channel_stack_size; + connection *con; + grpc_channel_stack *stk; + size_t num_filters; + const grpc_channel_filter **filters; waiting_for_connect *w4c; + + num_filters = c->num_filters + c->connecting_result.num_filters + 1; + filters = gpr_malloc(sizeof(*filters) * num_filters); + memcpy(filters, c->filters, sizeof(*filters) * c->num_filters); + memcpy(filters + c->num_filters, c->connecting_result.filters, sizeof(*filters) * c->connecting_result.num_filters); + filters[num_filters - 1] = &grpc_connected_channel_filter; + + channel_stack_size = grpc_channel_stack_size(filters, num_filters); + con = gpr_malloc(sizeof(connection) + channel_stack_size); + stk = (grpc_channel_stack *)(con + 1); + gpr_ref_init(&con->refs, 1); con->subchannel = c; - grpc_channel_stack_init(c->filters, c->filter_count, c->args, c->mdctx, stk); + grpc_channel_stack_init(filters, num_filters, c->args, c->mdctx, stk); grpc_connected_channel_bind_transport(stk, c->connecting_result.transport); memset(&c->connecting_result, 0, sizeof(c->connecting_result)); @@ -268,6 +280,8 @@ static void publish_transport(grpc_subchannel *c) { abort(); /* not implemented */ } gpr_mu_unlock(&c->mu); + + gpr_free(filters); } static void subchannel_connected(void *arg, int iomgr_success) { diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index afa1d36820c..a00c08a8300 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -40,6 +40,7 @@ #include "src/core/channel/channel_args.h" #include "src/core/channel/client_channel.h" +#include "src/core/channel/http_client_filter.h" #include "src/core/client_config/resolver_registry.h" #include "src/core/iomgr/tcp_client.h" #include "src/core/surface/channel.h" @@ -72,8 +73,11 @@ static void connected(void *arg, grpc_endpoint *tcp) { if (tcp != NULL) { c->result->transport = grpc_create_chttp2_transport(c->args.channel_args, tcp, NULL, 0, c->args.metadata_context, 1); + c->result->filters = gpr_malloc(sizeof(grpc_channel_filter*)); + c->result->filters[0] = &grpc_http_client_filter; + c->result->num_filters = 1; } else { - c->result->transport = NULL; + memset(c->result, 0, sizeof(*c->result)); } notify = c->notify; c->notify = NULL;