From a6cf6c00ea4373c244471788a3b717e9065bd29e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 6 Jan 2015 21:56:19 +0900 Subject: [PATCH] nghttpx: Add SSL_read/write error logging --- src/shrpx_client_handler.cc | 6 +++++ src/shrpx_http2_session.cc | 46 ++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 96983420..538ae876 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -250,6 +250,9 @@ int ClientHandler::read_tls() { ev_timer_again(loop_, &wt_); goto fin; default: + if (LOG_ENABLED(INFO)) { + CLOG(INFO, this) << "SSL_read: SSL_get_error returned " << err; + } return -1; } } @@ -298,6 +301,9 @@ int ClientHandler::write_tls() { ev_timer_again(loop_, &wt_); return 0; default: + if (LOG_ENABLED(INFO)) { + CLOG(INFO, this) << "SSL_write: SSL_get_error returned " << err; + } return -1; } } diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 11875d71..83c75331 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1668,29 +1668,34 @@ int Http2Session::read_tls() { rb_.reset(); struct iovec iov[2]; auto iovcnt = rb_.wiovec(iov); - if (iovcnt > 0) { - auto rv = SSL_read(ssl_, iov[0].iov_base, iov[0].iov_len); + if (iovcnt == 0) { + return 0; + } - if (rv == 0) { + auto rv = SSL_read(ssl_, iov[0].iov_base, iov[0].iov_len); + + if (rv == 0) { + return -1; + } + + if (rv < 0) { + auto err = SSL_get_error(ssl_, rv); + switch (err) { + case SSL_ERROR_WANT_READ: + return 0; + case SSL_ERROR_WANT_WRITE: + ev_io_start(loop_, &wev_); + ev_timer_again(loop_, &wt_); + return 0; + default: + if (LOG_ENABLED(INFO)) { + SSLOG(INFO, this) << "SSL_read: SSL_get_error returned " << err; + } return -1; } - - if (rv < 0) { - auto err = SSL_get_error(ssl_, rv); - switch (err) { - case SSL_ERROR_WANT_READ: - return 0; - case SSL_ERROR_WANT_WRITE: - ev_io_start(loop_, &wev_); - ev_timer_again(loop_, &wt_); - return 0; - default: - return -1; - } - } - - rb_.write(rv); } + + rb_.write(rv); } } @@ -1721,6 +1726,9 @@ int Http2Session::write_tls() { ev_timer_again(loop_, &wt_); return 0; default: + if (LOG_ENABLED(INFO)) { + SSLOG(INFO, this) << "SSL_write: SSL_get_error returned " << err; + } return -1; } }