Add GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED

pull/10494/head
Yuchen Zeng 8 years ago
parent 6cb260af72
commit aaa779e57c
  1. 23
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  2. 1
      src/core/ext/transport/chttp2/transport/internal.h

@ -544,9 +544,9 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time), gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC)); &t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
} else { } else {
/* Use GRPC_CHTTP2_KEEPALIVE_STATE_DYING to indicate there are no inflight /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no
keeaplive timers */ inflight keeaplive timers */
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED;
} }
grpc_chttp2_initiate_write(exec_ctx, t, false, "init"); grpc_chttp2_initiate_write(exec_ctx, t, false, "init");
@ -596,19 +596,18 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx,
GRPC_ERROR_REF(error), "close_transport"); GRPC_ERROR_REF(error), "close_transport");
grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error)); grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error));
switch (t->keepalive_state) { switch (t->keepalive_state) {
case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: { case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING:
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
break; break;
} case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING:
case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING: {
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer); grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer); grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer);
break; break;
} case GRPC_CHTTP2_KEEPALIVE_STATE_DYING:
case GRPC_CHTTP2_KEEPALIVE_STATE_DYING: { case GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED:
/* keepalive timers are not set in these two states */
break; break;
} }
}
/* flush writable stream list to avoid dangling references */ /* flush writable stream list to avoid dangling references */
grpc_chttp2_stream *s; grpc_chttp2_stream *s;
@ -2269,7 +2268,9 @@ static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) { grpc_error *error) {
grpc_chttp2_transport *t = arg; grpc_chttp2_transport *t = arg;
GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING);
if (error == GRPC_ERROR_NONE && !(t->destroying || t->closed)) { if (t->destroying || t->closed) {
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
} else if (error == GRPC_ERROR_NONE) {
if (t->keepalive_permit_without_calls || if (t->keepalive_permit_without_calls ||
grpc_chttp2_stream_map_size(&t->stream_map) > 0) { grpc_chttp2_stream_map_size(&t->stream_map) > 0) {
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING; t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING;
@ -2284,7 +2285,7 @@ static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time), gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC)); &t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
} }
} else if (error == GRPC_ERROR_CANCELLED && !(t->destroying || t->closed)) { } else if (error == GRPC_ERROR_CANCELLED) {
/* The keepalive ping timer may be cancelled by bdp */ /* The keepalive ping timer may be cancelled by bdp */
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
grpc_timer_init( grpc_timer_init(

@ -222,6 +222,7 @@ typedef enum {
GRPC_CHTTP2_KEEPALIVE_STATE_WAITING, GRPC_CHTTP2_KEEPALIVE_STATE_WAITING,
GRPC_CHTTP2_KEEPALIVE_STATE_PINGING, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING,
GRPC_CHTTP2_KEEPALIVE_STATE_DYING, GRPC_CHTTP2_KEEPALIVE_STATE_DYING,
GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED,
} grpc_chttp2_keepalive_state; } grpc_chttp2_keepalive_state;
struct grpc_chttp2_transport { struct grpc_chttp2_transport {

Loading…
Cancel
Save