diff options
author | klempner <klempner@google.com> | 2014-12-19 13:03:35 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2014-12-19 13:49:05 -0800 |
commit | c463f746c90240d5b724c546660e90853ebed77d (patch) | |
tree | e0be20f930e0346abfeb95b23900ab9f822400a3 /src/core/surface/channel.c | |
parent | 186cdab82eaca139c63f4742a57658e01e2571ec (diff) |
Pre allocate client side strings per channel for method, scheme, path, and
authority.
For method and scheme, move these from channel to http_client_filter.
Change on 2014/12/19 by klempner <klempner@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=82536909
Diffstat (limited to 'src/core/surface/channel.c')
-rw-r--r-- | src/core/surface/channel.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index fe7a3afcc9..8ef13675fe 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -47,6 +47,8 @@ struct grpc_channel { grpc_mdctx *metadata_context; grpc_mdstr *grpc_status_string; grpc_mdstr *grpc_message_string; + grpc_mdstr *path_string; + grpc_mdstr *authority_string; }; #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack *)((c)+1)) @@ -63,6 +65,8 @@ grpc_channel *grpc_channel_create_from_filters( channel->metadata_context = mdctx; channel->grpc_status_string = grpc_mdstr_from_string(mdctx, "grpc-status"); channel->grpc_message_string = grpc_mdstr_from_string(mdctx, "grpc-message"); + channel->path_string = grpc_mdstr_from_string(mdctx, ":path"); + channel->authority_string = grpc_mdstr_from_string(mdctx, ":authority"); grpc_channel_stack_init(filters, num_filters, args, channel->metadata_context, CHANNEL_STACK_FROM_CHANNEL(channel)); return channel; @@ -74,7 +78,8 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, const char *method, const char *host, gpr_timespec absolute_deadline) { grpc_call *call; - grpc_metadata md; + grpc_mdelem *path_mdelem; + grpc_mdelem *authority_mdelem; if (!channel->is_client) { gpr_log(GPR_ERROR, "Cannot create a call on the server."); @@ -83,18 +88,21 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, const char *method, call = grpc_call_create(channel, NULL); -#define ADDMD(k, v) \ - do { \ - md.key = (k); \ - md.value = (char *)(v); \ - md.value_length = strlen((v)); \ - grpc_call_add_metadata(call, &md, 0); \ - } while (0) - ADDMD(":method", "POST"); - ADDMD(":scheme", "grpc"); - ADDMD(":path", method); - ADDMD(":authority", host); - ADDMD("content-type", "application/grpc"); + /* Add :path and :authority headers. */ + /* TODO(klempner): Consider optimizing this by stashing mdelems for common + values of method and host. */ + grpc_mdstr_ref(channel->path_string); + path_mdelem = grpc_mdelem_from_metadata_strings( + channel->metadata_context, channel->path_string, + grpc_mdstr_from_string(channel->metadata_context, method)); + grpc_call_add_mdelem(call, path_mdelem, 0); + + grpc_mdstr_ref(channel->authority_string); + authority_mdelem = grpc_mdelem_from_metadata_strings( + channel->metadata_context, channel->authority_string, + grpc_mdstr_from_string(channel->metadata_context, host)); + grpc_call_add_mdelem(call, authority_mdelem, 0); + if (0 != gpr_time_cmp(absolute_deadline, gpr_inf_future)) { grpc_call_op op; op.type = GRPC_SEND_DEADLINE; @@ -118,6 +126,8 @@ void grpc_channel_internal_unref(grpc_channel *channel) { grpc_channel_stack_destroy(CHANNEL_STACK_FROM_CHANNEL(channel)); grpc_mdstr_unref(channel->grpc_status_string); grpc_mdstr_unref(channel->grpc_message_string); + grpc_mdstr_unref(channel->path_string); + grpc_mdstr_unref(channel->authority_string); grpc_mdctx_orphan(channel->metadata_context); gpr_free(channel); } |