From 8f3d4fdeecbec16be615e58acd7c65baa4f6a0d0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 18 Jan 2014 18:39:25 +0900 Subject: [PATCH] nghttpx: Remove deprecated evbuffer_setcb, send WU before buffer gets empty --- src/shrpx_downstream.cc | 13 ------------- src/shrpx_http2_downstream_connection.cc | 9 ++++++++- src/shrpx_http2_upstream.cc | 7 +++++++ src/shrpx_http_downstream_connection.cc | 4 ++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 7366e2c3..6d4c587e 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -635,18 +635,6 @@ int Downstream::get_response_state() const return response_state_; } -namespace { -void body_buf_cb(evbuffer *body, size_t oldlen, size_t newlen, void *arg) -{ - Downstream *downstream = reinterpret_cast(arg); - if(newlen == 0) { - if(downstream->resume_read(SHRPX_NO_BUFFER) == -1) { - DLOG(WARNING, downstream) << "Sending WINDOW_UPDATE failed"; - } - } -} -} // namespace - int Downstream::init_response_body_buf() { if(!response_body_buf_) { @@ -654,7 +642,6 @@ int Downstream::init_response_body_buf() if(response_body_buf_ == nullptr) { DIE(); } - evbuffer_setcb(response_body_buf_, body_buf_cb, this); } return 0; } diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index 5763dab4..5ce44115 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -92,7 +92,6 @@ int Http2DownstreamConnection::init_request_body_buf() if(request_body_buf_ == nullptr) { return -1; } - evbuffer_setcb(request_body_buf_, nullptr, this); } return 0; } @@ -212,6 +211,14 @@ ssize_t http2_data_read_callback(nghttp2_session *session, } } } else { + // Send WINDOW_UPDATE before buffer is empty to avoid delay + // because of RTT. + if(!downstream->get_output_buffer_full() && + downstream->get_upstream()->resume_read(SHRPX_NO_BUFFER, + downstream) == -1) { + // In this case, downstream may be deleted. + return NGHTTP2_ERR_DEFERRED; + } break; } } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 3a9c5e86..5a25c052 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -902,6 +902,13 @@ ssize_t downstream_data_read_callback(nghttp2_session *session, (downstream->get_response_rst_stream_error_code())); } } + // Send WINDOW_UPDATE before buffer is empty to avoid delay because + // of RTT. + if(*eof != 1 && + evbuffer_get_length(body) < SHRPX_HTTP2_UPSTREAM_OUTPUT_UPPER_THRES && + downstream->resume_read(SHRPX_NO_BUFFER) != 0) { + DLOG(WARNING, downstream) << "Sending WINDOW_UPDATE failed"; + } if(nread == 0 && *eof != 1) { return NGHTTP2_ERR_DEFERRED; } diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 446d9640..4678e61b 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -457,6 +457,10 @@ int htp_msg_completecb(http_parser *htp) { auto downstream = reinterpret_cast(htp->data); downstream->set_response_state(Downstream::MSG_COMPLETE); + // Block reading another response message from (broken?) + // server. This callback is not called if the connection is + // tunneled. + downstream->pause_read(SHRPX_MSG_BLOCK); return downstream->get_upstream()->on_downstream_body_complete(downstream); } } // namespace