Fix bug that nghttp2_session_find_stream(session, 0) returned NULL

Previously, nghttp2_session_find_stream(session, 0) returned NULL
despite the fact that documentation said that it should return root
stream.  Now it is corrected, and it returns root stream as
documented.
This commit is contained in:
Tatsuhiro Tsujikawa 2015-11-24 22:30:12 +09:00
parent c44ee44cc3
commit b53b1381b7
4 changed files with 35 additions and 0 deletions

View File

@ -6768,6 +6768,10 @@ int32_t nghttp2_session_get_last_proc_stream_id(nghttp2_session *session) {
nghttp2_stream *nghttp2_session_find_stream(nghttp2_session *session,
int32_t stream_id) {
if (stream_id == 0) {
return &session->root;
}
return nghttp2_session_get_stream_raw(session, stream_id);
}

View File

@ -251,6 +251,8 @@ int main(int argc _U_, char *argv[] _U_) {
test_nghttp2_session_stream_get_state) ||
!CU_add_test(pSuite, "session_stream_get_something",
test_nghttp2_session_stream_get_something) ||
!CU_add_test(pSuite, "session_find_stream",
test_nghttp2_session_find_stream) ||
!CU_add_test(pSuite, "session_keep_closed_stream",
test_nghttp2_session_keep_closed_stream) ||
!CU_add_test(pSuite, "session_keep_idle_stream",

View File

@ -7439,6 +7439,34 @@ void test_nghttp2_session_stream_get_something(void) {
nghttp2_session_del(session);
}
void test_nghttp2_session_find_stream(void) {
nghttp2_session *session;
nghttp2_session_callbacks callbacks;
nghttp2_stream *stream;
memset(&callbacks, 0, sizeof(callbacks));
nghttp2_session_server_new(&session, &callbacks, NULL);
open_stream(session, 1);
stream = nghttp2_session_find_stream(session, 1);
CU_ASSERT(NULL != stream);
CU_ASSERT(1 == stream->stream_id);
stream = nghttp2_session_find_stream(session, 0);
CU_ASSERT(&session->root == stream);
CU_ASSERT(0 == stream->stream_id);
stream = nghttp2_session_find_stream(session, 2);
CU_ASSERT(NULL == stream);
nghttp2_session_del(session);
}
void test_nghttp2_session_keep_closed_stream(void) {
nghttp2_session *session;
nghttp2_session_callbacks callbacks;

View File

@ -117,6 +117,7 @@ void test_nghttp2_session_stream_attach_item(void);
void test_nghttp2_session_stream_attach_item_subtree(void);
void test_nghttp2_session_stream_get_state(void);
void test_nghttp2_session_stream_get_something(void);
void test_nghttp2_session_find_stream(void);
void test_nghttp2_session_keep_closed_stream(void);
void test_nghttp2_session_keep_idle_stream(void);
void test_nghttp2_session_detach_idle_stream(void);