diff options
Diffstat (limited to 'src/core/transport')
-rw-r--r-- | src/core/transport/chttp2_transport.c | 26 | ||||
-rw-r--r-- | src/core/transport/connectivity_state.c | 26 | ||||
-rw-r--r-- | src/core/transport/connectivity_state.h | 6 | ||||
-rw-r--r-- | src/core/transport/transport.h | 2 |
4 files changed, 54 insertions, 6 deletions
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index c923d5e42f..ac8a4665db 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -110,6 +110,8 @@ static void cancel_from_api(grpc_chttp2_transport_global *transport_global, /** Add endpoint from this transport to pollset */ static void add_to_pollset_locked(grpc_chttp2_transport *t, grpc_pollset *pollset); +static void add_to_pollset_set_locked(grpc_chttp2_transport *t, + grpc_pollset_set *pollset_set); /** Start new streams that have been created if we can */ static void maybe_start_some_streams( @@ -233,7 +235,7 @@ static void init_transport(grpc_chttp2_transport *t, is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0; t->writing.is_client = is_client; grpc_connectivity_state_init(&t->channel_callback.state_tracker, - GRPC_CHANNEL_READY); + GRPC_CHANNEL_READY, "transport"); gpr_slice_buffer_init(&t->global.qbuf); @@ -686,6 +688,7 @@ static void send_ping_locked(grpc_chttp2_transport *t, static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt; + int close_transport = 0; lock(t); @@ -705,9 +708,7 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { t->global.last_incoming_stream_id, grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), gpr_slice_ref(*op->goaway_message), &t->global.qbuf); - if (!grpc_chttp2_has_streams(t)) { - close_transport_locked(t); - } + close_transport = !grpc_chttp2_has_streams(t); } if (op->set_accept_stream != NULL) { @@ -720,6 +721,10 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { add_to_pollset_locked(t, op->bind_pollset); } + if (op->bind_pollset_set) { + add_to_pollset_set_locked(t, op->bind_pollset_set); + } + if (op->send_ping) { send_ping_locked(t, op->send_ping); } @@ -729,6 +734,12 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { } unlock(t); + + if (close_transport) { + lock(t); + close_transport_locked(t); + unlock(t); + } } /* @@ -1034,6 +1045,13 @@ static void add_to_pollset_locked(grpc_chttp2_transport *t, } } +static void add_to_pollset_set_locked(grpc_chttp2_transport *t, + grpc_pollset_set *pollset_set) { + if (t->ep) { + grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); + } +} + /* * TRACING */ diff --git a/src/core/transport/connectivity_state.c b/src/core/transport/connectivity_state.c index 1091ceae44..8bc7526e3c 100644 --- a/src/core/transport/connectivity_state.c +++ b/src/core/transport/connectivity_state.c @@ -34,11 +34,27 @@ #include "src/core/transport/connectivity_state.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> +#include <grpc/support/string_util.h> + +int grpc_connectivity_state_trace = 0; + +const char *grpc_connectivity_state_name(grpc_connectivity_state state) { + switch (state) { + case GRPC_CHANNEL_IDLE: return "IDLE"; + case GRPC_CHANNEL_CONNECTING: return "CONNECTING"; + case GRPC_CHANNEL_READY: return "READY"; + case GRPC_CHANNEL_TRANSIENT_FAILURE: return "TRANSIENT_FAILURE"; + case GRPC_CHANNEL_FATAL_FAILURE: return "FATAL_FAILURE"; + } + abort(); + return "UNKNOWN"; +} void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker, - grpc_connectivity_state init_state) { + grpc_connectivity_state init_state, const char *name) { tracker->current_state = init_state; tracker->watchers = NULL; + tracker->name = gpr_strdup(name); } void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker *tracker) { @@ -54,6 +70,7 @@ void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker *tracker) { } gpr_free(w); } + gpr_free(tracker->name); } grpc_connectivity_state grpc_connectivity_state_check( @@ -64,6 +81,9 @@ grpc_connectivity_state grpc_connectivity_state_check( int grpc_connectivity_state_notify_on_state_change( grpc_connectivity_state_tracker *tracker, grpc_connectivity_state *current, grpc_iomgr_closure *notify) { + if (grpc_connectivity_state_trace) { + gpr_log(GPR_DEBUG, "CONWATCH: %s: from %s [cur=%s]", tracker->name, grpc_connectivity_state_name(*current), grpc_connectivity_state_name(tracker->current_state)); + } if (tracker->current_state != *current) { *current = tracker->current_state; grpc_iomgr_add_callback(notify); @@ -82,9 +102,13 @@ void grpc_connectivity_state_set_with_scheduler( void (*scheduler)(void *arg, grpc_iomgr_closure *closure), void *arg) { grpc_connectivity_state_watcher *new = NULL; grpc_connectivity_state_watcher *w; + if (grpc_connectivity_state_trace) { + gpr_log(GPR_DEBUG, "SET: %s: %s --> %s", tracker->name, grpc_connectivity_state_name(tracker->current_state), grpc_connectivity_state_name(state)); + } if (tracker->current_state == state) { return; } + GPR_ASSERT(tracker->current_state != GRPC_CHANNEL_FATAL_FAILURE); tracker->current_state = state; while ((w = tracker->watchers)) { tracker->watchers = w->next; diff --git a/src/core/transport/connectivity_state.h b/src/core/transport/connectivity_state.h index bbdcbcb069..8e40158a5d 100644 --- a/src/core/transport/connectivity_state.h +++ b/src/core/transport/connectivity_state.h @@ -51,10 +51,14 @@ typedef struct { grpc_connectivity_state current_state; /** all our watchers */ grpc_connectivity_state_watcher *watchers; + /** a name to help debugging */ + char *name; } grpc_connectivity_state_tracker; +extern int grpc_connectivity_state_trace; + void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker, - grpc_connectivity_state init_state); + grpc_connectivity_state init_state, const char *name); void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker *tracker); void grpc_connectivity_state_set(grpc_connectivity_state_tracker *tracker, diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index 64503604ee..aac42303a9 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -109,6 +109,8 @@ typedef struct grpc_transport_op { void *set_accept_stream_user_data; /** add this transport to a pollset */ grpc_pollset *bind_pollset; + /** add this transport to a pollset_set */ + grpc_pollset_set *bind_pollset_set; /** send a ping, call this back if not NULL */ grpc_iomgr_closure *send_ping; } grpc_transport_op; |