Commit 053c4447 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Add int return value to nghttp2_on_request_recv_callback

parent 81653c1d
...@@ -928,8 +928,13 @@ typedef int (*nghttp2_on_stream_close_callback) ...@@ -928,8 +928,13 @@ typedef int (*nghttp2_on_stream_close_callback)
* received. In other words, the frame with END_STREAM flag set is * received. In other words, the frame with END_STREAM flag set is
* received. In HTTP, this means HTTP request, including request * received. In HTTP, this means HTTP request, including request
* body, is fully received. * body, is fully received.
*
* 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_request_recv_callback) typedef int (*nghttp2_on_request_recv_callback)
(nghttp2_session *session, int32_t stream_id, void *user_data); (nghttp2_session *session, int32_t stream_id, void *user_data);
/** /**
......
...@@ -1611,13 +1611,16 @@ static ssize_t nghttp2_recv(nghttp2_session *session, uint8_t *buf, size_t len) ...@@ -1611,13 +1611,16 @@ static ssize_t nghttp2_recv(nghttp2_session *session, uint8_t *buf, size_t len)
return r; return r;
} }
static void nghttp2_session_call_on_request_recv static int nghttp2_session_call_on_request_recv
(nghttp2_session *session, int32_t stream_id) (nghttp2_session *session, int32_t stream_id)
{ {
if(session->callbacks.on_request_recv_callback) { if(session->callbacks.on_request_recv_callback) {
session->callbacks.on_request_recv_callback(session, stream_id, if(session->callbacks.on_request_recv_callback(session, stream_id,
session->user_data); session->user_data) != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
} }
return 0;
} }
static int nghttp2_session_call_on_frame_received static int nghttp2_session_call_on_frame_received
...@@ -1776,7 +1779,10 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session, ...@@ -1776,7 +1779,10 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session,
return r; return r;
} }
if(flags & NGHTTP2_FLAG_END_STREAM) { if(flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_session_call_on_request_recv(session, frame->hd.stream_id); r = nghttp2_session_call_on_request_recv(session, frame->hd.stream_id);
if(r != 0) {
return r;
}
} }
} else { } else {
r = nghttp2_session_handle_invalid_stream(session, frame, error_code); r = nghttp2_session_handle_invalid_stream(session, frame, error_code);
...@@ -1909,7 +1915,11 @@ int nghttp2_session_on_headers_received(nghttp2_session *session, ...@@ -1909,7 +1915,11 @@ int nghttp2_session_on_headers_received(nghttp2_session *session,
return r; return r;
} }
if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { if(frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_session_call_on_request_recv(session, frame->hd.stream_id); r = nghttp2_session_call_on_request_recv(session,
frame->hd.stream_id);
if(r != 0) {
return r;
}
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD);
r = nghttp2_session_close_stream_if_shut_rdwr(session, stream); r = nghttp2_session_close_stream_if_shut_rdwr(session, stream);
if(r != 0 && nghttp2_is_fatal(r)) { if(r != 0 && nghttp2_is_fatal(r)) {
...@@ -2717,7 +2727,10 @@ int nghttp2_session_on_data_received(nghttp2_session *session, ...@@ -2717,7 +2727,10 @@ int nghttp2_session_on_data_received(nghttp2_session *session,
} }
} }
if(flags & NGHTTP2_FLAG_END_STREAM) { if(flags & NGHTTP2_FLAG_END_STREAM) {
nghttp2_session_call_on_request_recv(session, stream_id); r = nghttp2_session_call_on_request_recv(session, stream_id);
if(r != 0) {
return r;
}
} }
} }
if(valid) { if(valid) {
......
...@@ -728,7 +728,7 @@ int hd_on_frame_recv_callback ...@@ -728,7 +728,7 @@ int hd_on_frame_recv_callback
} }
} // namespace } // namespace
void htdocs_on_request_recv_callback int htdocs_on_request_recv_callback
(nghttp2_session *session, int32_t stream_id, void *user_data) (nghttp2_session *session, int32_t stream_id, void *user_data)
{ {
auto hd = reinterpret_cast<Http2Handler*>(user_data); auto hd = reinterpret_cast<Http2Handler*>(user_data);
...@@ -736,6 +736,7 @@ void htdocs_on_request_recv_callback ...@@ -736,6 +736,7 @@ void htdocs_on_request_recv_callback
if(stream) { if(stream) {
prepare_response(hd->get_stream(stream_id), hd); prepare_response(hd->get_stream(stream_id), hd);
} }
return 0;
} }
namespace { namespace {
......
...@@ -134,7 +134,7 @@ private: ...@@ -134,7 +134,7 @@ private:
const Config *config_; const Config *config_;
}; };
void htdocs_on_request_recv_callback int htdocs_on_request_recv_callback
(nghttp2_session *session, int32_t stream_id, void *user_data); (nghttp2_session *session, int32_t stream_id, void *user_data);
ssize_t file_read_callback ssize_t file_read_callback
......
...@@ -221,12 +221,13 @@ static ssize_t fail_data_source_read_callback ...@@ -221,12 +221,13 @@ static ssize_t fail_data_source_read_callback
return NGHTTP2_ERR_CALLBACK_FAILURE; return NGHTTP2_ERR_CALLBACK_FAILURE;
} }
static void on_request_recv_callback(nghttp2_session *session, static int on_request_recv_callback(nghttp2_session *session,
int32_t stream_id, int32_t stream_id,
void *user_data) void *user_data)
{ {
my_user_data *ud = (my_user_data*)user_data; my_user_data *ud = (my_user_data*)user_data;
ud->stream_id = stream_id; ud->stream_id = stream_id;
return 0;
} }
/* static void no_stream_user_data_stream_close_callback */ /* static void no_stream_user_data_stream_close_callback */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment