diff --git a/lib/nghttp2_stream.c b/lib/nghttp2_stream.c index 904c293e..dc3a6b11 100644 --- a/lib/nghttp2_stream.c +++ b/lib/nghttp2_stream.c @@ -30,6 +30,7 @@ #include "nghttp2_session.h" #include "nghttp2_helper.h" #include "nghttp2_debug.h" +#include "nghttp2_frame.h" /* Maximum distance between any two stream's cycle in the same prirority queue. Imagine stream A's cycle is A, and stream B's @@ -40,7 +41,8 @@ words, B is really greater than or equal to A. Otherwise, A is a result of overflow, and it is actually A > B if we consider that fact. */ -#define NGHTTP2_MAX_CYCLE_DISTANCE (16384 * 256 + 255) +#define NGHTTP2_MAX_CYCLE_DISTANCE \ + ((uint64_t)NGHTTP2_MAX_FRAME_SIZE_MAX * 256 + 255) static int stream_less(const void *lhsx, const void *rhsx) { const nghttp2_stream *lhs, *rhs; @@ -131,14 +133,14 @@ static int stream_subtree_active(nghttp2_stream *stream) { /* * Returns next cycle for |stream|. */ -static void stream_next_cycle(nghttp2_stream *stream, uint32_t last_cycle) { - uint32_t penalty; +static void stream_next_cycle(nghttp2_stream *stream, uint64_t last_cycle) { + uint64_t penalty; - penalty = (uint32_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT + + penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT + stream->pending_penalty; stream->cycle = last_cycle + penalty / (uint32_t)stream->weight; - stream->pending_penalty = penalty % (uint32_t)stream->weight; + stream->pending_penalty = (uint32_t)(penalty % (uint32_t)stream->weight); } static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) { @@ -149,7 +151,7 @@ static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) { stream_next_cycle(stream, dep_stream->descendant_last_cycle); stream->seq = dep_stream->descendant_next_seq++; - DEBUGF("stream: stream=%d obq push cycle=%d\n", stream->stream_id, + DEBUGF("stream: stream=%d obq push cycle=%lu\n", stream->stream_id, stream->cycle); DEBUGF("stream: push stream %d to stream %d\n", stream->stream_id, @@ -235,7 +237,7 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) { nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - DEBUGF("stream: stream=%d obq resched cycle=%d\n", stream->stream_id, + DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, stream->cycle); dep_stream->last_writelen = stream->last_writelen; @@ -244,9 +246,9 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) { void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_stream *dep_stream; - uint32_t last_cycle; + uint64_t last_cycle; int32_t old_weight; - uint32_t wlen_penalty; + uint64_t wlen_penalty; if (stream->weight == weight) { return; @@ -269,7 +271,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry); - wlen_penalty = (uint32_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT; + wlen_penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT; /* Compute old stream->pending_penalty we used to calculate stream->cycle */ @@ -285,9 +287,8 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { place */ stream_next_cycle(stream, last_cycle); - if (stream->cycle < dep_stream->descendant_last_cycle && - (dep_stream->descendant_last_cycle - stream->cycle) <= - NGHTTP2_MAX_CYCLE_DISTANCE) { + if (dep_stream->descendant_last_cycle - stream->cycle <= + NGHTTP2_MAX_CYCLE_DISTANCE) { stream->cycle = dep_stream->descendant_last_cycle; } @@ -295,7 +296,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - DEBUGF("stream: stream=%d obq resched cycle=%d\n", stream->stream_id, + DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, stream->cycle); } diff --git a/lib/nghttp2_stream.h b/lib/nghttp2_stream.h index fb8dc14d..a1b807d2 100644 --- a/lib/nghttp2_stream.h +++ b/lib/nghttp2_stream.h @@ -148,9 +148,9 @@ struct nghttp2_stream { /* Received body so far */ int64_t recv_content_length; /* Base last_cycle for direct descendent streams. */ - uint32_t descendant_last_cycle; + uint64_t descendant_last_cycle; /* Next scheduled time to sent item */ - uint32_t cycle; + uint64_t cycle; /* Next seq used for direct descendant streams */ uint64_t descendant_next_seq; /* Secondary key for prioritization to break a tie for cycle. This