From e8fd5f69e44d459f851e11a85ee28c8314c30791 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Thu, 1 Dec 2011 17:52:43 -0600 Subject: [PATCH] adjusts some debugging code and fixes the TLS shutdown delay issue --- src/connection.hpp | 24 +++++++++++++++--------- src/sockets/ssl.hpp | 9 +++------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/connection.hpp b/src/connection.hpp index 4d86b45ce6..634a22b5de 100644 --- a/src/connection.hpp +++ b/src/connection.hpp @@ -476,7 +476,7 @@ protected: if (error) { if (error == boost::asio::error::operation_aborted) { // previous write was aborted - std::cout << "aborted" << std::endl; + m_endpoint.alog().at(log::alevel::DEBUG_CLOSE) << "handle_write was called with operation_aborted error" << log::endl; } else { log_error("Error writing frame data",error); terminate(false); @@ -485,10 +485,10 @@ protected: } if (m_write_queue.size() == 0) { - std::cout << "handle_write called with empty queue" << std::endl; + m_endpoint.alog().at(log::alevel::DEBUG_CLOSE) << "handle_write called with empty queue" << log::endl; return; } - + m_write_buffer -= m_write_queue.front()->size(); m_write_queue.pop(); @@ -511,17 +511,23 @@ protected: // cancel the close timeout m_timer.cancel(); - m_dropped_by_me = socket_type::shutdown(); - m_failed_by_me = failed_by_me; - - session::state::value old_state = m_state; - m_state = session::state::CLOSED; // If this was a websocket connection notify the application handler // about the close using either on_fail or on_close if (role_type::get_version() != -1) { - if (old_state == session::state::CONNECTING) { + // TODO: note, calling shutdown on the ssl socket for an HTTP + // connection seems to cause shutdown to block for a very long time. + // NOT calling it for a websocket connection causes the connection + // to time out. Behavior now is correct but I am not sure why. + m_dropped_by_me = socket_type::shutdown(); + + m_failed_by_me = failed_by_me; + + session::state::value old_state = m_state; + m_state = session::state::CLOSED; + + if (old_state == session::state::CONNECTING) { m_endpoint.get_handler()->on_fail(type::shared_from_this()); } else if (old_state == session::state::OPEN || old_state == session::state::CLOSING) { diff --git a/src/sockets/ssl.hpp b/src/sockets/ssl.hpp index 700c93f862..a214fe2d29 100644 --- a/src/sockets/ssl.hpp +++ b/src/sockets/ssl.hpp @@ -116,15 +116,12 @@ public: callback(error); } + // note, this function for some reason shouldn't/doesn't need to be + // called for plain HTTP connections. not sure why. bool shutdown() { boost::system::error_code ignored_ec; - // TODO: this call blocks, sometimes for a long period of time. - // need to figure out what is going on here and how to calculate - // if the socket was already closed by this point. - // Until this is fixed, dropped_by_me for TLS connections will be - // inaccurate. - //m_socket_ptr->shutdown(ignored_ec); + m_socket_ptr->shutdown(ignored_ec); if (ignored_ec) { return false;