diff options
author | David G. Quintas <dgq@google.com> | 2015-10-15 13:35:37 -0700 |
---|---|---|
committer | David G. Quintas <dgq@google.com> | 2015-10-15 13:35:37 -0700 |
commit | 8dbc4734d87ad9472cea2065a96d5934e7125af0 (patch) | |
tree | 12250fcaefb4e648882d13a514b0ff92ff3b7fad /src/core | |
parent | 665fbecca5b4d41a14783a101873effbd037573b (diff) | |
parent | 42cc378a4c2a9c729fe9275d90065edd7af9dc3c (diff) |
Merge pull request #3767 from ctiller/cache-accept-enc
Cache encodings accepted by peer on mdelem
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/surface/call.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/core/surface/call.c b/src/core/surface/call.c index cfd6f21d69..81ff215c0c 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -539,12 +539,24 @@ grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( return algorithm; } -static void set_encodings_accepted_by_peer( - grpc_call *call, const gpr_slice accept_encoding_slice) { +static void destroy_encodings_accepted_by_peer(void *p) { return; } + +static void set_encodings_accepted_by_peer(grpc_call *call, grpc_mdelem *mdel) { size_t i; grpc_compression_algorithm algorithm; gpr_slice_buffer accept_encoding_parts; + gpr_slice accept_encoding_slice; + void *accepted_user_data; + + accepted_user_data = + grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); + if (accepted_user_data != NULL) { + call->encodings_accepted_by_peer = + (gpr_uint32)(((gpr_uintptr)accepted_user_data) - 1); + return; + } + accept_encoding_slice = mdel->value->slice; gpr_slice_buffer_init(&accept_encoding_parts); gpr_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); @@ -568,6 +580,12 @@ static void set_encodings_accepted_by_peer( gpr_free(accept_encoding_entry_str); } } + + gpr_slice_buffer_destroy(&accept_encoding_parts); + + grpc_mdelem_set_user_data( + mdel, destroy_encodings_accepted_by_peer, + (void *)(((gpr_uintptr)call->encodings_accepted_by_peer) + 1)); } gpr_uint32 grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { @@ -1549,7 +1567,7 @@ static void recv_metadata(grpc_exec_ctx *exec_ctx, grpc_call *call, } else if (key == grpc_channel_get_encodings_accepted_by_peer_string( call->channel)) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(call, mdel->value->slice); + set_encodings_accepted_by_peer(call, mdel); GPR_TIMER_END("encodings_accepted_by_peer", 0); } else { GPR_TIMER_BEGIN("report_up", 0); |