nghttpx: Handle connect error

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-05 16:14:10 +09:00
parent 7dba426db4
commit 7a50299cb0
3 changed files with 19 additions and 3 deletions

View File

@ -1503,6 +1503,10 @@ void Http2Session::set_connection_check_state(int state) {
int Http2Session::noop() { return 0; } int Http2Session::noop() { return 0; }
int Http2Session::connected() { int Http2Session::connected() {
if (!util::check_socket_connected(fd_)) {
return -1;
}
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "Connection established"; SSLOG(INFO, this) << "Connection established";
} }

View File

@ -91,7 +91,13 @@ void writecb(struct ev_loop *loop, ev_io *w, int revents) {
namespace { namespace {
void connectcb(struct ev_loop *loop, ev_io *w, int revents) { void connectcb(struct ev_loop *loop, ev_io *w, int revents) {
auto dconn = static_cast<HttpDownstreamConnection *>(w->data); auto dconn = static_cast<HttpDownstreamConnection *>(w->data);
dconn->on_connect(); auto downstream = dconn->get_downstream();
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
if (dconn->on_connect() != 0) {
delete handler;
return;
}
writecb(loop, w, revents); writecb(loop, w, revents);
} }
} // namespace } // namespace
@ -724,9 +730,15 @@ end:
return 0; return 0;
} }
void HttpDownstreamConnection::on_connect() { int HttpDownstreamConnection::on_connect() {
if (!util::check_socket_connected(fd_)) {
return -1;
}
ev_io_start(loop_, &rev_); ev_io_start(loop_, &rev_);
ev_set_cb(&wev_, writecb); ev_set_cb(&wev_, writecb);
return 0;
} }
void HttpDownstreamConnection::on_upstream_change(Upstream *upstream) {} void HttpDownstreamConnection::on_upstream_change(Upstream *upstream) {}

View File

@ -58,7 +58,7 @@ public:
virtual void on_upstream_change(Upstream *upstream); virtual void on_upstream_change(Upstream *upstream);
virtual int on_priority_change(int32_t pri) { return 0; } virtual int on_priority_change(int32_t pri) { return 0; }
void on_connect(); int on_connect();
void signal_write(); void signal_write();
private: private: