30
30
#include "nghttp2_session.h"
31
31
#include "nghttp2_helper.h"
32
32
#include "nghttp2_debug.h"
33
+ #include "nghttp2_frame.h"
33
34
34
35
/* Maximum distance between any two stream's cycle in the same
35
36
prirority queue. Imagine stream A's cycle is A, and stream B's
40
41
words, B is really greater than or equal to A. Otherwise, A is a
41
42
result of overflow, and it is actually A > B if we consider that
42
43
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)
44
46
45
47
static int stream_less (const void * lhsx , const void * rhsx ) {
46
48
const nghttp2_stream * lhs , * rhs ;
@@ -52,11 +54,7 @@ static int stream_less(const void *lhsx, const void *rhsx) {
52
54
return lhs -> seq < rhs -> seq ;
53
55
}
54
56
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 ;
60
58
}
61
59
62
60
void nghttp2_stream_init (nghttp2_stream * stream , int32_t stream_id ,
@@ -135,14 +133,14 @@ static int stream_subtree_active(nghttp2_stream *stream) {
135
133
/*
136
134
* Returns next cycle for |stream|.
137
135
*/
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 ;
140
138
141
- penalty = (uint32_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT +
139
+ penalty = (uint64_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT +
142
140
stream -> pending_penalty ;
143
141
144
142
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 ) ;
146
144
}
147
145
148
146
static 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) {
153
151
stream_next_cycle (stream , dep_stream -> descendant_last_cycle );
154
152
stream -> seq = dep_stream -> descendant_next_seq ++ ;
155
153
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 ,
157
155
stream -> cycle );
158
156
159
157
DEBUGF ("stream: push stream %d to stream %d\n" , stream -> stream_id ,
@@ -239,7 +237,7 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) {
239
237
240
238
nghttp2_pq_push (& dep_stream -> obq , & stream -> pq_entry );
241
239
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 ,
243
241
stream -> cycle );
244
242
245
243
dep_stream -> last_writelen = stream -> last_writelen ;
@@ -248,9 +246,9 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) {
248
246
249
247
void nghttp2_stream_change_weight (nghttp2_stream * stream , int32_t weight ) {
250
248
nghttp2_stream * dep_stream ;
251
- uint32_t last_cycle ;
249
+ uint64_t last_cycle ;
252
250
int32_t old_weight ;
253
- uint32_t wlen_penalty ;
251
+ uint64_t wlen_penalty ;
254
252
255
253
if (stream -> weight == weight ) {
256
254
return ;
@@ -273,7 +271,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) {
273
271
274
272
nghttp2_pq_remove (& dep_stream -> obq , & stream -> pq_entry );
275
273
276
- wlen_penalty = (uint32_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT ;
274
+ wlen_penalty = (uint64_t )stream -> last_writelen * NGHTTP2_MAX_WEIGHT ;
277
275
278
276
/* Compute old stream->pending_penalty we used to calculate
279
277
stream->cycle */
@@ -289,17 +287,16 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) {
289
287
place */
290
288
stream_next_cycle (stream , last_cycle );
291
289
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 ) {
295
292
stream -> cycle = dep_stream -> descendant_last_cycle ;
296
293
}
297
294
298
295
/* Continue to use same stream->seq */
299
296
300
297
nghttp2_pq_push (& dep_stream -> obq , & stream -> pq_entry );
301
298
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 ,
303
300
stream -> cycle );
304
301
}
305
302
0 commit comments