diff --git a/websocketpp/transport/asio/base.hpp b/websocketpp/transport/asio/base.hpp index 3796fae2f0..f313b916e4 100644 --- a/websocketpp/transport/asio/base.hpp +++ b/websocketpp/transport/asio/base.hpp @@ -28,8 +28,11 @@ #ifndef WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP #define WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP -#include #include +#include +#include + +#include #include @@ -37,6 +40,9 @@ namespace websocketpp { namespace transport { namespace asio { +typedef lib::function + socket_shutdown_handler; + /** * This policy uses a single boost::asio io_service to provide transport * services to a WebSocket++ endpoint. diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 7cf155bf28..d5716eca54 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -503,9 +503,12 @@ protected: boost::system::error_code& ec) { m_bufs.clear(); - // TODO: translate this better if (ec) { - handler(make_error_code(error::pass_through)); + std::stringstream s; + s << "asio async_write error: " << ec + << " (" << ec.message() << ")"; + m_elog.write(log::elevel::info,s.str()); + handler(make_error_code(transport::error::pass_through)); } else { handler(lib::error_code()); } @@ -544,8 +547,37 @@ protected: }*/ /// close and clean up the underlying socket - void shutdown() { - socket_con_type::shutdown(); + void async_shutdown(shutdown_handler h) { + if (m_alog.static_test(log::alevel::devel)) { + m_alog.write(log::alevel::devel,"asio connection async_shutdown"); + } + + socket_con_type::async_shutdown( + lib::bind( + &type::handle_async_shutdown, + this, + h, + lib::placeholders::_1 + ) + ); + } + + void handle_async_shutdown(shutdown_handler h, const + boost::system::error_code & ec) + { + if (m_alog.static_test(log::alevel::devel)) { + m_alog.write(log::alevel::devel,"asio con handle_async_shutdown"); + } + + if (ec) { + std::stringstream s; + s << "asio async_shutdown error: " << ec + << " (" << ec.message() << ")"; + m_elog.write(log::elevel::info,s.str()); + h(make_error_code(transport::error::pass_through)); + } else { + h(lib::error_code()); + } } typedef lib::shared_ptr timer_ptr; @@ -563,9 +595,8 @@ protected: h(make_error_code(transport::error::operation_aborted)); } else if (ec) { std::stringstream s; - s << "asio async_wait error::pass_through" - << "Original Error: " << ec << " (" << ec.message() << ")"; - m_elog.write(log::elevel::devel,s.str()); + s << "asio async_wait error: " << ec << " (" << ec.message() << ")"; + m_elog.write(log::elevel::info,s.str()); h(make_error_code(transport::error::pass_through)); } else { h(lib::error_code()); diff --git a/websocketpp/transport/asio/security/none.hpp b/websocketpp/transport/asio/security/none.hpp index 373bdfb89c..68e77e4451 100644 --- a/websocketpp/transport/asio/security/none.hpp +++ b/websocketpp/transport/asio/security/none.hpp @@ -205,11 +205,10 @@ protected: m_hdl = hdl; } - void shutdown() { + void async_shutdown(socket_shutdown_handler h) { boost::system::error_code ec; m_socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both,ec); - - // TODO: handle errors + h(ec); } private: enum state { diff --git a/websocketpp/transport/asio/security/tls.hpp b/websocketpp/transport/asio/security/tls.hpp index 946c49c2de..682eb5e66b 100644 --- a/websocketpp/transport/asio/security/tls.hpp +++ b/websocketpp/transport/asio/security/tls.hpp @@ -291,20 +291,23 @@ protected: callback(lib::error_code()); } - void handle_shutdown(socket_ptr s, const boost::system::error_code& ec) { - // TODO: error handling? - } - - void shutdown() { + void async_shutdown(socket_shutdown_handler h) { m_socket->async_shutdown( - lib::bind( - &type::handle_shutdown, + lib::bind( + &type::handle_async_shutdown, this, m_socket, + h, lib::placeholders::_1 ) ); } + + void handle_async_shutdown(socket_ptr s, socket_shutdown_handler h, const + boost::system::error_code& ec) + { + h(ec); + } private: socket_type::handshake_type get_handshake_type() { if (m_is_server) { diff --git a/websocketpp/transport/base/connection.hpp b/websocketpp/transport/base/connection.hpp index d3ccaafb69..983fcb8393 100644 --- a/websocketpp/transport/base/connection.hpp +++ b/websocketpp/transport/base/connection.hpp @@ -70,6 +70,7 @@ typedef lib::function init_handler; typedef lib::function read_handler; typedef lib::function write_handler; typedef lib::function timer_handler; +typedef lib::function shutdown_handler; typedef lib::function inturrupt_handler; typedef lib::function dispatch_handler; diff --git a/websocketpp/transport/iostream/connection.hpp b/websocketpp/transport/iostream/connection.hpp index ed801e421c..ab2b19b01d 100644 --- a/websocketpp/transport/iostream/connection.hpp +++ b/websocketpp/transport/iostream/connection.hpp @@ -313,8 +313,8 @@ protected: return lib::error_code(); } - void shutdown() { - // TODO: + void async_shutdown(shutdown_handler h) { + h(lib::error_code()); } private: void read(std::istream &in) {