asio: Add signal_write() to server::http2_handler to avoid scattered ifs

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-05 22:00:14 +09:00
parent 7f04968950
commit 6020b727d8
3 changed files with 14 additions and 16 deletions

View File

@ -343,6 +343,8 @@ int http2_handler::start_response(stream &strm) {
return -1;
}
signal_write();
return 0;
}
@ -356,16 +358,22 @@ void http2_handler::leave_callback() {
inside_callback_ = false;
}
bool http2_handler::inside_callback() const { return inside_callback_; }
void http2_handler::stream_error(int32_t stream_id, uint32_t error_code) {
::nghttp2::asio_http2::server::stream_error(session_, stream_id, error_code);
signal_write();
}
void http2_handler::signal_write() {
if (!inside_callback_) {
initiate_write();
}
}
void http2_handler::initiate_write() { writefun_(); }
void http2_handler::resume(stream &strm) {
nghttp2_session_resume_data(session_, strm.get_stream_id());
signal_write();
}
response *http2_handler::push_promise(boost::system::error_code &ec,
@ -412,6 +420,8 @@ response *http2_handler::push_promise(boost::system::error_code &ec,
auto &promised_res = promised_strm->response().impl();
promised_res.pushed(true);
signal_write();
return &promised_strm->response();
}

View File

@ -76,7 +76,6 @@ public:
void enter_callback();
void leave_callback();
bool inside_callback() const;
void resume(stream &s);
@ -84,6 +83,8 @@ public:
std::string method, std::string raw_path_query,
header_map h);
void signal_write();
boost::asio::io_service &io_service();
template <size_t N>

View File

@ -72,12 +72,7 @@ void response_impl::call_on_close(uint32_t error_code) {
void response_impl::cancel(uint32_t error_code) {
auto handler = strm_->handler();
handler->stream_error(strm_->get_stream_id(), error_code);
if (!handler->inside_callback()) {
handler->initiate_write();
}
}
void response_impl::start_response() {
@ -91,10 +86,6 @@ void response_impl::start_response() {
handler->stream_error(strm_->get_stream_id(), NGHTTP2_INTERNAL_ERROR);
return;
}
if (!handler->inside_callback()) {
handler->initiate_write();
}
}
response *response_impl::push(boost::system::error_code &ec, std::string method,
@ -107,10 +98,6 @@ response *response_impl::push(boost::system::error_code &ec, std::string method,
void response_impl::resume() {
auto handler = strm_->handler();
handler->resume(*strm_);
if (!handler->inside_callback()) {
handler->initiate_write();
}
}
boost::asio::io_service &response_impl::io_service() {