From 3e05da91c14dc02fef460d63d36ea7a8640e3104 Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Tue, 11 Sep 2007 11:17:56 +0000 Subject: [PATCH] Use enum-based error code constants. [SVN r39189] --- include/boost/asio/detail/epoll_reactor.hpp | 21 +- include/boost/asio/detail/kqueue_reactor.hpp | 31 +- include/boost/asio/detail/posix_event.hpp | 3 +- include/boost/asio/detail/posix_mutex.hpp | 7 +- include/boost/asio/detail/posix_thread.hpp | 3 +- include/boost/asio/detail/posix_tss_ptr.hpp | 3 +- .../asio/detail/reactive_socket_service.hpp | 8 +- include/boost/asio/detail/socket_ops.hpp | 9 +- include/boost/asio/detail/win_event.hpp | 4 +- .../boost/asio/detail/win_iocp_io_service.hpp | 14 +- .../asio/detail/win_iocp_socket_service.hpp | 52 +- include/boost/asio/detail/win_mutex.hpp | 5 +- include/boost/asio/detail/win_thread.hpp | 4 +- include/boost/asio/detail/win_tss_ptr.hpp | 4 +- include/boost/asio/detail/winsock_init.hpp | 3 +- include/boost/asio/error.hpp | 770 ++++++++---------- include/boost/asio/impl/read_until.ipp | 18 +- .../asio/ssl/detail/openssl_operation.hpp | 4 +- test/Jamfile | 5 +- test/error.cpp | 4 +- test/is_read_buffered.cpp | 16 +- test/is_write_buffered.cpp | 16 +- 22 files changed, 469 insertions(+), 535 deletions(-) diff --git a/include/boost/asio/detail/epoll_reactor.hpp b/include/boost/asio/detail/epoll_reactor.hpp index 9f5aec74..7c73c194 100644 --- a/include/boost/asio/detail/epoll_reactor.hpp +++ b/include/boost/asio/detail/epoll_reactor.hpp @@ -158,7 +158,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -191,7 +192,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -220,7 +222,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -251,7 +254,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); except_op_queue_.dispatch_all_operations(descriptor, ec); } @@ -428,7 +432,8 @@ private: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - ec = boost::system::error_code(errno, boost::system::native_ecat); + ec = boost::system::error_code(errno, + boost::asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); write_op_queue_.dispatch_all_operations(descriptor, ec); except_op_queue_.dispatch_all_operations(descriptor, ec); @@ -486,8 +491,10 @@ private: int fd = epoll_create(epoll_size); if (fd == -1) { - boost::throw_exception(boost::system::system_error( - boost::system::error_code(errno, boost::system::native_ecat), + boost::throw_exception( + boost::system::system_error( + boost::system::error_code(errno, + boost::asio::error::system_category), "epoll")); } return fd; diff --git a/include/boost/asio/detail/kqueue_reactor.hpp b/include/boost/asio/detail/kqueue_reactor.hpp index 4a8064f8..c49c8e34 100644 --- a/include/boost/asio/detail/kqueue_reactor.hpp +++ b/include/boost/asio/detail/kqueue_reactor.hpp @@ -151,7 +151,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -177,7 +178,8 @@ public: EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -202,7 +204,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -225,7 +228,8 @@ public: EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -239,7 +243,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code ec(errno, boost::system::native_ecat); + boost::system::error_code ec(errno, + boost::asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); write_op_queue_.dispatch_all_operations(descriptor, ec); } @@ -393,7 +398,7 @@ private: if (events[i].flags & EV_ERROR) { boost::system::error_code error( - events[i].data, boost::system::native_ecat); + events[i].data, boost::asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, error); read_op_queue_.dispatch_all_operations(descriptor, error); } @@ -423,7 +428,8 @@ private: EV_SET(&event, descriptor, EVFILT_READ, EV_DELETE, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code error(errno, boost::system::native_ecat); + boost::system::error_code error(errno, + boost::asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, error); read_op_queue_.dispatch_all_operations(descriptor, error); } @@ -435,7 +441,7 @@ private: if (events[i].flags & EV_ERROR) { boost::system::error_code error( - events[i].data, boost::system::native_ecat); + events[i].data, boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, error); } else @@ -452,7 +458,8 @@ private: EV_SET(&event, descriptor, EVFILT_WRITE, EV_DELETE, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - boost::system::error_code error(errno, boost::system::native_ecat); + boost::system::error_code error(errno, + boost::asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, error); } } @@ -506,8 +513,10 @@ private: int fd = kqueue(); if (fd == -1) { - boost::throw_exception(boost::system::system_error( - boost::system::error_code(errno, boost::system::native_ecat), + boost::throw_exception( + boost::system::system_error( + boost::system::error_code(errno, + boost::asio::error::system_category), "kqueue")); } return fd; diff --git a/include/boost/asio/detail/posix_event.hpp b/include/boost/asio/detail/posix_event.hpp index c7bb4e73..e6f3b160 100644 --- a/include/boost/asio/detail/posix_event.hpp +++ b/include/boost/asio/detail/posix_event.hpp @@ -30,6 +30,7 @@ #include #include +#include #include namespace boost { @@ -48,7 +49,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "event"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/posix_mutex.hpp b/include/boost/asio/detail/posix_mutex.hpp index 47b99327..56dd1211 100644 --- a/include/boost/asio/detail/posix_mutex.hpp +++ b/include/boost/asio/detail/posix_mutex.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -51,7 +52,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -70,7 +71,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -83,7 +84,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "mutex"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/posix_thread.hpp b/include/boost/asio/detail/posix_thread.hpp index cb2f2891..c51ff143 100644 --- a/include/boost/asio/detail/posix_thread.hpp +++ b/include/boost/asio/detail/posix_thread.hpp @@ -30,6 +30,7 @@ #include #include +#include #include namespace boost { @@ -53,7 +54,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "thread"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/posix_tss_ptr.hpp b/include/boost/asio/detail/posix_tss_ptr.hpp index d8d34b06..f235b765 100644 --- a/include/boost/asio/detail/posix_tss_ptr.hpp +++ b/include/boost/asio/detail/posix_tss_ptr.hpp @@ -29,6 +29,7 @@ #include #include +#include #include namespace boost { @@ -47,7 +48,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "tss"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/reactive_socket_service.hpp b/include/boost/asio/detail/reactive_socket_service.hpp index 922e8264..58772c5f 100644 --- a/include/boost/asio/detail/reactive_socket_service.hpp +++ b/include/boost/asio/detail/reactive_socket_service.hpp @@ -158,7 +158,7 @@ public: if (int err = reactor_.register_descriptor(sock.get())) { - ec = boost::system::error_code(err, boost::system::native_ecat); + ec = boost::system::error_code(err, boost::asio::error::system_category); return ec; } @@ -182,7 +182,7 @@ public: if (int err = reactor_.register_descriptor(native_socket)) { - ec = boost::system::error_code(err, boost::system::native_ecat); + ec = boost::system::error_code(err, boost::asio::error::system_category); return ec; } @@ -1125,7 +1125,7 @@ public: bool operator()(const boost::system::error_code& result) { // Check whether the operation was successful. - if (result != 0) + if (result) { io_service_.post(bind_handler(handler_, result, 0)); return true; @@ -1490,7 +1490,7 @@ public: if (connect_error) { ec = boost::system::error_code(connect_error, - boost::system::native_ecat); + boost::asio::error::system_category); io_service_.post(bind_handler(handler_, ec)); return true; } diff --git a/include/boost/asio/detail/socket_ops.hpp b/include/boost/asio/detail/socket_ops.hpp index fb860d33..dcd6ba6e 100644 --- a/include/boost/asio/detail/socket_ops.hpp +++ b/include/boost/asio/detail/socket_ops.hpp @@ -53,9 +53,10 @@ inline ReturnType error_wrapper(ReturnType return_value, boost::system::error_code& ec) { #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) - ec = boost::system::error_code(WSAGetLastError(), boost::system::native_ecat); + ec = boost::system::error_code(WSAGetLastError(), + boost::asio::error::system_category); #else - ec = boost::system::error_code(errno, boost::system::native_ecat); + ec = boost::system::error_code(errno, boost::asio::error::system_category); #endif return return_value; } @@ -1519,10 +1520,10 @@ inline boost::system::error_code translate_addrinfo_error(int error) default: // Possibly the non-portable EAI_SYSTEM. #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) return boost::system::error_code( - WSAGetLastError(), boost::system::native_ecat); + WSAGetLastError(), boost::asio::error::system_category); #else return boost::system::error_code( - errno, boost::system::native_ecat); + errno, boost::asio::error::system_category); #endif } } diff --git a/include/boost/asio/detail/win_event.hpp b/include/boost/asio/detail/win_event.hpp index 187f1552..4ddb0198 100644 --- a/include/boost/asio/detail/win_event.hpp +++ b/include/boost/asio/detail/win_event.hpp @@ -24,6 +24,7 @@ #if defined(BOOST_WINDOWS) +#include #include #include @@ -48,7 +49,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "event"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/win_iocp_io_service.hpp b/include/boost/asio/detail/win_iocp_io_service.hpp index 9c1a2b3e..83c9eeed 100644 --- a/include/boost/asio/detail/win_iocp_io_service.hpp +++ b/include/boost/asio/detail/win_iocp_io_service.hpp @@ -64,7 +64,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "iocp"); boost::throw_exception(e); } @@ -174,7 +175,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -229,7 +231,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -248,7 +251,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -313,7 +317,7 @@ private: { DWORD last_error = ::GetLastError(); ec = boost::system::error_code(last_error, - boost::system::native_ecat); + boost::asio::error::system_category); return 0; } diff --git a/include/boost/asio/detail/win_iocp_socket_service.hpp b/include/boost/asio/detail/win_iocp_socket_service.hpp index ef681218..0698426b 100644 --- a/include/boost/asio/detail/win_iocp_socket_service.hpp +++ b/include/boost/asio/detail/win_iocp_socket_service.hpp @@ -338,7 +338,8 @@ public: if (!cancel_io_ex(sock_as_handle, 0)) { DWORD last_error = ::GetLastError(); - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); } else { @@ -359,7 +360,8 @@ public: if (!::CancelIo(sock_as_handle)) { DWORD last_error = ::GetLastError(); - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); } else { @@ -665,7 +667,8 @@ public: last_error = WSAECONNRESET; else if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); return 0; } @@ -716,7 +719,8 @@ public: #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); if (ec.value() == ERROR_NETNAME_DELETED) { if (handler_op->cancel_token_.expired()) @@ -818,7 +822,8 @@ public: { boost::asio::io_service::work work(this->io_service()); ptr.reset(); - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -862,7 +867,8 @@ public: DWORD last_error = ::WSAGetLastError(); if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); return 0; } @@ -911,7 +917,8 @@ public: #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); if (ec.value() == ERROR_PORT_UNREACHABLE) { ec = boost::asio::error::connection_refused; @@ -994,7 +1001,8 @@ public: { boost::asio::io_service::work work(this->io_service()); ptr.reset(); - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1048,7 +1056,8 @@ public: last_error = WSAECONNRESET; else if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); return 0; } if (bytes_transferred == 0) @@ -1106,7 +1115,8 @@ public: #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); if (ec.value() == ERROR_NETNAME_DELETED) { if (handler_op->cancel_token_.expired()) @@ -1213,7 +1223,8 @@ public: { boost::asio::io_service::work work(this->io_service()); ptr.reset(); - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1259,7 +1270,8 @@ public: DWORD last_error = ::WSAGetLastError(); if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = boost::system::error_code(last_error, boost::system::native_ecat); + ec = boost::system::error_code(last_error, + boost::asio::error::system_category); return 0; } if (bytes_transferred == 0) @@ -1325,7 +1337,8 @@ public: #endif // defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); if (ec.value() == ERROR_PORT_UNREACHABLE) { ec = boost::asio::error::connection_refused; @@ -1419,7 +1432,8 @@ public: { boost::asio::io_service::work work(this->io_service()); ptr.reset(); - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1656,7 +1670,8 @@ public: ptr.reset(); // Call the handler. - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); asio_handler_invoke_helpers::invoke( detail::bind_handler(handler, ec), &handler); } @@ -1756,7 +1771,8 @@ public: { boost::asio::io_service::work work(this->io_service()); ptr.reset(); - boost::system::error_code ec(last_error, boost::system::native_ecat); + boost::system::error_code ec(last_error, + boost::asio::error::system_category); iocp_service_.post(bind_handler(handler, ec)); } } @@ -1832,8 +1848,8 @@ public: // If connection failed then post the handler with the error code. if (connect_error) { - ec = boost::system::error_code( - connect_error, boost::system::native_ecat); + ec = boost::system::error_code(connect_error, + boost::asio::error::system_category); io_service_.post(bind_handler(handler_, ec)); return true; } diff --git a/include/boost/asio/detail/win_mutex.hpp b/include/boost/asio/detail/win_mutex.hpp index ed150ff8..f171c45d 100644 --- a/include/boost/asio/detail/win_mutex.hpp +++ b/include/boost/asio/detail/win_mutex.hpp @@ -24,6 +24,7 @@ #if defined(BOOST_WINDOWS) +#include #include #include #include @@ -49,7 +50,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -68,7 +69,7 @@ public: if (error != 0) { boost::system::system_error e( - boost::system::error_code(error, boost::system::native_ecat), + boost::system::error_code(error, boost::asio::error::system_category), "mutex"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/win_thread.hpp b/include/boost/asio/detail/win_thread.hpp index 0cfc770d..b838ce78 100644 --- a/include/boost/asio/detail/win_thread.hpp +++ b/include/boost/asio/detail/win_thread.hpp @@ -24,6 +24,7 @@ #if defined(BOOST_WINDOWS) +#include #include #include @@ -55,7 +56,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "thread"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/win_tss_ptr.hpp b/include/boost/asio/detail/win_tss_ptr.hpp index 7a3950d1..32144540 100644 --- a/include/boost/asio/detail/win_tss_ptr.hpp +++ b/include/boost/asio/detail/win_tss_ptr.hpp @@ -24,6 +24,7 @@ #if defined(BOOST_WINDOWS) +#include #include #include @@ -48,7 +49,8 @@ public: { DWORD last_error = ::GetLastError(); boost::system::system_error e( - boost::system::error_code(last_error, boost::system::native_ecat), + boost::system::error_code(last_error, + boost::asio::error::system_category), "tss"); boost::throw_exception(e); } diff --git a/include/boost/asio/detail/winsock_init.hpp b/include/boost/asio/detail/winsock_init.hpp index ea68f2a9..b89f7097 100644 --- a/include/boost/asio/detail/winsock_init.hpp +++ b/include/boost/asio/detail/winsock_init.hpp @@ -86,7 +86,8 @@ public: if (this != &instance_ && ref_->result() != 0) { boost::system::system_error e( - boost::system::error_code(ref_->result(), boost::system::native_ecat), + boost::system::error_code(ref_->result(), + boost::asio::error::system_category), "winsock"); boost::throw_exception(e); } diff --git a/include/boost/asio/error.hpp b/include/boost/asio/error.hpp index 4c508797..ecca84ac 100644 --- a/include/boost/asio/error.hpp +++ b/include/boost/asio/error.hpp @@ -37,493 +37,372 @@ /// INTERNAL ONLY. # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__) -# define BOOST_ASIO_NATIVE_ERROR(e) \ - boost::system::error_code(e, \ - boost::system::native_ecat) -# define BOOST_ASIO_SOCKET_ERROR(e) \ - boost::system::error_code(WSA ## e, \ - boost::system::native_ecat) -# define BOOST_ASIO_NETDB_ERROR(e) \ - boost::system::error_code(WSA ## e, \ - boost::system::native_ecat) -# define BOOST_ASIO_GETADDRINFO_ERROR(e) \ - boost::system::error_code(WSA ## e, \ - boost::system::native_ecat) -# define BOOST_ASIO_MISC_ERROR(e) \ - boost::system::error_code(e, \ - boost::asio::detail::error_base::misc_ecat()) +# define BOOST_ASIO_NATIVE_ERROR(e) e +# define BOOST_ASIO_SOCKET_ERROR(e) WSA ## e +# define BOOST_ASIO_NETDB_ERROR(e) WSA ## e +# define BOOST_ASIO_GETADDRINFO_ERROR(e) WSA ## e # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win #else -# define BOOST_ASIO_NATIVE_ERROR(e) \ - boost::system::error_code(e, \ - boost::system::native_ecat) -# define BOOST_ASIO_SOCKET_ERROR(e) \ - boost::system::error_code(e, \ - boost::system::native_ecat) -# define BOOST_ASIO_NETDB_ERROR(e) \ - boost::system::error_code(e, \ - boost::asio::detail::error_base::netdb_ecat()) -# define BOOST_ASIO_GETADDRINFO_ERROR(e) \ - boost::system::error_code(e, \ - boost::asio::detail::error_base::addrinfo_ecat()) -# define BOOST_ASIO_MISC_ERROR(e) \ - boost::system::error_code(e, \ - boost::asio::detail::error_base::misc_ecat()) +# define BOOST_ASIO_NATIVE_ERROR(e) e +# define BOOST_ASIO_SOCKET_ERROR(e) e +# define BOOST_ASIO_NETDB_ERROR(e) e +# define BOOST_ASIO_GETADDRINFO_ERROR(e) e # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix #endif namespace boost { namespace asio { +namespace error { + +enum basic_errors +{ + /// Permission denied. + access_denied = BOOST_ASIO_SOCKET_ERROR(EACCES), + + /// Address family not supported by protocol. + address_family_not_supported = BOOST_ASIO_SOCKET_ERROR(EAFNOSUPPORT), + + /// Address already in use. + address_in_use = BOOST_ASIO_SOCKET_ERROR(EADDRINUSE), + + /// Transport endpoint is already connected. + already_connected = BOOST_ASIO_SOCKET_ERROR(EISCONN), + + /// Operation already in progress. + already_started = BOOST_ASIO_SOCKET_ERROR(EALREADY), + + /// A connection has been aborted. + connection_aborted = BOOST_ASIO_SOCKET_ERROR(ECONNABORTED), + + /// Connection refused. + connection_refused = BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED), + + /// Connection reset by peer. + connection_reset = BOOST_ASIO_SOCKET_ERROR(ECONNRESET), + + /// Bad file descriptor. + bad_descriptor = BOOST_ASIO_SOCKET_ERROR(EBADF), + + /// Bad address. + fault = BOOST_ASIO_SOCKET_ERROR(EFAULT), + + /// No route to host. + host_unreachable = BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH), + + /// Operation now in progress. + in_progress = BOOST_ASIO_SOCKET_ERROR(EINPROGRESS), + + /// Interrupted system call. + interrupted = BOOST_ASIO_SOCKET_ERROR(EINTR), + + /// Invalid argument. + invalid_argument = BOOST_ASIO_SOCKET_ERROR(EINVAL), + + /// Message too long. + message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE), + + /// Network is down. + network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN), + + /// Network dropped connection on reset. + network_reset = BOOST_ASIO_SOCKET_ERROR(ENETRESET), + + /// Network is unreachable. + network_unreachable = BOOST_ASIO_SOCKET_ERROR(ENETUNREACH), + + /// Too many open files. + no_descriptors = BOOST_ASIO_SOCKET_ERROR(EMFILE), + + /// No buffer space available. + no_buffer_space = BOOST_ASIO_SOCKET_ERROR(ENOBUFS), + + /// Cannot allocate memory. + no_memory = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY), + BOOST_ASIO_NATIVE_ERROR(ENOMEM)), + + /// Operation not permitted. + no_permission = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED), + BOOST_ASIO_NATIVE_ERROR(EPERM)), + + /// Protocol not available. + no_protocol_option = BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT), + + /// Transport endpoint is not connected. + not_connected = BOOST_ASIO_SOCKET_ERROR(ENOTCONN), + + /// Socket operation on non-socket. + not_socket = BOOST_ASIO_SOCKET_ERROR(ENOTSOCK), + + /// Operation cancelled. + operation_aborted = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED), + BOOST_ASIO_NATIVE_ERROR(ECANCELED)), + + /// Operation not supported. + operation_not_supported = BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP), + + /// Cannot send after transport endpoint shutdown. + shut_down = BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN), + + /// Connection timed out. + timed_out = BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT), + + /// Resource temporarily unavailable. + try_again = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY), + BOOST_ASIO_NATIVE_ERROR(EAGAIN)), + + /// The socket is marked non-blocking and the requested operation would block. + would_block = BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK) +}; + +enum netdb_errors +{ + /// Host not found (authoritative). + host_not_found = BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND), + + /// Host not found (non-authoritative). + host_not_found_try_again = BOOST_ASIO_NETDB_ERROR(TRY_AGAIN), + + /// The query is valid but does not have associated address data. + no_data = BOOST_ASIO_NETDB_ERROR(NO_DATA), + + /// A non-recoverable error occurred. + no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY) +}; + +enum addrinfo_errors +{ + /// The service is not supported for the given socket type. + service_not_found = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND), + BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE)), + + /// The socket type is not supported. + socket_type_not_supported = BOOST_ASIO_WIN_OR_POSIX( + BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT), + BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE)) +}; + +enum misc_errors +{ + /// Already open. + already_open = 1, + + /// End of file or stream. + eof, + + /// Element not found. + not_found +}; namespace detail { -/// Hack to keep asio library header-file-only. -template -class error_base +inline const boost::system::error_category& get_system_category() +{ + return boost::system::system_category; +} + +#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) + +class netdb_category : public boost::system::error_category { public: -#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) - static boost::system::error_category netdb_ecat(); - static int netdb_ed(const boost::system::error_code& ec); - static std::string netdb_md(const boost::system::error_code& ec); - static boost::system::wstring_t netdb_wmd( - const boost::system::error_code& ec); + const char* name() const + { + return "asio.netdb"; + } - static boost::system::error_category addrinfo_ecat(); - static int addrinfo_ed(const boost::system::error_code& ec); - static std::string addrinfo_md(const boost::system::error_code& ec); - static boost::system::wstring_t addrinfo_wmd( - const boost::system::error_code& ec); -#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) - - static boost::system::error_category misc_ecat(); - static int misc_ed(const boost::system::error_code& ec); - static std::string misc_md(const boost::system::error_code& ec); - static boost::system::wstring_t misc_wmd(const boost::system::error_code& ec); - - static boost::system::error_category ssl_ecat(); - static int ssl_ed(const boost::system::error_code& ec); - static std::string ssl_md(const boost::system::error_code& ec); - static boost::system::wstring_t ssl_wmd(const boost::system::error_code& ec); - - /// Permission denied. - static const boost::system::error_code access_denied; - - /// Address family not supported by protocol. - static const boost::system::error_code address_family_not_supported; - - /// Address already in use. - static const boost::system::error_code address_in_use; - - /// Transport endpoint is already connected. - static const boost::system::error_code already_connected; - - /// Already open. - static const boost::system::error_code already_open; - - /// Operation already in progress. - static const boost::system::error_code already_started; - - /// A connection has been aborted. - static const boost::system::error_code connection_aborted; - - /// Connection refused. - static const boost::system::error_code connection_refused; - - /// Connection reset by peer. - static const boost::system::error_code connection_reset; - - /// Bad file descriptor. - static const boost::system::error_code bad_descriptor; - - /// End of file or stream. - static const boost::system::error_code eof; - - /// Bad address. - static const boost::system::error_code fault; - - /// Host not found (authoritative). - static const boost::system::error_code host_not_found; - - /// Host not found (non-authoritative). - static const boost::system::error_code host_not_found_try_again; - - /// No route to host. - static const boost::system::error_code host_unreachable; - - /// Operation now in progress. - static const boost::system::error_code in_progress; - - /// Interrupted system call. - static const boost::system::error_code interrupted; - - /// Invalid argument. - static const boost::system::error_code invalid_argument; - - /// Message too long. - static const boost::system::error_code message_size; - - /// Network is down. - static const boost::system::error_code network_down; - - /// Network dropped connection on reset. - static const boost::system::error_code network_reset; - - /// Network is unreachable. - static const boost::system::error_code network_unreachable; - - /// Too many open files. - static const boost::system::error_code no_descriptors; - - /// No buffer space available. - static const boost::system::error_code no_buffer_space; - - /// The query is valid but does not have associated address data. - static const boost::system::error_code no_data; - - /// Cannot allocate memory. - static const boost::system::error_code no_memory; - - /// Operation not permitted. - static const boost::system::error_code no_permission; - - /// Protocol not available. - static const boost::system::error_code no_protocol_option; - - /// A non-recoverable error occurred. - static const boost::system::error_code no_recovery; - - /// Transport endpoint is not connected. - static const boost::system::error_code not_connected; - - /// Element not found. - static const boost::system::error_code not_found; - - /// Socket operation on non-socket. - static const boost::system::error_code not_socket; - - /// Operation cancelled. - static const boost::system::error_code operation_aborted; - - /// Operation not supported. - static const boost::system::error_code operation_not_supported; - - /// The service is not supported for the given socket type. - static const boost::system::error_code service_not_found; - - /// The socket type is not supported. - static const boost::system::error_code socket_type_not_supported; - - /// Cannot send after transport endpoint shutdown. - static const boost::system::error_code shut_down; - - /// Connection timed out. - static const boost::system::error_code timed_out; - - /// Resource temporarily unavailable. - static const boost::system::error_code try_again; - - /// The socket is marked non-blocking and the requested operation would block. - static const boost::system::error_code would_block; - -private: - error_base(); + std::string message(int value) const + { + if (value == error::host_not_found) + return "Host not found (authoritative)"; + if (value == error::host_not_found_try_again) + return "Host not found (non-authoritative), try again later"; + if (value == error::no_data) + return "The query is valid, but it does not have associated data"; + if (value == error::no_recovery) + return "A non-recoverable error occurred during database lookup"; + return "asio.netdb error"; + } }; -#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) - -template -boost::system::error_category error_base::netdb_ecat() +inline const boost::system::error_category& get_netdb_category() { - static boost::system::error_category ecat = - boost::system::error_code::new_category(&error_base::netdb_ed, - &error_base::netdb_md, &error_base::netdb_wmd); - return ecat; + static netdb_category instance; + return instance; } -template -int error_base::netdb_ed(const boost::system::error_code&) +class addrinfo_category : public boost::system::error_category { - return EOTHER; +public: + const char* name() const + { + return "asio.addrinfo"; + } + + std::string message(int value) const + { + if (value == error::service_not_found) + return "Service not found"; + if (value == error::socket_type_not_supported) + return "Socket type not supported"; + return "asio.addrinfo error"; + } +}; + +inline const boost::system::error_category& get_addrinfo_category() +{ + static addrinfo_category instance; + return instance; } -template -std::string error_base::netdb_md(const boost::system::error_code& ec) +#else // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) + +inline const boost::system::error_category& get_netdb_category() { - if (ec == error_base::host_not_found) - return "Host not found (authoritative)"; - if (ec == error_base::host_not_found_try_again) - return "Host not found (non-authoritative), try again later"; - if (ec == error_base::no_data) - return "The query is valid, but it does not have associated data"; - if (ec == error_base::no_recovery) - return "A non-recoverable error occurred during database lookup"; - return "EINVAL"; + return get_system_category(); } -template -boost::system::wstring_t error_base::netdb_wmd( - const boost::system::error_code& ec) +inline const boost::system::error_category& get_addrinfo_category() { - if (ec == error_base::host_not_found) - return L"Host not found (authoritative)"; - if (ec == error_base::host_not_found_try_again) - return L"Host not found (non-authoritative), try again later"; - if (ec == error_base::no_data) - return L"The query is valid, but it does not have associated data"; - if (ec == error_base::no_recovery) - return L"A non-recoverable error occurred during database lookup"; - return L"EINVAL"; -} - -template -boost::system::error_category error_base::addrinfo_ecat() -{ - static boost::system::error_category ecat = - boost::system::error_code::new_category(&error_base::addrinfo_ed, - &error_base::addrinfo_md, &error_base::addrinfo_wmd); - return ecat; -} - -template -int error_base::addrinfo_ed(const boost::system::error_code&) -{ - return EOTHER; -} - -template -std::string error_base::addrinfo_md(const boost::system::error_code& ec) -{ - if (ec == error_base::service_not_found) - return "Service not found"; - if (ec == error_base::socket_type_not_supported) - return "Socket type not supported"; - return "EINVAL"; -} - -template -boost::system::wstring_t error_base::addrinfo_wmd( - const boost::system::error_code& ec) -{ - if (ec == error_base::service_not_found) - return L"Service not found"; - if (ec == error_base::socket_type_not_supported) - return L"Socket type not supported"; - return L"EINVAL"; + return get_system_category(); } #endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) -template -boost::system::error_category error_base::misc_ecat() +class misc_category : public boost::system::error_category { - static boost::system::error_category ecat = - boost::system::error_code::new_category(&error_base::misc_ed, - &error_base::misc_md, &error_base::misc_wmd); - return ecat; +public: + const char* name() const + { + return "asio.misc"; + } + + std::string message(int value) const + { + if (value == error::already_open) + return "Already open"; + if (value == error::eof) + return "End of file"; + if (value == error::not_found) + return "Element not found"; + return "asio.misc error"; + } +}; + +inline const boost::system::error_category& get_misc_category() +{ + static misc_category instance; + return instance; } -template -int error_base::misc_ed(const boost::system::error_code&) +class ssl_category : public boost::system::error_category { - return EOTHER; -} +public: + const char* name() const + { + return "asio.ssl"; + } -template -std::string error_base::misc_md(const boost::system::error_code& ec) + std::string message(int value) const + { + return "asio.ssl error"; + } +}; + +inline const boost::system::error_category& get_ssl_category() { - if (ec == error_base::already_open) - return "Already open"; - if (ec == error_base::eof) - return "End of file"; - if (ec == error_base::not_found) - return "Element not found"; - return "EINVAL"; + static ssl_category instance; + return instance; } -template -boost::system::wstring_t error_base::misc_wmd( - const boost::system::error_code& ec) -{ - if (ec == error_base::already_open) - return L"Already open"; - if (ec == error_base::eof) - return L"End of file"; - if (ec == error_base::not_found) - return L"Element not found"; - return L"EINVAL"; -} - -template -boost::system::error_category error_base::ssl_ecat() -{ - static boost::system::error_category ecat = - boost::system::error_code::new_category(&error_base::ssl_ed, - &error_base::ssl_md, &error_base::ssl_wmd); - return ecat; -} - -template -int error_base::ssl_ed(const boost::system::error_code&) -{ - return EOTHER; -} - -template -std::string error_base::ssl_md(const boost::system::error_code&) -{ - return "SSL error"; -} - -template -boost::system::wstring_t error_base::ssl_wmd( - const boost::system::error_code&) -{ - return L"SSL error"; -} - -template const boost::system::error_code -error_base::access_denied = BOOST_ASIO_SOCKET_ERROR(EACCES); - -template const boost::system::error_code -error_base::address_family_not_supported = BOOST_ASIO_SOCKET_ERROR( - EAFNOSUPPORT); - -template const boost::system::error_code -error_base::address_in_use = BOOST_ASIO_SOCKET_ERROR(EADDRINUSE); - -template const boost::system::error_code -error_base::already_connected = BOOST_ASIO_SOCKET_ERROR(EISCONN); - -template const boost::system::error_code -error_base::already_open = BOOST_ASIO_MISC_ERROR(1); - -template const boost::system::error_code -error_base::already_started = BOOST_ASIO_SOCKET_ERROR(EALREADY); - -template const boost::system::error_code -error_base::connection_aborted = BOOST_ASIO_SOCKET_ERROR(ECONNABORTED); - -template const boost::system::error_code -error_base::connection_refused = BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED); - -template const boost::system::error_code -error_base::connection_reset = BOOST_ASIO_SOCKET_ERROR(ECONNRESET); - -template const boost::system::error_code -error_base::bad_descriptor = BOOST_ASIO_SOCKET_ERROR(EBADF); - -template const boost::system::error_code -error_base::eof = BOOST_ASIO_MISC_ERROR(2); - -template const boost::system::error_code -error_base::fault = BOOST_ASIO_SOCKET_ERROR(EFAULT); - -template const boost::system::error_code -error_base::host_not_found = BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND); - -template const boost::system::error_code -error_base::host_not_found_try_again = BOOST_ASIO_NETDB_ERROR(TRY_AGAIN); - -template const boost::system::error_code -error_base::host_unreachable = BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH); - -template const boost::system::error_code -error_base::in_progress = BOOST_ASIO_SOCKET_ERROR(EINPROGRESS); - -template const boost::system::error_code -error_base::interrupted = BOOST_ASIO_SOCKET_ERROR(EINTR); - -template const boost::system::error_code -error_base::invalid_argument = BOOST_ASIO_SOCKET_ERROR(EINVAL); - -template const boost::system::error_code -error_base::message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE); - -template const boost::system::error_code -error_base::network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN); - -template const boost::system::error_code -error_base::network_reset = BOOST_ASIO_SOCKET_ERROR(ENETRESET); - -template const boost::system::error_code -error_base::network_unreachable = BOOST_ASIO_SOCKET_ERROR(ENETUNREACH); - -template const boost::system::error_code -error_base::no_descriptors = BOOST_ASIO_SOCKET_ERROR(EMFILE); - -template const boost::system::error_code -error_base::no_buffer_space = BOOST_ASIO_SOCKET_ERROR(ENOBUFS); - -template const boost::system::error_code -error_base::no_data = BOOST_ASIO_NETDB_ERROR(NO_DATA); - -template const boost::system::error_code -error_base::no_memory = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY), - BOOST_ASIO_NATIVE_ERROR(ENOMEM)); - -template const boost::system::error_code -error_base::no_permission = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED), - BOOST_ASIO_NATIVE_ERROR(EPERM)); - -template const boost::system::error_code -error_base::no_protocol_option = BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT); - -template const boost::system::error_code -error_base::no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY); - -template const boost::system::error_code -error_base::not_connected = BOOST_ASIO_SOCKET_ERROR(ENOTCONN); - -template const boost::system::error_code -error_base::not_found = BOOST_ASIO_MISC_ERROR(3); - -template const boost::system::error_code -error_base::not_socket = BOOST_ASIO_SOCKET_ERROR(ENOTSOCK); - -template const boost::system::error_code -error_base::operation_aborted = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED), - BOOST_ASIO_NATIVE_ERROR(ECANCELED)); - -template const boost::system::error_code -error_base::operation_not_supported = BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP); - -template const boost::system::error_code -error_base::service_not_found = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND), - BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE)); - -template const boost::system::error_code -error_base::socket_type_not_supported = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT), - BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE)); - -template const boost::system::error_code -error_base::shut_down = BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN); - -template const boost::system::error_code -error_base::timed_out = BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT); - -template const boost::system::error_code -error_base::try_again = BOOST_ASIO_WIN_OR_POSIX( - BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY), - BOOST_ASIO_NATIVE_ERROR(EAGAIN)); - -template const boost::system::error_code -error_base::would_block = BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK); - } // namespace detail -/// Contains error constants. -class error : public boost::asio::detail::error_base +#if BOOST_WORKAROUND(BOOST_MSVC, < 1400) + +static const boost::system::error_category& system_category + = boost::asio::error::detail::get_system_category(); +static const boost::system::error_category& netdb_category + = boost::asio::error::detail::get_netdb_category(); +static const boost::system::error_category& addrinfo_category + = boost::asio::error::detail::get_addrinfo_category(); +static const boost::system::error_category& misc_category + = boost::asio::error::detail::get_misc_category(); +static const boost::system::error_category& ssl_category + = boost::asio::error::detail::get_ssl_category(); + +#else + +namespace { -private: - error(); + const boost::system::error_category& system_category + = boost::asio::error::detail::get_system_category(); + const boost::system::error_category& netdb_category + = boost::asio::error::detail::get_netdb_category(); + const boost::system::error_category& addrinfo_category + = boost::asio::error::detail::get_addrinfo_category(); + const boost::system::error_category& misc_category + = boost::asio::error::detail::get_misc_category(); + const boost::system::error_category& ssl_category + = boost::asio::error::detail::get_ssl_category(); +} // namespace + +#endif + +} // namespace error +} // namespace asio + +namespace system { + +template<> struct is_error_code_enum +{ + static const bool value = true; }; +template<> struct is_error_code_enum +{ + static const bool value = true; +}; + +template<> struct is_error_code_enum +{ + static const bool value = true; +}; + +template<> struct is_error_code_enum +{ + static const bool value = true; +}; + +} // namespace system + +namespace asio { +namespace error { + +inline boost::system::error_code make_error_code(basic_errors e) +{ + return boost::system::error_code(static_cast(e), system_category); +} + +inline boost::system::error_code make_error_code(netdb_errors e) +{ + return boost::system::error_code(static_cast(e), netdb_category); +} + +inline boost::system::error_code make_error_code(addrinfo_errors e) +{ + return boost::system::error_code(static_cast(e), addrinfo_category); +} + +inline boost::system::error_code make_error_code(misc_errors e) +{ + return boost::system::error_code(static_cast(e), misc_category); +} + +} // namespace error } // namespace asio } // namespace boost @@ -531,7 +410,6 @@ private: #undef BOOST_ASIO_SOCKET_ERROR #undef BOOST_ASIO_NETDB_ERROR #undef BOOST_ASIO_GETADDRINFO_ERROR -#undef BOOST_ASIO_MISC_ERROR #undef BOOST_ASIO_WIN_OR_POSIX diff --git a/include/boost/asio/impl/read_until.ipp b/include/boost/asio/impl/read_until.ipp index ff25fec2..821b80e8 100644 --- a/include/boost/asio/impl/read_until.ipp +++ b/include/boost/asio/impl/read_until.ipp @@ -312,7 +312,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + boost::system::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -389,7 +390,8 @@ void async_read_until(AsyncReadStream& s, // No match. Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + boost::system::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } @@ -470,7 +472,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + boost::system::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -560,7 +563,8 @@ void async_read_until(AsyncReadStream& s, // Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + boost::system::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } @@ -642,7 +646,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + boost::system::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -732,7 +737,8 @@ void async_read_until(AsyncReadStream& s, // Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + boost::system::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } diff --git a/include/boost/asio/ssl/detail/openssl_operation.hpp b/include/boost/asio/ssl/detail/openssl_operation.hpp index a637ba3b..ee4e94e2 100644 --- a/include/boost/asio/ssl/detail/openssl_operation.hpp +++ b/include/boost/asio/ssl/detail/openssl_operation.hpp @@ -175,12 +175,12 @@ public: if (error_code == SSL_ERROR_SYSCALL) { return handler_(boost::system::error_code( - sys_error_code, boost::system::native_ecat), rc); + sys_error_code, boost::asio::error::system_category), rc); } else { return handler_(boost::system::error_code( - error_code, boost::asio::error::ssl_ecat()), rc); + error_code, boost::asio::error::ssl_category), rc); } } diff --git a/test/Jamfile b/test/Jamfile index 0837bfa1..8af28e46 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -8,6 +8,7 @@ subproject libs/asio/test ; project boost : $(BOOST_ROOT) ; +project boost_system : $(BOOST_SYSTEM_ROOT) ; # bring in the rules for testing import testing ; @@ -25,8 +26,8 @@ if $(UNIX) template asio_unit_test : @boost/libs/thread/build/boost_thread - @boost/libs/system/build/boost_system - : ../../.. + @boost_system/libs/system/build/boost_system + : ../../.. @boost @boost_system BOOST_ALL_NO_LIB=1 multi <*>ws2_32 diff --git a/test/error.cpp b/test/error.cpp index 95fc1acf..6ba20676 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -24,8 +24,8 @@ void test_error_code(const boost::system::error_code& code) boost::system::error_code error(code); BOOST_CHECK(code == error); - BOOST_CHECK(code == 0 || error); - BOOST_CHECK(code == 0 || !!error); + BOOST_CHECK(!code || error); + BOOST_CHECK(!code || !!error); boost::system::error_code error2(error); BOOST_CHECK(error == error2); diff --git a/test/is_read_buffered.cpp b/test/is_read_buffered.cpp index 62ecb4e8..1d292220 100644 --- a/test/is_read_buffered.cpp +++ b/test/is_read_buffered.cpp @@ -29,8 +29,6 @@ class test_stream public: typedef boost::asio::io_service io_service_type; - typedef boost::asio::error error_type; - typedef test_stream lowest_layer_type; test_stream(boost::asio::io_service& io_service) @@ -54,16 +52,17 @@ public: return 0; } - template - size_t write(const Const_Buffers&, Error_Handler) + template + size_t write(const Const_Buffers&, boost::system::error_code& ec) { + ec = boost::system::error_code(); return 0; } template void async_write(const Const_Buffers&, Handler handler) { - boost::asio::error error; + boost::system::error_code error; io_service_.post(boost::asio::detail::bind_handler(handler, error, 0)); } @@ -73,16 +72,17 @@ public: return 0; } - template - size_t read(const Mutable_Buffers&, Error_Handler error_handler) + template + size_t read(const Mutable_Buffers&, boost::system::error_code& ec) { + ec = boost::system::error_code(); return 0; } template void async_read(const Mutable_Buffers&, Handler handler) { - boost::asio::error error; + boost::system::error_code error; io_service_.post(boost::asio::detail::bind_handler(handler, error, 0)); } diff --git a/test/is_write_buffered.cpp b/test/is_write_buffered.cpp index 02c68fd4..6af4c633 100644 --- a/test/is_write_buffered.cpp +++ b/test/is_write_buffered.cpp @@ -29,8 +29,6 @@ class test_stream public: typedef boost::asio::io_service io_service_type; - typedef boost::asio::error error_type; - typedef test_stream lowest_layer_type; test_stream(boost::asio::io_service& io_service) @@ -54,16 +52,17 @@ public: return 0; } - template - size_t write(const Const_Buffers&, Error_Handler) + template + size_t write(const Const_Buffers&, boost::system::error_code& ec) { + ec = boost::system::error_code(); return 0; } template void async_write(const Const_Buffers&, Handler handler) { - boost::asio::error error; + boost::system::error_code error; io_service_.post(boost::asio::detail::bind_handler(handler, error, 0)); } @@ -73,16 +72,17 @@ public: return 0; } - template - size_t read(const Mutable_Buffers&, Error_Handler error_handler) + template + size_t read(const Mutable_Buffers&, boost::system::error_code& ec) { + ec = boost::system::error_code(); return 0; } template void async_read(const Mutable_Buffers&, Handler handler) { - boost::asio::error error; + boost::system::error_code error; io_service_.post(boost::asio::detail::bind_handler(handler, error, 0)); }