Skip to content

Commit

Permalink
Merge pull request zaphoyd#652 from vadz/preserve-asio-errors
Browse files Browse the repository at this point in the history
Preserve ASIO errors if possible
  • Loading branch information
zaphoyd authored Sep 24, 2017
2 parents e79e0d1 + 81ef065 commit 88de392
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions websocketpp/transport/asio/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class endpoint : public config::socket_type {
m_acceptor->close();
}
log_err(log::elevel::info,"asio listen",bec);
ec = make_error_code(error::pass_through);
ec = socket_con_type::translate_ec(ec);
} else {
m_state = LISTENING;
ec = lib::error_code();
Expand Down Expand Up @@ -752,7 +752,7 @@ class endpoint : public config::socket_type {
m_elog->write(log::elevel::info,
"asio handle_timer error: "+ec.message());
log_err(log::elevel::info,"asio handle_timer",ec);
callback(make_error_code(error::pass_through));
callback(socket_con_type::translate_ec(ec));
}
} else {
callback(lib::error_code());
Expand Down Expand Up @@ -837,7 +837,7 @@ class endpoint : public config::socket_type {
ret_ec = make_error_code(websocketpp::error::operation_canceled);
} else {
log_err(log::elevel::info,"asio handle_accept",asio_ec);
ret_ec = make_error_code(error::pass_through);
ret_ec = socket_con_type::translate_ec(asio_ec);
}
}

Expand Down Expand Up @@ -980,7 +980,7 @@ class endpoint : public config::socket_type {

if (ec) {
log_err(log::elevel::info,"asio async_resolve",ec);
callback(make_error_code(error::pass_through));
callback(socket_con_type::translate_ec(ec));
return;
}

Expand Down Expand Up @@ -1088,7 +1088,7 @@ class endpoint : public config::socket_type {

if (ec) {
log_err(log::elevel::info,"asio async_connect",ec);
callback(make_error_code(error::pass_through));
callback(socket_con_type::translate_ec(ec));
return;
}

Expand Down
5 changes: 4 additions & 1 deletion websocketpp/transport/asio/security/none.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class connection : public lib::enable_shared_from_this<connection> {
return lib::error_code();
}

public:
/// Translate any security policy specific information about an error code
/**
* Translate_ec takes an Asio error code and attempts to convert its value
Expand All @@ -280,11 +281,13 @@ class connection : public lib::enable_shared_from_this<connection> {
* @return The translated error code
*/
template <typename ErrorCodeType>
static
lib::error_code translate_ec(ErrorCodeType) {
// We don't know any more information about this error so pass through
return make_error_code(transport::error::pass_through);
}


static
/// Overload of translate_ec to catch cases where lib::error_code is the
/// same type as lib::asio::error_code
lib::error_code translate_ec(lib::error_code ec) {
Expand Down
5 changes: 4 additions & 1 deletion websocketpp/transport/asio/security/tls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class connection : public lib::enable_shared_from_this<connection> {
}
}

public:
/// Translate any security policy specific information about an error code
/**
* Translate_ec takes an Asio error code and attempts to convert its value
Expand All @@ -353,6 +354,7 @@ class connection : public lib::enable_shared_from_this<connection> {
* @return The translated error code
*/
template <typename ErrorCodeType>
static
lib::error_code translate_ec(ErrorCodeType ec) {
if (ec.category() == lib::asio::error::get_ssl_category()) {
// We know it is a TLS related error, but otherwise don't know more.
Expand All @@ -364,7 +366,8 @@ class connection : public lib::enable_shared_from_this<connection> {
return make_error_code(transport::error::pass_through);
}
}


static
/// Overload of translate_ec to catch cases where lib::error_code is the
/// same type as lib::asio::error_code
lib::error_code translate_ec(lib::error_code ec) {
Expand Down

0 comments on commit 88de392

Please sign in to comment.