3030#include "nghttp2_session.h"
3131#include "nghttp2_helper.h"
3232#include "nghttp2_debug.h"
33+ #include "nghttp2_frame.h"
3334
3435/* Maximum distance between any two stream's cycle in the same
3536 prirority queue. Imagine stream A's cycle is A, and stream B's
4041 words, B is really greater than or equal to A. Otherwise, A is a
4142 result of overflow, and it is actually A > B if we consider that
4243 fact. */
43- #define NGHTTP2_MAX_CYCLE_DISTANCE (16384 * 256 + 255)
44+ #define NGHTTP2_MAX_CYCLE_DISTANCE \
45+ ((uint64_t)NGHTTP2_MAX_FRAME_SIZE_MAX * 256 + 255)
4446
4547static int stream_less (const void * lhsx , const void * rhsx ) {
4648 const nghttp2_stream * lhs , * rhs ;
@@ -52,11 +54,7 @@ static int stream_less(const void *lhsx, const void *rhsx) {
5254 return lhs -> seq < rhs -> seq ;
5355 }
5456
55- if (lhs -> cycle < rhs -> cycle ) {
56- return rhs -> cycle - lhs -> cycle <= NGHTTP2_MAX_CYCLE_DISTANCE ;
57- }
58-
59- return lhs -> cycle - rhs -> cycle > NGHTTP2_MAX_CYCLE_DISTANCE ;
57+ return rhs -> cycle - lhs -> cycle <= NGHTTP2_MAX_CYCLE_DISTANCE ;
6058}
6159
6260void nghttp2_stream_init (nghttp2_stream * stream , int32_t stream_id ,
@@ -135,14 +133,14 @@ static int stream_subtree_active(nghttp2_stream *stream) {
135133/*
136134 * Returns next cycle for |stream|.
137135 */
138- static void stream_next_cycle (nghttp2_stream * stream , uint32_t last_cycle ) {
139- uint32_t penalty ;
136+ static void stream_next_cycle (nghttp2_stream * stream , uint64_t last_cycle ) {
137+ uint64_t penalty ;
140138
141- penalty = (uint32_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT +
139+ penalty = (uint64_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT +
142140 stream -> pending_penalty ;
143141
144142 stream -> cycle = last_cycle + penalty / (uint32_t )stream -> weight ;
145- stream -> pending_penalty = penalty % (uint32_t )stream -> weight ;
143+ stream -> pending_penalty = ( uint32_t )( penalty % (uint32_t )stream -> weight ) ;
146144}
147145
148146static int stream_obq_push (nghttp2_stream * dep_stream , nghttp2_stream * stream ) {
@@ -153,7 +151,7 @@ static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) {
153151 stream_next_cycle (stream , dep_stream -> descendant_last_cycle );
154152 stream -> seq = dep_stream -> descendant_next_seq ++ ;
155153
156- DEBUGF ("stream: stream=%d obq push cycle=%d \n" , stream -> stream_id ,
154+ DEBUGF ("stream: stream=%d obq push cycle=%lu \n" , stream -> stream_id ,
157155 stream -> cycle );
158156
159157 DEBUGF ("stream: push stream %d to stream %d\n" , stream -> stream_id ,
@@ -239,7 +237,7 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) {
239237
240238 nghttp2_pq_push (& dep_stream -> obq , & stream -> pq_entry );
241239
242- DEBUGF ("stream: stream=%d obq resched cycle=%d \n" , stream -> stream_id ,
240+ DEBUGF ("stream: stream=%d obq resched cycle=%lu \n" , stream -> stream_id ,
243241 stream -> cycle );
244242
245243 dep_stream -> last_writelen = stream -> last_writelen ;
@@ -248,9 +246,9 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) {
248246
249247void nghttp2_stream_change_weight (nghttp2_stream * stream , int32_t weight ) {
250248 nghttp2_stream * dep_stream ;
251- uint32_t last_cycle ;
249+ uint64_t last_cycle ;
252250 int32_t old_weight ;
253- uint32_t wlen_penalty ;
251+ uint64_t wlen_penalty ;
254252
255253 if (stream -> weight == weight ) {
256254 return ;
@@ -273,7 +271,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) {
273271
274272 nghttp2_pq_remove (& dep_stream -> obq , & stream -> pq_entry );
275273
276- wlen_penalty = (uint32_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT ;
274+ wlen_penalty = (uint64_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT ;
277275
278276 /* Compute old stream->pending_penalty we used to calculate
279277 stream->cycle */
@@ -289,17 +287,16 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) {
289287 place */
290288 stream_next_cycle (stream , last_cycle );
291289
292- if (stream -> cycle < dep_stream -> descendant_last_cycle &&
293- (dep_stream -> descendant_last_cycle - stream -> cycle ) <=
294- NGHTTP2_MAX_CYCLE_DISTANCE ) {
290+ if (dep_stream -> descendant_last_cycle - stream -> cycle <=
291+ NGHTTP2_MAX_CYCLE_DISTANCE ) {
295292 stream -> cycle = dep_stream -> descendant_last_cycle ;
296293 }
297294
298295 /* Continue to use same stream->seq */
299296
300297 nghttp2_pq_push (& dep_stream -> obq , & stream -> pq_entry );
301298
302- DEBUGF ("stream: stream=%d obq resched cycle=%d \n" , stream -> stream_id ,
299+ DEBUGF ("stream: stream=%d obq resched cycle=%lu \n" , stream -> stream_id ,
303300 stream -> cycle );
304301}
305302
0 commit comments