From 794633f894472c70f058317ed61195073316e004 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 23 Dec 2013 17:40:34 +0900 Subject: [PATCH] Add nghttp2_session_set_stream_user_data API function --- lib/includes/nghttp2/nghttp2.h | 33 ++++++++++++++++++++++++++------- lib/nghttp2_session.c | 13 +++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 66df0077..c163f3ca 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -1577,17 +1577,36 @@ int nghttp2_session_want_write(nghttp2_session *session); * @function * * Returns stream_user_data for the stream |stream_id|. The - * stream_user_data is provided by `nghttp2_submit_request()` or - * `nghttp2_submit_headers()`. If the stream is initiated by the - * remote endpoint, stream_user_data is always ``NULL``. If the stream - * is initiated by the local endpoint and ``NULL`` is given in - * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, then - * this function returns ``NULL``. If the stream does not exist, this - * function returns ``NULL``. + * stream_user_data is provided by `nghttp2_submit_request()`, + * `nghttp2_submit_headers()` or + * `nghttp2_session_set_stream_user_data()`. Unless it is set using + * `nghttp2_session_set_stream_user_data()`, if the stream is + * initiated by the remote endpoint, stream_user_data is always + * ``NULL``. If the stream does not exist, this function returns + * ``NULL``. */ void* nghttp2_session_get_stream_user_data(nghttp2_session *session, int32_t stream_id); +/** + * @function + * + * Sets the |stream_user_data| to the stream denoted by the + * |stream_id|. If a stream user data is already set to the stream, it + * is replaced with the |stream_user_data|. It is valid to specify + * ``NULL`` in the |stream_user_data|, which nullifies the associated + * data pointer. + * + * This function returns 0 if it succeeds, or one of following + * negative error codes: + * + * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` + * The stream does not exist + */ +int nghttp2_session_set_stream_user_data(nghttp2_session *session, + int32_t stream_id, + void *stream_user_data); + /** * @function * diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 463e7bd3..30ac55a8 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -3622,6 +3622,19 @@ void* nghttp2_session_get_stream_user_data(nghttp2_session *session, } } +int nghttp2_session_set_stream_user_data(nghttp2_session *session, + int32_t stream_id, + void *stream_user_data) +{ + nghttp2_stream *stream; + stream = nghttp2_session_get_stream(session, stream_id); + if(!stream) { + return NGHTTP2_ERR_INVALID_ARGUMENT; + } + stream->stream_user_data = stream_user_data; + return 0; +} + int nghttp2_session_resume_data(nghttp2_session *session, int32_t stream_id) { int r;