diff --git a/websocketpp/transport/asio/security/none.hpp b/websocketpp/transport/asio/security/none.hpp index 1c9486fa8d..96bf868589 100644 --- a/websocketpp/transport/asio/security/none.hpp +++ b/websocketpp/transport/asio/security/none.hpp @@ -229,6 +229,23 @@ protected: lib::error_code get_ec() const { return lib::error_code(); } + + /// Translate any security policy specific information about an error code + /** + * Translate_ec takes a boost error code and attempts to convert its value + * to an appropriate websocketpp error code. The plain socket policy does + * not presently provide any additional information so all errors will be + * reported as the generic transport pass_through error. + * + * @since 0.4.0-beta1 + * + * @param ec The error code to translate_ec + * @return The translated error code + */ + lib::error_code translate_ec(boost::system::error_code ec) { + // We don't know any more information about this error so pass through + return make_error_code(transport::error::pass_through); + } private: enum state { UNINITIALIZED = 0, diff --git a/websocketpp/transport/asio/security/tls.hpp b/websocketpp/transport/asio/security/tls.hpp index 2a743112bb..4f383e5a27 100644 --- a/websocketpp/transport/asio/security/tls.hpp +++ b/websocketpp/transport/asio/security/tls.hpp @@ -284,6 +284,37 @@ protected: void async_shutdown(socket_shutdown_handler callback) { m_socket->async_shutdown(callback); } + + /// Translate any security policy specific information about an error code + /** + * Translate_ec takes a boost error code and attempts to convert its value + * to an appropriate websocketpp error code. Any error that is determined to + * be related to TLS but does not have a more specific websocketpp error + * code is returned under the catch all error "tls_error". + * + * Non-TLS related errors are returned as the transport generic pass_through + * error. + * + * @since 0.4.0-beta1 + * + * @param ec The error code to translate_ec + * @return The translated error code + */ + lib::error_code translate_ec(boost::system::error_code ec) { + if (ec.category() == boost::asio::error::get_ssl_category()) { + if (ERR_GET_REASON(ec.value()) == SSL_R_SHORT_READ) { + return make_error_code(transport::error::tls_short_read); + } else { + // We know it is a TLS related error, but otherwise don't know + // more. Pass through as TLS generic. + return make_error_code(transport::error::tls_error); + } + } else { + // We don't know any more information about this error so pass + // through + return make_error_code(transport::error::pass_through); + } + } private: socket_type::handshake_type get_handshake_type() { if (m_is_server) {