Chris@16: // Chris@16: // error.hpp Chris@16: // ~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_ERROR_HPP Chris@16: #define BOOST_ASIO_ERROR_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #if defined(BOOST_ASIO_WINDOWS) \ Chris@16: || defined(__CYGWIN__) \ Chris@16: || defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: # include Chris@16: #else Chris@16: # include Chris@16: # include Chris@16: #endif Chris@16: Chris@16: #if defined(GENERATING_DOCUMENTATION) Chris@16: /// INTERNAL ONLY. Chris@16: # define BOOST_ASIO_NATIVE_ERROR(e) implementation_defined Chris@16: /// INTERNAL ONLY. Chris@16: # define BOOST_ASIO_SOCKET_ERROR(e) implementation_defined Chris@16: /// INTERNAL ONLY. Chris@16: # define BOOST_ASIO_NETDB_ERROR(e) implementation_defined Chris@16: /// INTERNAL ONLY. Chris@16: # define BOOST_ASIO_GETADDRINFO_ERROR(e) implementation_defined Chris@16: /// INTERNAL ONLY. Chris@16: # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined Chris@16: #elif defined(BOOST_ASIO_WINDOWS_RUNTIME) Chris@16: # define BOOST_ASIO_NATIVE_ERROR(e) __HRESULT_FROM_WIN32(e) Chris@16: # define BOOST_ASIO_SOCKET_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e) Chris@16: # define BOOST_ASIO_NETDB_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e) Chris@16: # define BOOST_ASIO_GETADDRINFO_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e) Chris@16: # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win Chris@16: #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__) Chris@16: # define BOOST_ASIO_NATIVE_ERROR(e) e Chris@16: # define BOOST_ASIO_SOCKET_ERROR(e) WSA ## e Chris@16: # define BOOST_ASIO_NETDB_ERROR(e) WSA ## e Chris@16: # define BOOST_ASIO_GETADDRINFO_ERROR(e) WSA ## e Chris@16: # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win Chris@16: #else Chris@16: # define BOOST_ASIO_NATIVE_ERROR(e) e Chris@16: # define BOOST_ASIO_SOCKET_ERROR(e) e Chris@16: # define BOOST_ASIO_NETDB_ERROR(e) e Chris@16: # define BOOST_ASIO_GETADDRINFO_ERROR(e) e Chris@16: # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace error { Chris@16: Chris@16: enum basic_errors Chris@16: { Chris@16: /// Permission denied. Chris@16: access_denied = BOOST_ASIO_SOCKET_ERROR(EACCES), Chris@16: Chris@16: /// Address family not supported by protocol. Chris@16: address_family_not_supported = BOOST_ASIO_SOCKET_ERROR(EAFNOSUPPORT), Chris@16: Chris@16: /// Address already in use. Chris@16: address_in_use = BOOST_ASIO_SOCKET_ERROR(EADDRINUSE), Chris@16: Chris@16: /// Transport endpoint is already connected. Chris@16: already_connected = BOOST_ASIO_SOCKET_ERROR(EISCONN), Chris@16: Chris@16: /// Operation already in progress. Chris@16: already_started = BOOST_ASIO_SOCKET_ERROR(EALREADY), Chris@16: Chris@16: /// Broken pipe. Chris@16: broken_pipe = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE), Chris@16: BOOST_ASIO_NATIVE_ERROR(EPIPE)), Chris@16: Chris@16: /// A connection has been aborted. Chris@16: connection_aborted = BOOST_ASIO_SOCKET_ERROR(ECONNABORTED), Chris@16: Chris@16: /// Connection refused. Chris@16: connection_refused = BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED), Chris@16: Chris@16: /// Connection reset by peer. Chris@16: connection_reset = BOOST_ASIO_SOCKET_ERROR(ECONNRESET), Chris@16: Chris@16: /// Bad file descriptor. Chris@16: bad_descriptor = BOOST_ASIO_SOCKET_ERROR(EBADF), Chris@16: Chris@16: /// Bad address. Chris@16: fault = BOOST_ASIO_SOCKET_ERROR(EFAULT), Chris@16: Chris@16: /// No route to host. Chris@16: host_unreachable = BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH), Chris@16: Chris@16: /// Operation now in progress. Chris@16: in_progress = BOOST_ASIO_SOCKET_ERROR(EINPROGRESS), Chris@16: Chris@16: /// Interrupted system call. Chris@16: interrupted = BOOST_ASIO_SOCKET_ERROR(EINTR), Chris@16: Chris@16: /// Invalid argument. Chris@16: invalid_argument = BOOST_ASIO_SOCKET_ERROR(EINVAL), Chris@16: Chris@16: /// Message too long. Chris@16: message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE), Chris@16: Chris@16: /// The name was too long. Chris@16: name_too_long = BOOST_ASIO_SOCKET_ERROR(ENAMETOOLONG), Chris@16: Chris@16: /// Network is down. Chris@16: network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN), Chris@16: Chris@16: /// Network dropped connection on reset. Chris@16: network_reset = BOOST_ASIO_SOCKET_ERROR(ENETRESET), Chris@16: Chris@16: /// Network is unreachable. Chris@16: network_unreachable = BOOST_ASIO_SOCKET_ERROR(ENETUNREACH), Chris@16: Chris@16: /// Too many open files. Chris@16: no_descriptors = BOOST_ASIO_SOCKET_ERROR(EMFILE), Chris@16: Chris@16: /// No buffer space available. Chris@16: no_buffer_space = BOOST_ASIO_SOCKET_ERROR(ENOBUFS), Chris@16: Chris@16: /// Cannot allocate memory. Chris@16: no_memory = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY), Chris@16: BOOST_ASIO_NATIVE_ERROR(ENOMEM)), Chris@16: Chris@16: /// Operation not permitted. Chris@16: no_permission = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED), Chris@16: BOOST_ASIO_NATIVE_ERROR(EPERM)), Chris@16: Chris@16: /// Protocol not available. Chris@16: no_protocol_option = BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT), Chris@16: Chris@101: /// No such device. Chris@101: no_such_device = BOOST_ASIO_WIN_OR_POSIX( Chris@101: BOOST_ASIO_NATIVE_ERROR(ERROR_BAD_UNIT), Chris@101: BOOST_ASIO_NATIVE_ERROR(ENODEV)), Chris@101: Chris@16: /// Transport endpoint is not connected. Chris@16: not_connected = BOOST_ASIO_SOCKET_ERROR(ENOTCONN), Chris@16: Chris@16: /// Socket operation on non-socket. Chris@16: not_socket = BOOST_ASIO_SOCKET_ERROR(ENOTSOCK), Chris@16: Chris@16: /// Operation cancelled. Chris@16: operation_aborted = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED), Chris@16: BOOST_ASIO_NATIVE_ERROR(ECANCELED)), Chris@16: Chris@16: /// Operation not supported. Chris@16: operation_not_supported = BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP), Chris@16: Chris@16: /// Cannot send after transport endpoint shutdown. Chris@16: shut_down = BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN), Chris@16: Chris@16: /// Connection timed out. Chris@16: timed_out = BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT), Chris@16: Chris@16: /// Resource temporarily unavailable. Chris@16: try_again = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY), Chris@16: BOOST_ASIO_NATIVE_ERROR(EAGAIN)), Chris@16: Chris@16: /// The socket is marked non-blocking and the requested operation would block. Chris@16: would_block = BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK) Chris@16: }; Chris@16: Chris@16: enum netdb_errors Chris@16: { Chris@16: /// Host not found (authoritative). Chris@16: host_not_found = BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND), Chris@16: Chris@16: /// Host not found (non-authoritative). Chris@16: host_not_found_try_again = BOOST_ASIO_NETDB_ERROR(TRY_AGAIN), Chris@16: Chris@16: /// The query is valid but does not have associated address data. Chris@16: no_data = BOOST_ASIO_NETDB_ERROR(NO_DATA), Chris@16: Chris@16: /// A non-recoverable error occurred. Chris@16: no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY) Chris@16: }; Chris@16: Chris@16: enum addrinfo_errors Chris@16: { Chris@16: /// The service is not supported for the given socket type. Chris@16: service_not_found = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND), Chris@16: BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE)), Chris@16: Chris@16: /// The socket type is not supported. Chris@16: socket_type_not_supported = BOOST_ASIO_WIN_OR_POSIX( Chris@16: BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT), Chris@16: BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE)) Chris@16: }; Chris@16: Chris@16: enum misc_errors Chris@16: { Chris@16: /// Already open. Chris@16: already_open = 1, Chris@16: Chris@16: /// End of file or stream. Chris@16: eof, Chris@16: Chris@16: /// Element not found. Chris@16: not_found, Chris@16: Chris@16: /// The descriptor cannot fit into the select system call's fd_set. Chris@16: fd_set_failure Chris@16: }; Chris@16: Chris@16: inline const boost::system::error_category& get_system_category() Chris@16: { Chris@16: return boost::system::system_category(); Chris@16: } Chris@16: Chris@16: #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) Chris@16: Chris@16: extern BOOST_ASIO_DECL Chris@16: const boost::system::error_category& get_netdb_category(); Chris@16: Chris@16: extern BOOST_ASIO_DECL Chris@16: const boost::system::error_category& get_addrinfo_category(); Chris@16: Chris@16: #else // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) Chris@16: Chris@16: inline const boost::system::error_category& get_netdb_category() Chris@16: { Chris@16: return get_system_category(); Chris@16: } Chris@16: Chris@16: inline const boost::system::error_category& get_addrinfo_category() Chris@16: { Chris@16: return get_system_category(); Chris@16: } Chris@16: Chris@16: #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__) Chris@16: Chris@16: extern BOOST_ASIO_DECL Chris@16: const boost::system::error_category& get_misc_category(); Chris@16: Chris@16: static const boost::system::error_category& system_category Chris@16: = boost::asio::error::get_system_category(); Chris@16: static const boost::system::error_category& netdb_category Chris@16: = boost::asio::error::get_netdb_category(); Chris@16: static const boost::system::error_category& addrinfo_category Chris@16: = boost::asio::error::get_addrinfo_category(); Chris@16: static const boost::system::error_category& misc_category Chris@16: = boost::asio::error::get_misc_category(); Chris@16: Chris@16: } // namespace error Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: namespace boost { Chris@16: namespace system { Chris@16: Chris@16: template<> struct is_error_code_enum Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: template<> struct is_error_code_enum Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: template<> struct is_error_code_enum Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: template<> struct is_error_code_enum Chris@16: { Chris@16: static const bool value = true; Chris@16: }; Chris@16: Chris@16: } // namespace system Chris@16: } // namespace boost Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace error { Chris@16: Chris@16: inline boost::system::error_code make_error_code(basic_errors e) Chris@16: { Chris@16: return boost::system::error_code( Chris@16: static_cast(e), get_system_category()); Chris@16: } Chris@16: Chris@16: inline boost::system::error_code make_error_code(netdb_errors e) Chris@16: { Chris@16: return boost::system::error_code( Chris@16: static_cast(e), get_netdb_category()); Chris@16: } Chris@16: Chris@16: inline boost::system::error_code make_error_code(addrinfo_errors e) Chris@16: { Chris@16: return boost::system::error_code( Chris@16: static_cast(e), get_addrinfo_category()); Chris@16: } Chris@16: Chris@16: inline boost::system::error_code make_error_code(misc_errors e) Chris@16: { Chris@16: return boost::system::error_code( Chris@16: static_cast(e), get_misc_category()); Chris@16: } Chris@16: Chris@16: } // namespace error Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #undef BOOST_ASIO_NATIVE_ERROR Chris@16: #undef BOOST_ASIO_SOCKET_ERROR Chris@16: #undef BOOST_ASIO_NETDB_ERROR Chris@16: #undef BOOST_ASIO_GETADDRINFO_ERROR Chris@16: #undef BOOST_ASIO_WIN_OR_POSIX Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // BOOST_ASIO_ERROR_HPP