From 6afb7442b5f31f002cdd195a49c15bc41baedbd8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 31 Mar 2014 23:01:05 +0900 Subject: [PATCH] Adjust weight when pushing data to queue --- lib/nghttp2_stream.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/nghttp2_stream.c b/lib/nghttp2_stream.c index 5c1832a6..a0365fcf 100644 --- a/lib/nghttp2_stream.c +++ b/lib/nghttp2_stream.c @@ -76,6 +76,31 @@ void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag) stream->shut_flags |= flag; } +static int stream_push_data(nghttp2_stream *stream, nghttp2_pq *pq) +{ + int rv; + ssize_t weight; + + assert(stream->data); + assert(stream->data->queued == 0); + + weight = nghttp2_stream_group_shared_wait(stream->stream_group); + + if(stream->data->weight > weight) { + stream->data->weight = weight; + } + + rv = nghttp2_pq_push(pq, stream->data); + + if(rv != 0) { + return rv; + } + + stream->data->queued = 1; + + return 0; +} + static nghttp2_stream* stream_first_sib(nghttp2_stream *stream) { for(; stream->sib_prev; stream = stream->sib_prev); @@ -202,13 +227,11 @@ static ssize_t stream_update_dep_set_top(nghttp2_stream *stream, stream->stream_id)); if(!stream->data->queued) { - rv = nghttp2_pq_push(pq, stream->data); + rv = stream_push_data(stream, pq); if(rv != 0) { return rv; } - - stream->data->queued = 1; } stream->dpri = NGHTTP2_STREAM_DPRI_TOP;