From 33e64f705af47d3393e2239a047c75ab37d1e48f Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Sun, 15 Feb 2015 17:06:04 +1100 Subject: [PATCH] Map ConnectEx errors to portable equivalents. Fixes boost trac ticket 10744. --- asio/include/asio/detail/impl/socket_ops.ipp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/asio/include/asio/detail/impl/socket_ops.ipp b/asio/include/asio/detail/impl/socket_ops.ipp index 3444d02c..6e65a11b 100644 --- a/asio/include/asio/detail/impl/socket_ops.ipp +++ b/asio/include/asio/detail/impl/socket_ops.ipp @@ -524,6 +524,25 @@ void sync_connect(socket_type s, const socket_addr_type* addr, void complete_iocp_connect(socket_type s, asio::error_code& ec) { + // Map non-portable errors to their portable counterparts. + switch (ec.value()) + { + case ERROR_CONNECTION_REFUSED: + ec = asio::error::connection_refused; + break; + case ERROR_NETWORK_UNREACHABLE: + ec = asio::error::network_unreachable; + break; + case ERROR_HOST_UNREACHABLE: + ec = asio::error::host_unreachable; + break; + case ERROR_SEM_TIMEOUT: + ec = asio::error::timed_out; + break; + default: + break; + } + if (!ec) { // Need to set the SO_UPDATE_CONNECT_CONTEXT option so that getsockname