diff options
Diffstat (limited to 'src/core/ext/transport/chttp2')
5 files changed, 67 insertions, 31 deletions
diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index e24e19d903..f0dccefeee 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -31,6 +31,7 @@ #include <grpc/support/log.h> #include <grpc/support/string_util.h> +#include "src/core/ext/transport/chttp2/transport/context_list.h" #include "src/core/ext/transport/chttp2/transport/frame_data.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include "src/core/ext/transport/chttp2/transport/varint.h" @@ -155,6 +156,7 @@ bool g_flow_control_enabled = true; */ static void destruct_transport(grpc_chttp2_transport* t) { + gpr_log(GPR_INFO, "destruct transport %p", t); size_t i; grpc_endpoint_destroy(t->ep); @@ -164,6 +166,8 @@ static void destruct_transport(grpc_chttp2_transport* t) { grpc_slice_buffer_destroy_internal(&t->outbuf); grpc_chttp2_hpack_compressor_destroy(&t->hpack_compressor); + grpc_core::ContextList::Execute(t->cl, nullptr, GRPC_ERROR_NONE); + grpc_slice_buffer_destroy_internal(&t->read_buffer); grpc_chttp2_hpack_parser_destroy(&t->hpack_parser); grpc_chttp2_goaway_parser_destroy(&t->goaway_parser); @@ -236,7 +240,7 @@ static void init_transport(grpc_chttp2_transport* t, size_t i; int j; - grpc_tcp_set_write_timestamps_callback(ContextList::Execute); + grpc_tcp_set_write_timestamps_callback(grpc_core::ContextList::Execute); GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) == GRPC_CHTTP2_CLIENT_CONNECT_STRLEN); @@ -1027,13 +1031,16 @@ static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { static void write_action(void* gt, grpc_error* error) { GPR_TIMER_SCOPE("write_action", 0); grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(gt); - void *cl = t->cl; + void* cl = t->cl; t->cl = nullptr; + if (cl) { + gpr_log(GPR_INFO, "cleared for write"); + } grpc_endpoint_write( t->ep, &t->outbuf, GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, - grpc_combiner_scheduler(t->combiner)), cl - ); + grpc_combiner_scheduler(t->combiner)), + cl); } /* Callback from the grpc_endpoint after bytes have been written by calling @@ -1357,7 +1364,7 @@ static void perform_stream_op_locked(void* stream_op, GRPC_STATS_INC_HTTP2_OP_BATCHES(); - s->context = op->context; + s->context = op->payload->context; if (grpc_http_trace.enabled()) { char* str = grpc_transport_stream_op_batch_string(op); gpr_log(GPR_INFO, "perform_stream_op_locked: %s; on_complete = %p", str, diff --git a/src/core/ext/transport/chttp2/transport/context_list.cc b/src/core/ext/transport/chttp2/transport/context_list.cc index 69ecca09ab..7bfc947ebb 100644 --- a/src/core/ext/transport/chttp2/transport/context_list.cc +++ b/src/core/ext/transport/chttp2/transport/context_list.cc @@ -21,22 +21,32 @@ #include "src/core/ext/transport/chttp2/transport/context_list.h" namespace { -void (*cb)(void *, grpc_core::Timestamps*); +void (*cb)(void*, grpc_core::Timestamps*) = nullptr; } -void ContextList::Execute(ContextList *head, grpc_core::Timestamps *ts, grpc_error* error) { - ContextList *ptr; - while(head != nullptr) { - if(error == GRPC_ERROR_NONE) { - cb(head->context, ts); +namespace grpc_core { +void ContextList::Execute(void* arg, grpc_core::Timestamps* ts, + grpc_error* error) { + gpr_log(GPR_INFO, "execute"); + ContextList* head = static_cast<ContextList*>(arg); + ContextList* ptr; + while (head != nullptr) { + if (error == GRPC_ERROR_NONE && ts != nullptr) { + if (cb) { + cb(head->s->context, ts); + } } + gpr_log(GPR_INFO, "one iteration %p %p", head, arg); + // GRPC_CHTTP2_STREAM_UNREF(static_cast<grpc_chttp2_stream *>(head->s), + // "timestamp exec"); ptr = head; - head_ = head->next; + head = head->next; gpr_free(ptr); } } - -grpc_http2_set_write_timestamps_callback(void (*fn)(void *, grpc_core::Timestamps *)) { +void grpc_http2_set_write_timestamps_callback( + void (*fn)(void*, grpc_core::Timestamps*)) { cb = fn; } +} /* namespace grpc_core */ diff --git a/src/core/ext/transport/chttp2/transport/context_list.h b/src/core/ext/transport/chttp2/transport/context_list.h index 5411cf6bd8..26b8da413e 100644 --- a/src/core/ext/transport/chttp2/transport/context_list.h +++ b/src/core/ext/transport/chttp2/transport/context_list.h @@ -21,44 +21,55 @@ #include <grpc/support/port_platform.h> +#include "src/core/lib/iomgr/buffer_list.h" + +#include "src/core/ext/transport/chttp2/transport/internal.h" + namespace grpc_core { /** A list of RPC Contexts */ -class ContextList {\ +class ContextList { public: /* Creates a new element with \a context as the value and appends it to the * list. */ - void Append(ContextList **head, void *context) { + static void Append(ContextList** head, grpc_chttp2_stream* s) { /* Make sure context is not already present */ - ContextList *ptr = *head; - while(ptr != nullptr) { - if(ptr->context == context) { + ContextList* ptr = *head; + // GRPC_CHTTP2_STREAM_REF(s, "timestamp"); + while (ptr != nullptr) { + if (ptr->s == s) { GPR_ASSERT(false); } + ptr = ptr->next; } - ContextList *elem = static_cast<ContextListElement *>(gpr_malloc(sizeof(ContextList))); - elem->context = context; + ContextList* elem = + static_cast<ContextList*>(gpr_malloc(sizeof(ContextList))); + elem->s = s; elem->next = nullptr; - if(*head_ == nullptr) { + if (*head == nullptr) { *head = elem; + gpr_log(GPR_INFO, "new head"); + gpr_log(GPR_INFO, "append %p %p", elem, *head); return; } + gpr_log(GPR_INFO, "append %p %p", elem, *head); ptr = *head; - while(ptr->next != nullptr) { + while (ptr->next != nullptr) { ptr = ptr->next; } ptr->next = elem; } - /* Executes a function \a fn with each context in the list and \a arg. It also + /* Executes a function \a fn with each context in the list and \a ts. It also * frees up the entire list after this operation. */ - void Execute(ContextList *head, grpc_core::Timestamps *ts, grpc_error* error); + static void Execute(void* arg, grpc_core::Timestamps* ts, grpc_error* error); private: - void *context; - ContextListElement *next; + grpc_chttp2_stream* s; + ContextList* next; }; -grpc_http2_set_write_timestamps_callback(void (*fn)(void *, grpc_core::Timestamps*)); +void grpc_http2_set_write_timestamps_callback( + void (*fn)(void*, grpc_core::Timestamps*)); } /* namespace grpc_core */ #endif /* GRPC_CORE_EXT_TRANSPORT_CONTEXT_LIST_H */ diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 78595a6a4a..32a13df48c 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -44,6 +44,10 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/transport_impl.h" +namespace grpc_core { +class ContextList; +} + /* streams are kept in various linked lists depending on what things need to happen to them... this enum labels each list */ typedef enum { @@ -469,7 +473,7 @@ struct grpc_chttp2_transport { bool keepalive_permit_without_calls; /** keep-alive state machine state */ grpc_chttp2_keepalive_state keepalive_state; - ContextList *cl; + grpc_core::ContextList* cl; }; typedef enum { @@ -480,7 +484,7 @@ typedef enum { } grpc_published_metadata_method; struct grpc_chttp2_stream { - void *context; + void* context; grpc_chttp2_transport* t; grpc_stream_refcount* refcount; diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 51d62f4f60..c9273f7e39 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -18,6 +18,7 @@ #include <grpc/support/port_platform.h> +#include "src/core/ext/transport/chttp2/transport/context_list.h" #include "src/core/ext/transport/chttp2/transport/internal.h" #include <limits.h> @@ -487,7 +488,10 @@ class StreamWriteContext { return; // early out: nothing to do } - ContextList::Append(&t_->cl, s_->context); + if (/* traced && */ grpc_endpoint_can_track_err(t_->ep)) { + gpr_log(GPR_INFO, "for transport %p", t_); + grpc_core::ContextList::Append(&t_->cl, s_); + } while ((s_->flow_controlled_buffer.length > 0 || s_->compressed_data_buffer.length > 0) && data_send_context.max_outgoing() > 0) { |