Preserve ASIO errors if possible in asio::endpoint too

This was already done in asio::xxx_socket::connection methods by using
translate_ec() which allowed to preserve the error code when possible (i.e.
when using Boost.ASIO with Boost.System or standalone ASIO with C++11
std::error_code), but errors also can happen in endpoint methods such as
handle_connect(), where they were totally lost and replaced with a rather
useless error::pass_through.

With these changes, the real error codes are preserved and applications using
the library can give more useful error messages if connection fails.
This commit is contained in:
Vadim Zeitlin
2017-06-04 16:50:14 +02:00
parent e6e14df950
commit 81ef065ccf
3 changed files with 7 additions and 5 deletions

View File

@@ -423,7 +423,7 @@ public:
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();
@@ -733,7 +733,7 @@ public:
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());
@@ -818,7 +818,7 @@ protected:
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);
}
}
@@ -961,7 +961,7 @@ protected:
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;
}
@@ -1069,7 +1069,7 @@ protected:
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;
}

View File

@@ -261,6 +261,7 @@ protected:
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

View File

@@ -333,6 +333,7 @@ protected:
}
}
public:
/// Translate any security policy specific information about an error code
/**
* Translate_ec takes an Asio error code and attempts to convert its value