From a51cdaacfcca9e8f3c2d5e72345ac82845d9d72c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 29 Aug 2013 21:45:10 +0900 Subject: [PATCH] Add int return value to nghttp2_before_frame_send_callback --- lib/includes/nghttp2/nghttp2.h | 7 ++++++- lib/nghttp2_session.c | 10 ++++++---- src/shrpx_spdy_session.cc | 9 +++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 2b85e913..e60b3368 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -850,8 +850,13 @@ typedef int (*nghttp2_on_data_recv_callback) * HEADERS and PUSH_PROMISE frame (see also * `nghttp2_session_get_stream_user_data()`), which is not assigned * when it was queued. + * + * 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_before_frame_send_callback) +typedef int (*nghttp2_before_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 4d811121..791c090b 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1496,10 +1496,12 @@ int nghttp2_session_send(nghttp2_session *session) /* Call before_send callback */ if(item->frame_cat == NGHTTP2_CAT_CTRL && session->callbacks.before_frame_send_callback) { - session->callbacks.before_frame_send_callback - (session, - nghttp2_outbound_item_get_ctrl_frame(item), - session->user_data); + if(session->callbacks.before_frame_send_callback + (session, + nghttp2_outbound_item_get_ctrl_frame(item), + session->user_data) != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } } } data = session->aob.framebuf + session->aob.framebufoff; diff --git a/src/shrpx_spdy_session.cc b/src/shrpx_spdy_session.cc index 5221aef3..12c87ab1 100644 --- a/src/shrpx_spdy_session.cc +++ b/src/shrpx_spdy_session.cc @@ -945,9 +945,9 @@ int on_data_chunk_recv_callback(nghttp2_session *session, } // namespace namespace { -void before_frame_send_callback(nghttp2_session *session, - nghttp2_frame *frame, - void *user_data) +int before_frame_send_callback(nghttp2_session *session, + nghttp2_frame *frame, + void *user_data) { if(frame->hd.type == NGHTTP2_HEADERS && frame->headers.cat == NGHTTP2_HCAT_REQUEST) { @@ -956,7 +956,7 @@ void before_frame_send_callback(nghttp2_session *session, if(!sd || !sd->dconn) { nghttp2_submit_rst_stream(session, frame->hd.stream_id, NGHTTP2_CANCEL); - return; + return 0; } auto downstream = sd->dconn->get_downstream(); if(downstream) { @@ -965,6 +965,7 @@ void before_frame_send_callback(nghttp2_session *session, nghttp2_submit_rst_stream(session, frame->hd.stream_id, NGHTTP2_CANCEL); } } + return 0; } } // namespace