diff options
author | Craig Tiller <ctiller@google.com> | 2017-07-19 13:34:31 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-07-19 13:34:31 -0700 |
commit | 2e37d001a3bd56cde5f11083cd7f679a50b49022 (patch) | |
tree | d2c5a892d9607b56d576de6132660cea9e7a48a3 /src/core/ext/filters/max_age | |
parent | 203977925ccf04599336897a694b300d4f922464 (diff) |
Review feedback
Diffstat (limited to 'src/core/ext/filters/max_age')
-rw-r--r-- | src/core/ext/filters/max_age/max_age_filter.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core/ext/filters/max_age/max_age_filter.c b/src/core/ext/filters/max_age/max_age_filter.c index 14565fd530..2a785efc04 100644 --- a/src/core/ext/filters/max_age/max_age_filter.c +++ b/src/core/ext/filters/max_age/max_age_filter.c @@ -245,7 +245,8 @@ static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* arg, connection storms. Note that the MAX_CONNECTION_AGE option without jitter would not create connection storms by itself, but if there happened to be a connection storm it could cause it to repeat at a fixed period. */ -static int add_random_max_connection_age_jitter(int value) { +static grpc_millis +add_random_max_connection_age_jitter_and_convert_to_grpc_millis(int value) { /* generate a random number between 1 - MAX_CONNECTION_AGE_JITTER and 1 + MAX_CONNECTION_AGE_JITTER */ double multiplier = rand() * MAX_CONNECTION_AGE_JITTER * 2.0 / RAND_MAX + @@ -253,7 +254,8 @@ static int add_random_max_connection_age_jitter(int value) { double result = multiplier * value; /* INT_MAX - 0.5 converts the value to float, so that result will not be cast to int implicitly before the comparison. */ - return result > INT_MAX - 0.5 ? INT_MAX : (int)result; + return result > GRPC_MILLIS_INF_FUTURE - 0.5 ? GRPC_MILLIS_INF_FUTURE + : (int)result; } /* Constructor for call_data. */ @@ -283,9 +285,8 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, chand->max_age_grace_timer_pending = false; chand->channel_stack = args->channel_stack; chand->max_connection_age = - DEFAULT_MAX_CONNECTION_AGE_MS == INT_MAX - ? GRPC_MILLIS_INF_FUTURE - : add_random_max_connection_age_jitter(DEFAULT_MAX_CONNECTION_AGE_MS); + add_random_max_connection_age_jitter_and_convert_to_grpc_millis( + DEFAULT_MAX_CONNECTION_AGE_MS); chand->max_connection_age_grace = DEFAULT_MAX_CONNECTION_AGE_GRACE_MS == INT_MAX ? GRPC_MILLIS_INF_FUTURE @@ -299,8 +300,8 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, const int value = grpc_channel_arg_get_integer( &args->channel_args->args[i], MAX_CONNECTION_AGE_INTEGER_OPTIONS); chand->max_connection_age = - value == INT_MAX ? GRPC_MILLIS_INF_FUTURE - : add_random_max_connection_age_jitter(value); + add_random_max_connection_age_jitter_and_convert_to_grpc_millis( + value); } else if (0 == strcmp(args->channel_args->args[i].key, GRPC_ARG_MAX_CONNECTION_AGE_GRACE_MS)) { const int value = grpc_channel_arg_get_integer( |