updates socket policy error handling

This commit is contained in:
Peter Thorson
2013-05-11 09:36:42 -05:00
parent 67edd83a7c
commit 2f050cf412
3 changed files with 21 additions and 8 deletions

View File

@@ -131,7 +131,7 @@ inline const lib::error_category& get_socket_category() {
return instance;
}
inline lib::error_code make_error(error::value e) {
inline lib::error_code make_error_code(error::value e) {
return lib::error_code(static_cast<int>(e), get_socket_category());
}

View File

@@ -148,7 +148,7 @@ protected:
*/
lib::error_code init_asio (io_service_ptr service, bool is_server) {
if (m_state != UNINITIALIZED) {
return socket::make_error(socket::error::invalid_state);
return socket::make_error_code(socket::error::invalid_state);
}
m_socket.reset(new boost::asio::ip::tcp::socket(*service));
@@ -169,7 +169,7 @@ protected:
*/
void pre_init(init_handler callback) {
if (m_state != READY) {
callback(socket::make_error(socket::error::invalid_state));
callback(socket::make_error_code(socket::error::invalid_state));
return;
}
@@ -215,6 +215,10 @@ protected:
m_socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both,ec);
h(ec);
}
const lib::error_code &get_ec() const {
return lib::error_code();
}
private:
enum state {
UNINITIALIZED = 0,

View File

@@ -173,12 +173,12 @@ protected:
*/
lib::error_code init_asio (io_service_ptr service, bool is_server) {
if (!m_tls_init_handler) {
return socket::make_error(socket::error::missing_tls_init_handler);
return socket::make_error_code(socket::error::missing_tls_init_handler);
}
m_context = m_tls_init_handler(m_hdl);
if (!m_context) {
return socket::make_error(socket::error::invalid_tls_context);
return socket::make_error_code(socket::error::invalid_tls_context);
}
m_socket.reset(new socket_type(*service,*m_context));
@@ -214,6 +214,8 @@ protected:
* @param callback Handler to call back with completion information
*/
void post_init(init_handler callback) {
m_ec = socket::make_error_code(socket::error::tls_handshake_timeout);
// TLS handshake
m_socket->async_handshake(
get_handshake_type(),
@@ -241,11 +243,16 @@ protected:
boost::system::error_code& ec)
{
if (ec) {
callback(socket::make_error(socket::error::pass_through));
return;
m_ec = socket::make_error_code(socket::error::pass_through);
} else {
m_ec = lib::error_code();
}
callback(lib::error_code());
callback(m_ec);
}
const lib::error_code &get_ec() const {
return m_ec;
}
/// Cancel all async operations on this socket
@@ -270,6 +277,8 @@ private:
socket_ptr m_socket;
bool m_is_server;
lib::error_code m_ec;
connection_hdl m_hdl;
socket_init_handler m_socket_init_handler;
tls_init_handler m_tls_init_handler;