diff options
Diffstat (limited to 'src/core/channel')
-rw-r--r-- | src/core/channel/channel_args.c | 36 | ||||
-rw-r--r-- | src/core/channel/channel_args.h | 7 | ||||
-rw-r--r-- | src/core/channel/compress_filter.c | 4 |
3 files changed, 28 insertions, 19 deletions
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 55b4cb6170..54ee75af28 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -167,30 +167,36 @@ static int find_compression_algorithm_states_bitset( } grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( - grpc_channel_args *a, + grpc_channel_args **a, grpc_compression_algorithm algorithm, int state) { int *states_arg; - grpc_channel_args *result = a; + grpc_channel_args *result = *a; const int states_arg_found = - find_compression_algorithm_states_bitset(a, &states_arg); + find_compression_algorithm_states_bitset(*a, &states_arg); - if (!states_arg_found) { + if (states_arg_found) { + if (state != 0) { + GPR_BITSET(states_arg, algorithm); + } else { + GPR_BITCLEAR(states_arg, algorithm); + } + } else { /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; - states_arg = &tmp.value.integer; - result = grpc_channel_args_copy_and_add(a, &tmp, 1); - } - - /* update either the new arg's value or the already present one */ - if (state != 0) { - GPR_BITSET(states_arg, algorithm); - } else { - GPR_BITCLEAR(states_arg, algorithm); + /* all enabled by default */ + tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; + if (state != 0) { + GPR_BITSET(&tmp.value.integer, algorithm); + } else { + GPR_BITCLEAR(&tmp.value.integer, algorithm); + } + result = grpc_channel_args_copy_and_add(*a, &tmp, 1); + grpc_channel_args_destroy(*a); + *a = result; } - return result; } @@ -200,6 +206,6 @@ int grpc_channel_args_compression_algorithm_get_states( if (find_compression_algorithm_states_bitset(a, &states_arg)) { return *states_arg; } else { - return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */ + return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */ } } diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h index e557f9a9d9..06a6012dee 100644 --- a/src/core/channel/channel_args.h +++ b/src/core/channel/channel_args.h @@ -70,9 +70,12 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( /** Sets the support for the given compression algorithm. By default, all * compression algorithms are enabled. It's an error to disable an algorithm set * by grpc_channel_args_set_compression_algorithm. - * */ + * + * Returns an instance will the updated algorithm states. The \a a pointer is + * modified to point to the returned instance (which may be different from the + * input value of \a a). */ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( - grpc_channel_args *a, + grpc_channel_args **a, grpc_compression_algorithm algorithm, int enabled); diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 39efc08ab5..eb27252d03 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -352,8 +352,8 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master, /* TODO(dgq): gpr_strjoin_sep could be made to work with statically allocated * arrays, as to avoid the heap allocs */ accept_encoding_str = - gpr_strjoin_sep(supported_algorithms_names, supported_algorithms_idx, - ", ", &accept_encoding_str_len); + gpr_strjoin_sep(supported_algorithms_names, supported_algorithms_idx, ",", + &accept_encoding_str_len); channeld->mdelem_accept_encoding = grpc_mdelem_from_metadata_strings( mdctx, GRPC_MDSTR_REF(channeld->mdstr_compression_capabilities_key), |