@@ -1961,7 +1961,7 @@ typedef int (*nghttp3_acked_stream_data)(nghttp3_conn *conn, int64_t stream_id,
19611961/**
19621962 * @functypedef
19631963 *
1964- * :type:`nghttp3_conn_stream_close ` is a callback function which is
1964+ * :type:`nghttp3_stream_close ` is a callback function which is
19651965 * invoked when a stream identified by |stream_id| is closed. QUIC
19661966 * application error code |app_error_code| indicates the reason of
19671967 * this closure.
@@ -1970,6 +1970,9 @@ typedef int (*nghttp3_acked_stream_data)(nghttp3_conn *conn, int64_t stream_id,
19701970 * Returning :macro:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the
19711971 * caller immediately. Any values other than 0 is treated as
19721972 * :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`.
1973+ *
1974+ * .. seealso::
1975+ * :type:`nghttp3_stream_close2`
19731976 */
19741977typedef int (* nghttp3_stream_close )(nghttp3_conn * conn , int64_t stream_id ,
19751978 uint64_t app_error_code ,
@@ -2240,10 +2243,80 @@ typedef int (*nghttp3_recv_settings2)(nghttp3_conn *conn,
22402243 const nghttp3_proto_settings * settings ,
22412244 void * conn_user_data );
22422245
2246+ /**
2247+ * @macrosection
2248+ *
2249+ * Stream close flags
2250+ */
2251+
2252+ /**
2253+ * @macro
2254+ *
2255+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_NONE` indicates no flag set.
2256+ *
2257+ * .. version-added:: 1.18.0
2258+ */
2259+ #define NGHTTP3_STREAM_CLOSE_FLAG_NONE 0x00U
2260+
2261+ /**
2262+ * @macro
2263+ *
2264+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` indicates
2265+ * that rx_app_error_code parameter is set.
2266+ *
2267+ * .. version-added:: 1.18.0
2268+ */
2269+ #define NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET 0x01U
2270+
2271+ /**
2272+ * @macro
2273+ *
2274+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` indicates
2275+ * that tx_app_error_code parameter is set.
2276+ *
2277+ * .. version-added:: 1.18.0
2278+ */
2279+ #define NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET 0x02U
2280+
2281+ /**
2282+ * @functypedef
2283+ *
2284+ * :type:`nghttp3_stream_close2` is a callback function which is
2285+ * invoked when a stream identified by |stream_id| is closed. If
2286+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` is set in
2287+ * |flags|, |rx_app_error_code| is the QUIC application error code
2288+ * that shut down the receiving side of the stream. If
2289+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` is set in
2290+ * |flags|, |tx_app_error_code| is the QUIC application error code
2291+ * that shut down the sending side of the stream. No application code
2292+ * means that direction of stream is closed without any error.
2293+ *
2294+ * This callback should be used with `nghttp3_conn_close_stream2`. If
2295+ * `nghttp3_conn_close_stream` is used, the app_error_code is set to
2296+ * both |rx_app_error_code| and |tx_app_error_code|, and
2297+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` and
2298+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` are set in
2299+ * |flags|.
2300+ *
2301+ * The implementation of this callback must return 0 if it succeeds.
2302+ * Returning :macro:`NGHTTP3_ERR_CALLBACK_FAILURE` will return to the
2303+ * caller immediately. Any values other than 0 is treated as
2304+ * :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`.
2305+ *
2306+ * .. version-added:: 1.18.0
2307+ */
2308+ typedef int (* nghttp3_stream_close2 )(nghttp3_conn * conn , uint32_t flags ,
2309+ int64_t stream_id ,
2310+ uint64_t rx_app_error_code ,
2311+ uint64_t tx_app_error_code ,
2312+ void * conn_user_data ,
2313+ void * stream_user_data );
2314+
22432315#define NGHTTP3_CALLBACKS_V1 1
22442316#define NGHTTP3_CALLBACKS_V2 2
22452317#define NGHTTP3_CALLBACKS_V3 3
2246- #define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V3
2318+ #define NGHTTP3_CALLBACKS_V4 4
2319+ #define NGHTTP3_CALLBACKS_VERSION NGHTTP3_CALLBACKS_V4
22472320
22482321/**
22492322 * @struct
@@ -2260,6 +2333,9 @@ typedef struct nghttp3_callbacks {
22602333 /**
22612334 * :member:`stream_close` is a callback function which is invoked
22622335 * when a particular stream has closed.
2336+ *
2337+ * .. seealso::
2338+ * :member:`stream_close2`
22632339 */
22642340 nghttp3_stream_close stream_close ;
22652341 /**
@@ -2368,13 +2444,24 @@ typedef struct nghttp3_callbacks {
23682444 * .. version-added:: 1.11.0
23692445 */
23702446 nghttp3_rand rand ;
2447+ /* The following fields have been added since
2448+ NGHTTP3_CALLBACKS_V3. */
23712449 /**
23722450 * :member:`recv_settings2` is a callback function which is invoked
23732451 * when SETTINGS frame is received.
23742452 *
23752453 * .. version-added:: 1.14.0
23762454 */
23772455 nghttp3_recv_settings2 recv_settings2 ;
2456+ /* The following fields have been added since
2457+ NGHTTP3_CALLBACKS_V4. */
2458+ /**
2459+ * :member:`stream_close2` is a callback function which is invoked
2460+ * when a particular stream has closed.
2461+ *
2462+ * .. version-added:: 1.18.0
2463+ */
2464+ nghttp3_stream_close2 stream_close2 ;
23782465} nghttp3_callbacks ;
23792466
23802467/**
@@ -2837,11 +2924,47 @@ NGHTTP3_EXTERN int nghttp3_conn_resume_stream(nghttp3_conn *conn,
28372924 * A critical stream is closed.
28382925 * :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`
28392926 * User callback failed
2927+ *
2928+ * .. seealso::
2929+ * `nghttp3_conn_close_stream2`
28402930 */
28412931NGHTTP3_EXTERN int nghttp3_conn_close_stream (nghttp3_conn * conn ,
28422932 int64_t stream_id ,
28432933 uint64_t app_error_code );
28442934
2935+ /**
2936+ * @function
2937+ *
2938+ * `nghttp3_conn_close_stream2` tells the library that a stream
2939+ * identified by |stream_id| has been closed. If
2940+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_RX_APP_ERROR_CODE_SET` is set in
2941+ * |flags|, |rx_app_error_code| is the QUIC application error code
2942+ * that shut down the receiving side of the stream. Similarly,
2943+ * :macro:`NGHTTP3_STREAM_CLOSE_FLAG_TX_APP_ERROR_CODE_SET` is set in
2944+ * |flags|, |tx_app_error_code| is the QUIC application error code
2945+ * that shut down the sending side of the stream.
2946+ *
2947+ * For stream close callback, prefer
2948+ * :member:`nghttp3_callbacks.stream_close2` to
2949+ * :member:`nghttp3_callbacks.stream_close`.
2950+ *
2951+ * This function returns 0 if it succeeds, or one of the following
2952+ * negative error codes:
2953+ *
2954+ * :macro:`NGHTTP3_ERR_STREAM_NOT_FOUND`
2955+ * Stream not found.
2956+ * :macro:`NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM`
2957+ * A critical stream is closed.
2958+ * :macro:`NGHTTP3_ERR_CALLBACK_FAILURE`
2959+ * User callback failed
2960+ *
2961+ * .. version-added:: 1.18.0
2962+ */
2963+ NGHTTP3_EXTERN int nghttp3_conn_close_stream2 (nghttp3_conn * conn ,
2964+ uint32_t flags , int64_t stream_id ,
2965+ uint64_t rx_app_error_code ,
2966+ uint64_t tx_app_error_code );
2967+
28452968/**
28462969 * @macrosection
28472970 *
0 commit comments