From ee158fb0aa42ad6bfc1282323c62a7498fdcf2c1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 13 Dec 2014 01:18:15 +0900 Subject: [PATCH] Add nghttp2_session_{set,get}_next_stream_id API function --- lib/includes/nghttp2/nghttp2.h | 26 ++++++++++++++++++++++++++ lib/nghttp2_session.c | 15 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index a76e9655..4af8a560 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -2435,6 +2435,32 @@ int nghttp2_session_terminate_session2(nghttp2_session *session, uint32_t nghttp2_session_get_remote_settings(nghttp2_session *session, nghttp2_settings_id id); +/** + * @function + * + * Tells the |session| that next stream ID is |next_stream_id|. The + * |next_stream_id| must be equal or greater than the value returned + * by `nghttp2_session_get_next_stream_id()`. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` + * The |next_stream_id| is strictly less than the value + * `nghttp2_session_get_next_stream_id()` returns. + */ +int nghttp2_session_set_next_stream_id(nghttp2_session *session, + int32_t next_stream_id); + +/** + * @function + * + * Returns the next outgoing stream ID. Notice that return type is + * uint32_t. If we run out of stream ID for this session, this + * function returns 1 << 31. + */ +uint32_t nghttp2_session_get_next_stream_id(nghttp2_session *session); + /** * @function * diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 8d5e8ddc..e7886171 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -6158,3 +6158,18 @@ int nghttp2_session_consume(nghttp2_session *session, int32_t stream_id, return 0; } + +int nghttp2_session_set_next_stream_id(nghttp2_session *session, + int32_t next_stream_id) { + if (next_stream_id < 0 || + session->next_stream_id > (uint32_t)next_stream_id) { + return NGHTTP2_ERR_INVALID_ARGUMENT; + } + + session->next_stream_id = next_stream_id; + return 0; +} + +uint32_t nghttp2_session_get_next_stream_id(nghttp2_session *session) { + return session->next_stream_id; +}