From d4852b0f1141b723c70c2e77c6c6b552850b85a1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 29 Aug 2013 21:48:34 +0900 Subject: [PATCH] Add int return value to on_frame_send_callback --- lib/includes/nghttp2/nghttp2.h | 7 ++++++- lib/nghttp2_session.c | 6 ++++-- src/HttpServer.cc | 3 ++- src/app_helper.cc | 3 ++- src/app_helper.h | 2 +- src/nghttp.cc | 3 ++- tests/nghttp2_session_test.c | 7 ++++--- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index e60b3368..314538fa 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -863,8 +863,13 @@ typedef int (*nghttp2_before_frame_send_callback) * @functypedef * * Callback function invoked after the non-DATA frame |frame| is sent. + * + * The implementation of this function must return 0 if it + * succeeds. If nonzero is returned, it is treated as fatal error and + * `nghttp2_session_recv()` and `nghttp2_session_send()` functions + * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. */ -typedef void (*nghttp2_on_frame_send_callback) +typedef int (*nghttp2_on_frame_send_callback) (nghttp2_session *session, nghttp2_frame *frame, void *user_data); /** diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 791c090b..4e2da2b6 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1259,8 +1259,10 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session) nghttp2_frame *frame; frame = nghttp2_outbound_item_get_ctrl_frame(session->aob.item); if(session->callbacks.on_frame_send_callback) { - session->callbacks.on_frame_send_callback(session, frame, - session->user_data); + if(session->callbacks.on_frame_send_callback(session, frame, + session->user_data) != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } } switch(frame->hd.type) { case NGHTTP2_HEADERS: { diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 24815298..fa4f558f 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -739,7 +739,7 @@ void htdocs_on_request_recv_callback } namespace { -void hd_on_frame_send_callback +int hd_on_frame_send_callback (nghttp2_session *session, nghttp2_frame *frame, void *user_data) { @@ -748,6 +748,7 @@ void hd_on_frame_send_callback print_session_id(hd->session_id()); on_frame_send_callback(session, frame, user_data); } + return 0; } } // namespace diff --git a/src/app_helper.cc b/src/app_helper.cc index ac77b7d8..20ca5a76 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -389,13 +389,14 @@ void on_unknown_frame_recv_callback(nghttp2_session *session, fflush(stdout); } -void on_frame_send_callback +int on_frame_send_callback (nghttp2_session *session, nghttp2_frame *frame, void *user_data) { print_timer(); printf(" send "); print_frame(PRINT_SEND, frame); fflush(stdout); + return 0; } namespace { diff --git a/src/app_helper.h b/src/app_helper.h index e3a1678c..43c2575a 100644 --- a/src/app_helper.h +++ b/src/app_helper.h @@ -61,7 +61,7 @@ void on_unknown_frame_recv_callback(nghttp2_session *session, size_t payloadlen, void *user_data); -void on_frame_send_callback +int on_frame_send_callback (nghttp2_session *session, nghttp2_frame *frame, void *user_data); int on_data_recv_callback diff --git a/src/nghttp.cc b/src/nghttp.cc index 4babde42..42b86e01 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -978,7 +978,7 @@ void check_stream_id(nghttp2_session *session, int32_t stream_id, } } // namespace -void on_frame_send_callback2 +int on_frame_send_callback2 (nghttp2_session *session, nghttp2_frame *frame, void *user_data) { if(frame->hd.type == NGHTTP2_HEADERS && @@ -988,6 +988,7 @@ void on_frame_send_callback2 if(config.verbose) { on_frame_send_callback(session, frame, user_data); } + return 0; } void check_response_header diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 96f336f0..32ef3166 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -145,13 +145,14 @@ static int on_invalid_frame_recv_callback(nghttp2_session *session, return 0; } -static void on_frame_send_callback(nghttp2_session *session, - nghttp2_frame *frame, - void *user_data) +static int on_frame_send_callback(nghttp2_session *session, + nghttp2_frame *frame, + void *user_data) { my_user_data *ud = (my_user_data*)user_data; ++ud->frame_send_cb_called; ud->sent_frame_type = frame->hd.type; + return 0; } static void on_frame_not_send_callback(nghttp2_session *session,