Use channel arg to enable workaround

pull/10849/head
Muxi Yan 8 years ago
parent 9dd9178f30
commit d64e70a815
  1. 2
      include/grpc/impl/codegen/grpc_types.h
  2. 13
      src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c
  3. 22
      src/core/ext/filters/workarounds/workaround_utils.c
  4. 2
      src/core/ext/filters/workarounds/workaround_utils.h

@ -292,6 +292,8 @@ each time recvmsg (or equivalent) is called */
"grpc.experimental.tcp_min_read_chunk_size"
#define GRPC_ARG_TCP_MAX_READ_CHUNK_SIZE \
"grpc.experimental.tcp_max_read_chunk_size"
/** If non-zero, grpc server's cronet compression workaround will be enabled */
#define GRPC_ARG_WORKAROUND_CRONET_COMPRESSION "grpc.socket_factory"
/** \} */
/** Result of a grpc call. If the caller satisfies the prerequisites of a

@ -206,7 +206,18 @@ const grpc_channel_filter grpc_workaround_cronet_compression_filter = {
static bool register_workaround_cronet_compression(
grpc_exec_ctx* exec_ctx, grpc_channel_stack_builder* builder, void* arg) {
if (!grpc_workaround_is_enabled(GRPC_WORKAROUND_ID_CRONET_COMPRESSION)) {
const grpc_channel_args *channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg *a =
grpc_channel_args_find(channel_args, GRPC_ARG_WORKAROUND_CRONET_COMPRESSION);
if (a == NULL) {
return true;
}
if (a->type != GRPC_ARG_INTEGER) {
gpr_log(GPR_ERROR, "%s ignored: it must be an integer", GRPC_ARG_WORKAROUND_CRONET_COMPRESSION);
return true;
}
if (a->value.integer == 0) {
return true;
}
grpc_register_workaround(GRPC_WORKAROUND_ID_CRONET_COMPRESSION,

@ -36,14 +36,6 @@
static user_agent_parser user_agent_parsers[GRPC_MAX_WORKAROUND_ID];
/* Workarounds enabled by user */
static bool workaround_enabled[GRPC_MAX_WORKAROUND_ID];
/* Workarounds supported by C core */
static bool workaround_supported[GRPC_MAX_WORKAROUND_ID] = {
true /* GRPC_WORKAROUND_ID_CRONET_COMPRESSION */
};
grpc_user_agent_md *grpc_parse_user_agent(grpc_mdelem md) {
grpc_user_agent_md *user_agent_md;
@ -63,17 +55,3 @@ void grpc_register_workaround(uint32_t id, user_agent_parser parser) {
GPR_ASSERT(id < GRPC_MAX_WORKAROUND_ID);
user_agent_parsers[id] = parser;
}
bool grpc_workaround_is_enabled(uint32_t id) {
GPR_ASSERT(id < GRPC_MAX_WORKAROUND_ID);
return workaround_enabled[id];
}
bool grpc_enable_workaround(uint32_t id) {
if (workaround_supported[id]) {
workaround_enabled[id] = true;
return true;
} else {
return false;
}
}

@ -51,6 +51,4 @@ typedef bool (*user_agent_parser)(grpc_mdelem);
void grpc_register_workaround(uint32_t id, user_agent_parser parser);
bool grpc_workaround_is_enabled(uint32_t id);
#endif

Loading…
Cancel
Save