From 7a50299cb0891557dd74597a107ca1420e2ffd56 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 5 Jan 2015 16:14:10 +0900 Subject: [PATCH] nghttpx: Handle connect error --- src/shrpx_http2_session.cc | 4 ++++ src/shrpx_http_downstream_connection.cc | 16 ++++++++++++++-- src/shrpx_http_downstream_connection.h | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 9cea0932..0c77b860 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1503,6 +1503,10 @@ void Http2Session::set_connection_check_state(int state) { int Http2Session::noop() { return 0; } int Http2Session::connected() { + if (!util::check_socket_connected(fd_)) { + return -1; + } + if (LOG_ENABLED(INFO)) { SSLOG(INFO, this) << "Connection established"; } diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index cc6c2f78..1daf02a6 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -91,7 +91,13 @@ void writecb(struct ev_loop *loop, ev_io *w, int revents) { namespace { void connectcb(struct ev_loop *loop, ev_io *w, int revents) { auto dconn = static_cast(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); } } // namespace @@ -724,9 +730,15 @@ end: return 0; } -void HttpDownstreamConnection::on_connect() { +int HttpDownstreamConnection::on_connect() { + if (!util::check_socket_connected(fd_)) { + return -1; + } + ev_io_start(loop_, &rev_); ev_set_cb(&wev_, writecb); + + return 0; } void HttpDownstreamConnection::on_upstream_change(Upstream *upstream) {} diff --git a/src/shrpx_http_downstream_connection.h b/src/shrpx_http_downstream_connection.h index 66132325..d61de22b 100644 --- a/src/shrpx_http_downstream_connection.h +++ b/src/shrpx_http_downstream_connection.h @@ -58,7 +58,7 @@ public: virtual void on_upstream_change(Upstream *upstream); virtual int on_priority_change(int32_t pri) { return 0; } - void on_connect(); + int on_connect(); void signal_write(); private: