From ff0eaf83997a5410faf45d2768533604d7d62b20 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 4 Mar 2015 22:51:46 +0900 Subject: [PATCH] asio: Indicate EOF by passing 0 to the second parameter to data_cb --- src/asio_http2_handler.cc | 14 ++------------ src/asio_http2_handler.h | 3 --- src/includes/nghttp2/asio_http2.h | 2 ++ src/includes/nghttp2/asio_http2_server.h | 3 --- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/asio_http2_handler.cc b/src/asio_http2_handler.cc index 3bf7586e..966295ab 100644 --- a/src/asio_http2_handler.cc +++ b/src/asio_http2_handler.cc @@ -57,8 +57,6 @@ void request::on_data(data_cb cb) const { return impl_->on_data(std::move(cb)); } -void request::on_end(void_cb cb) const { return impl_->on_end(std::move(cb)); } - request_impl &request::impl() const { return *impl_; } response::response() : impl_(make_unique()) {} @@ -108,8 +106,6 @@ void request_impl::pushed(bool f) { pushed_ = f; } void request_impl::on_data(data_cb cb) { on_data_cb_ = std::move(cb); } -void request_impl::on_end(void_cb cb) { on_end_cb_ = std::move(cb); } - void request_impl::stream(http2_stream *s) { stream_ = s; } void request_impl::call_on_data(const uint8_t *data, std::size_t len) { @@ -118,12 +114,6 @@ void request_impl::call_on_data(const uint8_t *data, std::size_t len) { } } -void request_impl::call_on_end() { - if (on_end_cb_) { - on_end_cb_(); - } -} - response_impl::response_impl() : stream_(nullptr), status_code_(200), started_(false) {} @@ -288,7 +278,7 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, } if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { - stream->request().impl().call_on_end(); + stream->request().impl().call_on_data(nullptr, 0); } break; @@ -300,7 +290,7 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, handler->call_on_request(*stream); if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { - stream->request().impl().call_on_end(); + stream->request().impl().call_on_data(nullptr, 0); } break; diff --git a/src/asio_http2_handler.h b/src/asio_http2_handler.h index febf0bf3..8364767c 100644 --- a/src/asio_http2_handler.h +++ b/src/asio_http2_handler.h @@ -62,12 +62,10 @@ public: bool pushed() const; void on_data(data_cb cb); - void on_end(void_cb cb); void pushed(bool f); void stream(http2_stream *s); void call_on_data(const uint8_t *data, std::size_t len); - void call_on_end(); private: http2_stream *stream_; @@ -75,7 +73,6 @@ private: std::string method_; uri_ref uri_; data_cb on_data_cb_; - void_cb on_end_cb_; bool pushed_; }; diff --git a/src/includes/nghttp2/asio_http2.h b/src/includes/nghttp2/asio_http2.h index 2382fe75..caa8a40a 100644 --- a/src/includes/nghttp2/asio_http2.h +++ b/src/includes/nghttp2/asio_http2.h @@ -71,6 +71,8 @@ struct uri_ref { std::string fragment; }; +// Callback function when data is arrived. EOF is indicated by +// passing 0 to the second parameter. typedef std::function data_cb; typedef std::function void_cb; typedef std::function error_cb; diff --git a/src/includes/nghttp2/asio_http2_server.h b/src/includes/nghttp2/asio_http2_server.h index caf1238d..16366ac2 100644 --- a/src/includes/nghttp2/asio_http2_server.h +++ b/src/includes/nghttp2/asio_http2_server.h @@ -54,9 +54,6 @@ public: // Sets callback when chunk of request body is received. void on_data(data_cb cb) const; - // Sets callback when request was completed. - void on_end(void_cb cb) const; - // Pushes resource denoted by |path| using |method|. The additional // headers can be given in |h|. request_cb will be called for // pushed resource later on. This function returns true if it