Comments and derived bugfixes.

pull/2533/head
David Garcia Quintas 10 years ago
parent d6fd3dbb78
commit cb30410b10
  1. 48
      src/core/channel/channel_args.c
  2. 9
      src/core/channel/compress_filter.c
  3. 27
      src/cpp/server/server.cc

@ -148,44 +148,58 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm(
return grpc_channel_args_copy_and_add(a, &tmp, 1);
}
/** Returns the compression algorithm's enabled states bitset from \a a. If not
* found, return a biset with all algorithms enabled */
static gpr_uint32 find_compression_algorithm_states_bitset(
const grpc_channel_args *a) {
gpr_uint32 states_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1;
/** Returns 1 if the argument for compression algorithm's enabled states bitset
* was found in \a a, returning the arg's value in \a states. Otherwise, returns
* 0. */
static int find_compression_algorithm_states_bitset(
const grpc_channel_args *a, int **states_arg) {
if (a != NULL) {
size_t i;
for (i = 0; i < a->num_args; ++i) {
if (a->args[i].type == GRPC_ARG_INTEGER &&
!strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) {
states_bitset = a->args[i].value.integer;
break;
*states_arg = &a->args[i].value.integer;
return 1; /* GPR_TRUE */
}
}
}
return states_bitset;
return 0; /* GPR_FALSE */
}
grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
grpc_channel_args *a,
grpc_compression_algorithm algorithm,
int state) {
gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a);
grpc_arg tmp;
int *states_arg;
grpc_channel_args *result = a;
const int states_arg_found =
find_compression_algorithm_states_bitset(a, &states_arg);
if (!states_arg_found) {
/* 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_bitset, algorithm);
GPR_BITSET(states_arg, algorithm);
} else {
GPR_BITCLEAR(&states_bitset, algorithm);
GPR_BITCLEAR(states_arg, algorithm);
}
tmp.type = GRPC_ARG_INTEGER;
tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG;
tmp.value.integer = states_bitset;
return grpc_channel_args_copy_and_add(a, &tmp, 1);
return result;
}
int grpc_channel_args_compression_algorithm_get_states(
const grpc_channel_args *a) {
return find_compression_algorithm_states_bitset(a);
int *states_arg;
if (find_compression_algorithm_states_bitset(a, &states_arg)) {
return *states_arg;
} else {
return (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; /* All algs. enabled */
}
}

@ -306,6 +306,7 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
channel_data *channeld = elem->channel_data;
grpc_compression_algorithm algo_idx;
const char *supported_algorithms_names[GRPC_COMPRESS_ALGORITHMS_COUNT - 1];
size_t supported_algorithms_idx = 0;
char *accept_encoding_str;
size_t accept_encoding_str_len;
@ -344,15 +345,15 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key),
grpc_mdstr_from_string(mdctx, algorithm_name, 0));
if (algo_idx > 0) {
supported_algorithms_names[algo_idx - 1] = algorithm_name;
supported_algorithms_names[supported_algorithms_idx++] = algorithm_name;
}
}
/* 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, GPR_ARRAY_SIZE(supported_algorithms_names),
", ", &accept_encoding_str_len);
accept_encoding_str =
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),

@ -187,21 +187,22 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
static grpc_server* CreateServer(
int max_message_size, const grpc_compression_options& compression_options) {
grpc_arg args[2];
size_t args_idx = 0;
if (max_message_size > 0) {
grpc_arg args[2];
args[0].type = GRPC_ARG_INTEGER;
args[0].key = const_cast<char*>(GRPC_ARG_MAX_MESSAGE_LENGTH);
args[0].value.integer = max_message_size;
args[1].type = GRPC_ARG_INTEGER;
args[1].key = const_cast<char*>(GRPC_COMPRESSION_ALGORITHM_STATE_ARG);
args[1].value.integer = compression_options.enabled_algorithms_bitset;
grpc_channel_args channel_args = {2, args};
return grpc_server_create(&channel_args, nullptr);
} else {
return grpc_server_create(nullptr, nullptr);
args[args_idx].type = GRPC_ARG_INTEGER;
args[args_idx].key = const_cast<char*>(GRPC_ARG_MAX_MESSAGE_LENGTH);
args[args_idx].value.integer = max_message_size;
args_idx++;
}
args[args_idx].type = GRPC_ARG_INTEGER;
args[args_idx].key = const_cast<char*>(GRPC_COMPRESSION_ALGORITHM_STATE_ARG);
args[args_idx].value.integer = compression_options.enabled_algorithms_bitset;
args_idx++;
grpc_channel_args channel_args = {args_idx, args};
return grpc_server_create(&channel_args, nullptr);
}
Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,

Loading…
Cancel
Save