From c31be5af4d0bc2a4aceb173da9d802e4f8e20f49 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 8 Nov 2014 16:12:13 +0900 Subject: [PATCH] Assign default priority if dep_stream in PRIORITY does not exist --- lib/nghttp2_session.c | 19 ++++++++++++------- tests/nghttp2_session_test.c | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 9a8d24b5..0b86b455 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -567,11 +567,13 @@ void nghttp2_session_del(nghttp2_session *session) int nghttp2_session_reprioritize_stream (nghttp2_session *session, nghttp2_stream *stream, - const nghttp2_priority_spec *pri_spec) + const nghttp2_priority_spec *pri_spec_in) { int rv; nghttp2_stream *dep_stream; nghttp2_stream *root_stream; + nghttp2_priority_spec pri_spec_default; + const nghttp2_priority_spec *pri_spec = pri_spec_in; if(!nghttp2_stream_in_dep_tree(stream)) { return 0; @@ -582,6 +584,15 @@ int nghttp2_session_reprioritize_stream (session, NGHTTP2_PROTOCOL_ERROR, "depend on itself"); } + if(pri_spec->stream_id != 0) { + dep_stream = nghttp2_session_get_stream_raw(session, pri_spec->stream_id); + + if(!dep_stream || !nghttp2_stream_in_dep_tree(dep_stream)) { + nghttp2_priority_spec_default_init(&pri_spec_default); + pri_spec = &pri_spec_default; + } + } + if(pri_spec->stream_id == 0) { nghttp2_stream_dep_remove_subtree(stream); @@ -602,12 +613,6 @@ int nghttp2_session_reprioritize_stream return rv; } - dep_stream = nghttp2_session_get_stream_raw(session, pri_spec->stream_id); - - if(!dep_stream || !nghttp2_stream_in_dep_tree(dep_stream)) { - return 0; - } - if(nghttp2_stream_dep_subtree_find(stream, dep_stream)) { DEBUGF(fprintf(stderr, "stream: cycle detected, dep_stream(%p)=%d " diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index ac263563..49351db3 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -3074,13 +3074,13 @@ void test_nghttp2_session_reprioritize_stream(void) CU_ASSERT(10 == stream->weight); CU_ASSERT(NULL == stream->dep_prev); - /* dep_stream does not exist */ + /* If dep_stream does not exist, default priority is assigned. */ nghttp2_priority_spec_init(&pri_spec, 3, 99, 0); nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(10 == stream->weight); + CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); CU_ASSERT(NULL == stream->dep_prev); dep_stream = open_stream(session, 3);