5 // Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_ERROR_HPP
12 #define BOOST_ASIO_ERROR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/cerrno.hpp>
20 #include <boost/system/error_code.hpp>
21 #include <boost/system/system_error.hpp>
22 #if defined(BOOST_ASIO_WINDOWS) \
23 || defined(__CYGWIN__) \
24 || defined(BOOST_ASIO_WINDOWS_RUNTIME)
25 # include <winerror.h>
31 #if defined(GENERATING_DOCUMENTATION)
33 # define BOOST_ASIO_NATIVE_ERROR(e) implementation_defined
35 # define BOOST_ASIO_SOCKET_ERROR(e) implementation_defined
37 # define BOOST_ASIO_NETDB_ERROR(e) implementation_defined
39 # define BOOST_ASIO_GETADDRINFO_ERROR(e) implementation_defined
41 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
42 #elif defined(BOOST_ASIO_WINDOWS_RUNTIME)
43 # define BOOST_ASIO_NATIVE_ERROR(e) __HRESULT_FROM_WIN32(e)
44 # define BOOST_ASIO_SOCKET_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
45 # define BOOST_ASIO_NETDB_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
46 # define BOOST_ASIO_GETADDRINFO_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
47 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
48 #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
49 # define BOOST_ASIO_NATIVE_ERROR(e) e
50 # define BOOST_ASIO_SOCKET_ERROR(e) WSA ## e
51 # define BOOST_ASIO_NETDB_ERROR(e) WSA ## e
52 # define BOOST_ASIO_GETADDRINFO_ERROR(e) WSA ## e
53 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
55 # define BOOST_ASIO_NATIVE_ERROR(e) e
56 # define BOOST_ASIO_SOCKET_ERROR(e) e
57 # define BOOST_ASIO_NETDB_ERROR(e) e
58 # define BOOST_ASIO_GETADDRINFO_ERROR(e) e
59 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
62 #include <boost/asio/detail/push_options.hpp>
70 /// Permission denied.
71 access_denied = BOOST_ASIO_SOCKET_ERROR(EACCES),
73 /// Address family not supported by protocol.
74 address_family_not_supported = BOOST_ASIO_SOCKET_ERROR(EAFNOSUPPORT),
76 /// Address already in use.
77 address_in_use = BOOST_ASIO_SOCKET_ERROR(EADDRINUSE),
79 /// Transport endpoint is already connected.
80 already_connected = BOOST_ASIO_SOCKET_ERROR(EISCONN),
82 /// Operation already in progress.
83 already_started = BOOST_ASIO_SOCKET_ERROR(EALREADY),
86 broken_pipe = BOOST_ASIO_WIN_OR_POSIX(
87 BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE),
88 BOOST_ASIO_NATIVE_ERROR(EPIPE)),
90 /// A connection has been aborted.
91 connection_aborted = BOOST_ASIO_SOCKET_ERROR(ECONNABORTED),
93 /// Connection refused.
94 connection_refused = BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED),
96 /// Connection reset by peer.
97 connection_reset = BOOST_ASIO_SOCKET_ERROR(ECONNRESET),
99 /// Bad file descriptor.
100 bad_descriptor = BOOST_ASIO_SOCKET_ERROR(EBADF),
103 fault = BOOST_ASIO_SOCKET_ERROR(EFAULT),
105 /// No route to host.
106 host_unreachable = BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH),
108 /// Operation now in progress.
109 in_progress = BOOST_ASIO_SOCKET_ERROR(EINPROGRESS),
111 /// Interrupted system call.
112 interrupted = BOOST_ASIO_SOCKET_ERROR(EINTR),
114 /// Invalid argument.
115 invalid_argument = BOOST_ASIO_SOCKET_ERROR(EINVAL),
117 /// Message too long.
118 message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE),
120 /// The name was too long.
121 name_too_long = BOOST_ASIO_SOCKET_ERROR(ENAMETOOLONG),
124 network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN),
126 /// Network dropped connection on reset.
127 network_reset = BOOST_ASIO_SOCKET_ERROR(ENETRESET),
129 /// Network is unreachable.
130 network_unreachable = BOOST_ASIO_SOCKET_ERROR(ENETUNREACH),
132 /// Too many open files.
133 no_descriptors = BOOST_ASIO_SOCKET_ERROR(EMFILE),
135 /// No buffer space available.
136 no_buffer_space = BOOST_ASIO_SOCKET_ERROR(ENOBUFS),
138 /// Cannot allocate memory.
139 no_memory = BOOST_ASIO_WIN_OR_POSIX(
140 BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY),
141 BOOST_ASIO_NATIVE_ERROR(ENOMEM)),
143 /// Operation not permitted.
144 no_permission = BOOST_ASIO_WIN_OR_POSIX(
145 BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED),
146 BOOST_ASIO_NATIVE_ERROR(EPERM)),
148 /// Protocol not available.
149 no_protocol_option = BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT),
151 /// Transport endpoint is not connected.
152 not_connected = BOOST_ASIO_SOCKET_ERROR(ENOTCONN),
154 /// Socket operation on non-socket.
155 not_socket = BOOST_ASIO_SOCKET_ERROR(ENOTSOCK),
157 /// Operation cancelled.
158 operation_aborted = BOOST_ASIO_WIN_OR_POSIX(
159 BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED),
160 BOOST_ASIO_NATIVE_ERROR(ECANCELED)),
162 /// Operation not supported.
163 operation_not_supported = BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP),
165 /// Cannot send after transport endpoint shutdown.
166 shut_down = BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN),
168 /// Connection timed out.
169 timed_out = BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT),
171 /// Resource temporarily unavailable.
172 try_again = BOOST_ASIO_WIN_OR_POSIX(
173 BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY),
174 BOOST_ASIO_NATIVE_ERROR(EAGAIN)),
176 /// The socket is marked non-blocking and the requested operation would block.
177 would_block = BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK)
182 /// Host not found (authoritative).
183 host_not_found = BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND),
185 /// Host not found (non-authoritative).
186 host_not_found_try_again = BOOST_ASIO_NETDB_ERROR(TRY_AGAIN),
188 /// The query is valid but does not have associated address data.
189 no_data = BOOST_ASIO_NETDB_ERROR(NO_DATA),
191 /// A non-recoverable error occurred.
192 no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY)
197 /// The service is not supported for the given socket type.
198 service_not_found = BOOST_ASIO_WIN_OR_POSIX(
199 BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND),
200 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE)),
202 /// The socket type is not supported.
203 socket_type_not_supported = BOOST_ASIO_WIN_OR_POSIX(
204 BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT),
205 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE))
213 /// End of file or stream.
216 /// Element not found.
219 /// The descriptor cannot fit into the select system call's fd_set.
223 inline const boost::system::error_category& get_system_category()
225 return boost::system::system_category();
228 #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
230 extern BOOST_ASIO_DECL
231 const boost::system::error_category& get_netdb_category();
233 extern BOOST_ASIO_DECL
234 const boost::system::error_category& get_addrinfo_category();
236 #else // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
238 inline const boost::system::error_category& get_netdb_category()
240 return get_system_category();
243 inline const boost::system::error_category& get_addrinfo_category()
245 return get_system_category();
248 #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
250 extern BOOST_ASIO_DECL
251 const boost::system::error_category& get_misc_category();
253 static const boost::system::error_category& system_category
254 = boost::asio::error::get_system_category();
255 static const boost::system::error_category& netdb_category
256 = boost::asio::error::get_netdb_category();
257 static const boost::system::error_category& addrinfo_category
258 = boost::asio::error::get_addrinfo_category();
259 static const boost::system::error_category& misc_category
260 = boost::asio::error::get_misc_category();
269 template<> struct is_error_code_enum<boost::asio::error::basic_errors>
271 static const bool value = true;
274 template<> struct is_error_code_enum<boost::asio::error::netdb_errors>
276 static const bool value = true;
279 template<> struct is_error_code_enum<boost::asio::error::addrinfo_errors>
281 static const bool value = true;
284 template<> struct is_error_code_enum<boost::asio::error::misc_errors>
286 static const bool value = true;
289 } // namespace system
296 inline boost::system::error_code make_error_code(basic_errors e)
298 return boost::system::error_code(
299 static_cast<int>(e), get_system_category());
302 inline boost::system::error_code make_error_code(netdb_errors e)
304 return boost::system::error_code(
305 static_cast<int>(e), get_netdb_category());
308 inline boost::system::error_code make_error_code(addrinfo_errors e)
310 return boost::system::error_code(
311 static_cast<int>(e), get_addrinfo_category());
314 inline boost::system::error_code make_error_code(misc_errors e)
316 return boost::system::error_code(
317 static_cast<int>(e), get_misc_category());
324 #include <boost/asio/detail/pop_options.hpp>
326 #undef BOOST_ASIO_NATIVE_ERROR
327 #undef BOOST_ASIO_SOCKET_ERROR
328 #undef BOOST_ASIO_NETDB_ERROR
329 #undef BOOST_ASIO_GETADDRINFO_ERROR
330 #undef BOOST_ASIO_WIN_OR_POSIX
332 #if defined(BOOST_ASIO_HEADER_ONLY)
333 # include <boost/asio/impl/error.ipp>
334 #endif // defined(BOOST_ASIO_HEADER_ONLY)
336 #endif // BOOST_ASIO_ERROR_HPP