nghttpx: Add flag to track connection state in HTTP/1 backend

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-29 01:47:22 +09:00
parent 3576f20e5a
commit 12ced1cddc
3 changed files with 16 additions and 6 deletions

View File

@ -81,13 +81,11 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) {
delete handler; delete handler;
return; return;
} }
if (ev_is_active(handler->get_wev())) {
if (handler->do_write() != 0) { if (handler->do_write() != 0) {
delete handler; delete handler;
return; return;
} }
} }
}
} // namespace } // namespace
namespace { namespace {

View File

@ -114,7 +114,8 @@ HttpDownstreamConnection::HttpDownstreamConnection(
conn_(loop, -1, nullptr, get_config()->downstream_write_timeout, conn_(loop, -1, nullptr, get_config()->downstream_write_timeout,
get_config()->downstream_read_timeout, 0, 0, 0, 0, connectcb, get_config()->downstream_read_timeout, 0, 0, 0, 0, connectcb,
readcb, timeoutcb, this), readcb, timeoutcb, this),
ioctrl_(&conn_.rlimit), response_htp_{0}, addr_idx_(0) {} ioctrl_(&conn_.rlimit), response_htp_{0}, addr_idx_(0),
connected_(false) {}
HttpDownstreamConnection::~HttpDownstreamConnection() { HttpDownstreamConnection::~HttpDownstreamConnection() {
// Downstream and DownstreamConnection may be deleted // Downstream and DownstreamConnection may be deleted
@ -670,6 +671,10 @@ http_parser_settings htp_hooks = {
} // namespace } // namespace
int HttpDownstreamConnection::on_read() { int HttpDownstreamConnection::on_read() {
if (!connected_) {
return 0;
}
ev_timer_again(conn_.loop, &conn_.rt); ev_timer_again(conn_.loop, &conn_.rt);
std::array<uint8_t, 8192> buf; std::array<uint8_t, 8192> buf;
int rv; int rv;
@ -742,6 +747,10 @@ int HttpDownstreamConnection::on_read() {
} }
int HttpDownstreamConnection::on_write() { int HttpDownstreamConnection::on_write() {
if (!connected_) {
return 0;
}
ev_timer_again(conn_.loop, &conn_.rt); ev_timer_again(conn_.loop, &conn_.rt);
auto upstream = downstream_->get_upstream(); auto upstream = downstream_->get_upstream();
@ -789,6 +798,8 @@ int HttpDownstreamConnection::on_connect() {
return -1; return -1;
} }
connected_ = true;
connect_blocker->on_success(); connect_blocker->on_success();
conn_.rlimit.startw(); conn_.rlimit.startw();

View File

@ -70,6 +70,7 @@ private:
http_parser response_htp_; http_parser response_htp_;
// index of get_config()->downstream_addrs this object is using // index of get_config()->downstream_addrs this object is using
size_t addr_idx_; size_t addr_idx_;
bool connected_;
}; };
} // namespace shrpx } // namespace shrpx