aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-08-19 15:50:54 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-08-19 15:50:54 -0700
commitcb30410b1063845cc3a0205741a72c9c96e07638 (patch)
tree0ab76611c40261b1c5ca442064e81412261e9ff4 /src
parentd6fd3dbb78093070c1c97f867f2b6f4d0ed8da5b (diff)
Comments and derived bugfixes.
Diffstat (limited to 'src')
-rw-r--r--src/core/channel/channel_args.c48
-rw-r--r--src/core/channel/compress_filter.c9
-rw-r--r--src/cpp/server/server.cc27
3 files changed, 50 insertions, 34 deletions
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c
index 4a18246e7c..55b4cb6170 100644
--- a/src/core/channel/channel_args.c
+++ b/src/core/channel/channel_args.c
@@ -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 */
+ }
}
diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c
index 68060f9da3..0729b5cf5a 100644
--- a/src/core/channel/compress_filter.c
+++ b/src/core/channel/compress_filter.c
@@ -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),
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 3e9ba5c076..eb2a984993 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -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,