diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index dc904fc8..4966726f 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -60,7 +60,7 @@ void upstream_writecb(bufferevent *bev, void *arg) { auto handler = reinterpret_cast(arg); // We actually depend on write low-warter mark == 0. - if(handler->get_pending_write_length() > 0) { + if(handler->get_outbuf_length() > 0) { // Possibly because of deferred callback, we may get this callback // when the output buffer is not empty. return; @@ -449,7 +449,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection() } } -size_t ClientHandler::get_pending_write_length() +size_t ClientHandler::get_outbuf_length() { auto underlying = bufferevent_get_underlying(bev_); auto len = evbuffer_get_length(bufferevent_get_output(bev_)); diff --git a/src/shrpx_client_handler.h b/src/shrpx_client_handler.h index bc76a48f..7e26277f 100644 --- a/src/shrpx_client_handler.h +++ b/src/shrpx_client_handler.h @@ -61,7 +61,7 @@ public: void pool_downstream_connection(DownstreamConnection *dconn); void remove_downstream_connection(DownstreamConnection *dconn); DownstreamConnection* get_downstream_connection(); - size_t get_pending_write_length(); + size_t get_outbuf_length(); SSL* get_ssl() const; void set_http2_session(Http2Session *http2session); Http2Session* get_http2_session() const; diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 227c501c..54a26be8 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -45,7 +45,7 @@ using namespace nghttp2; namespace shrpx { namespace { -const size_t SHRPX_HTTP2_UPSTREAM_OUTPUT_UPPER_THRES = 64*1024; +const size_t OUTBUF_MAX_THRES = 64*1024; } // namespace namespace { @@ -59,8 +59,7 @@ ssize_t send_callback(nghttp2_session *session, auto bev = handler->get_bev(); auto output = bufferevent_get_output(bev); // Check buffer length and return WOULDBLOCK if it is large enough. - if(handler->get_pending_write_length() > - SHRPX_HTTP2_UPSTREAM_OUTPUT_UPPER_THRES) { + if(handler->get_outbuf_length() > OUTBUF_MAX_THRES) { return NGHTTP2_ERR_WOULDBLOCK; } @@ -595,7 +594,7 @@ int Http2Upstream::on_read() } if(nghttp2_session_want_read(session_) == 0 && nghttp2_session_want_write(session_) == 0 && - handler_->get_pending_write_length() == 0) { + handler_->get_outbuf_length() == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this HTTP2 session"; } @@ -620,7 +619,7 @@ int Http2Upstream::send() if(rv == 0) { if(nghttp2_session_want_read(session_) == 0 && nghttp2_session_want_write(session_) == 0 && - handler_->get_pending_write_length() == 0) { + handler_->get_outbuf_length() == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this HTTP2 session"; } @@ -907,8 +906,8 @@ ssize_t downstream_data_read_callback(nghttp2_session *session, // Send WINDOW_UPDATE before buffer is empty to avoid delay because // of RTT. if(*eof != 1 && - handler->get_pending_write_length() + evbuffer_get_length(body) < - SHRPX_HTTP2_UPSTREAM_OUTPUT_UPPER_THRES) { + handler->get_outbuf_length() + evbuffer_get_length(body) < + OUTBUF_MAX_THRES) { if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; } @@ -1086,9 +1085,9 @@ int Http2Upstream::on_downstream_body(Downstream *downstream, } nghttp2_session_resume_data(session_, downstream->get_stream_id()); - auto outbuflen = handler->get_pending_write_length() + + auto outbuflen = handler->get_outbuf_length() + evbuffer_get_length(body); - if(outbuflen > SHRPX_HTTP2_UPSTREAM_OUTPUT_UPPER_THRES) { + if(outbuflen > OUTBUF_MAX_THRES) { downstream->pause_read(SHRPX_NO_BUFFER); } diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 2c573558..ad2d678b 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -44,7 +44,7 @@ using namespace nghttp2; namespace shrpx { namespace { -const size_t SHRPX_HTTPS_UPSTREAM_OUTPUT_UPPER_THRES = 64*1024; +const size_t OUTBUF_MAX_THRES = 64*1024; const size_t SHRPX_HTTPS_MAX_HEADER_LENGTH = 64*1024; } // namespace @@ -414,7 +414,7 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) auto handler = upstream->get_client_handler(); if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { if(handler->get_should_close_after_write() && - handler->get_pending_write_length() == 0) { + handler->get_outbuf_length() == 0) { // If all upstream response body has already written out to // the peer, we cannot use writecb for ClientHandler. In // this case, we just delete handler here. @@ -435,7 +435,7 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) // https_downstream_eventcb. // // Tunneled connection always indicates connection close. - if(handler->get_pending_write_length() == 0) { + if(handler->get_outbuf_length() == 0) { // For tunneled connection, if there is no pending data, // delete handler because on_write will not be called. delete handler; @@ -446,8 +446,8 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) } } } else { - if(upstream->get_client_handler()->get_pending_write_length() > - SHRPX_HTTPS_UPSTREAM_OUTPUT_UPPER_THRES) { + if(upstream->get_client_handler()->get_outbuf_length() > + OUTBUF_MAX_THRES) { downstream->pause_read(SHRPX_NO_BUFFER); } } @@ -514,7 +514,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr) auto handler = upstream->get_client_handler(); if(handler->get_should_close_after_write() && - handler->get_pending_write_length() == 0) { + handler->get_outbuf_length() == 0) { // If all upstream response body has already written out to // the peer, we cannot use writecb for ClientHandler. In this // case, we just delete handler here. diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 121849ae..903f13c8 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -45,7 +45,7 @@ using namespace nghttp2; namespace shrpx { namespace { -const size_t SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES = 64*1024; +const size_t OUTBUF_MAX_THRES = 64*1024; } // namespace namespace { @@ -59,8 +59,7 @@ ssize_t send_callback(spdylay_session *session, auto bev = handler->get_bev(); auto output = bufferevent_get_output(bev); // Check buffer length and return WOULDBLOCK if it is large enough. - if(handler->get_pending_write_length() > - SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES) { + if(handler->get_outbuf_length() > OUTBUF_MAX_THRES) { return SPDYLAY_ERR_WOULDBLOCK; } @@ -452,7 +451,7 @@ int SpdyUpstream::on_read() if(rv == 0) { if(spdylay_session_want_read(session_) == 0 && spdylay_session_want_write(session_) == 0 && - handler_->get_pending_write_length() == 0) { + handler_->get_outbuf_length() == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this SPDY session"; } @@ -478,7 +477,7 @@ int SpdyUpstream::send() if(rv == 0) { if(spdylay_session_want_read(session_) == 0 && spdylay_session_want_write(session_) == 0 && - handler_->get_pending_write_length() == 0) { + handler_->get_outbuf_length() == 0) { if(LOG_ENABLED(INFO)) { ULOG(INFO, this) << "No more read/write for this SPDY session"; } @@ -751,8 +750,8 @@ ssize_t spdy_data_read_callback(spdylay_session *session, // Send WINDOW_UPDATE before buffer is empty to avoid delay because // of RTT. if(*eof != 1 && - handler->get_pending_write_length() + evbuffer_get_length(body) < - SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES) { + handler->get_outbuf_length() + evbuffer_get_length(body) < + OUTBUF_MAX_THRES) { if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) { return SPDYLAY_ERR_CALLBACK_FAILURE; } @@ -931,9 +930,9 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream, } spdylay_session_resume_data(session_, downstream->get_stream_id()); - auto outbuflen = upstream->get_client_handler()->get_pending_write_length() + + auto outbuflen = upstream->get_client_handler()->get_outbuf_length() + evbuffer_get_length(body); - if(outbuflen > SHRPX_SPDY_UPSTREAM_OUTPUT_UPPER_THRES) { + if(outbuflen > OUTBUF_MAX_THRES) { downstream->pause_read(SHRPX_NO_BUFFER); }