nghttpx: Remove deprecated evbuffer_setcb, send WU before buffer gets empty

This commit is contained in:
Tatsuhiro Tsujikawa 2014-01-18 18:39:25 +09:00
parent 0872ce27f4
commit 8f3d4fdeec
4 changed files with 19 additions and 14 deletions

View File

@ -635,18 +635,6 @@ int Downstream::get_response_state() const
return response_state_; return response_state_;
} }
namespace {
void body_buf_cb(evbuffer *body, size_t oldlen, size_t newlen, void *arg)
{
Downstream *downstream = reinterpret_cast<Downstream*>(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() int Downstream::init_response_body_buf()
{ {
if(!response_body_buf_) { if(!response_body_buf_) {
@ -654,7 +642,6 @@ int Downstream::init_response_body_buf()
if(response_body_buf_ == nullptr) { if(response_body_buf_ == nullptr) {
DIE(); DIE();
} }
evbuffer_setcb(response_body_buf_, body_buf_cb, this);
} }
return 0; return 0;
} }

View File

@ -92,7 +92,6 @@ int Http2DownstreamConnection::init_request_body_buf()
if(request_body_buf_ == nullptr) { if(request_body_buf_ == nullptr) {
return -1; return -1;
} }
evbuffer_setcb(request_body_buf_, nullptr, this);
} }
return 0; return 0;
} }
@ -212,6 +211,14 @@ ssize_t http2_data_read_callback(nghttp2_session *session,
} }
} }
} else { } 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; break;
} }
} }

View File

@ -902,6 +902,13 @@ ssize_t downstream_data_read_callback(nghttp2_session *session,
(downstream->get_response_rst_stream_error_code())); (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) { if(nread == 0 && *eof != 1) {
return NGHTTP2_ERR_DEFERRED; return NGHTTP2_ERR_DEFERRED;
} }

View File

@ -457,6 +457,10 @@ int htp_msg_completecb(http_parser *htp)
{ {
auto downstream = reinterpret_cast<Downstream*>(htp->data); auto downstream = reinterpret_cast<Downstream*>(htp->data);
downstream->set_response_state(Downstream::MSG_COMPLETE); 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); return downstream->get_upstream()->on_downstream_body_complete(downstream);
} }
} // namespace } // namespace