5 // Copyright (c) 2003-2008 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/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/config.hpp>
22 #include <boost/cerrno.hpp>
23 #include <boost/system/error_code.hpp>
24 #include <boost/asio/detail/pop_options.hpp>
26 #include <boost/asio/detail/socket_types.hpp>
28 #if defined(GENERATING_DOCUMENTATION)
30 # define BOOST_ASIO_NATIVE_ERROR(e) implementation_defined
32 # define BOOST_ASIO_SOCKET_ERROR(e) implementation_defined
34 # define BOOST_ASIO_NETDB_ERROR(e) implementation_defined
36 # define BOOST_ASIO_GETADDRINFO_ERROR(e) implementation_defined
38 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
39 #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
40 # define BOOST_ASIO_NATIVE_ERROR(e) e
41 # define BOOST_ASIO_SOCKET_ERROR(e) WSA ## e
42 # define BOOST_ASIO_NETDB_ERROR(e) WSA ## e
43 # define BOOST_ASIO_GETADDRINFO_ERROR(e) WSA ## e
44 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
46 # define BOOST_ASIO_NATIVE_ERROR(e) e
47 # define BOOST_ASIO_SOCKET_ERROR(e) e
48 # define BOOST_ASIO_NETDB_ERROR(e) e
49 # define BOOST_ASIO_GETADDRINFO_ERROR(e) e
50 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
59 /// Permission denied.
60 access_denied
= BOOST_ASIO_SOCKET_ERROR(EACCES
),
62 /// Address family not supported by protocol.
63 address_family_not_supported
= BOOST_ASIO_SOCKET_ERROR(EAFNOSUPPORT
),
65 /// Address already in use.
66 address_in_use
= BOOST_ASIO_SOCKET_ERROR(EADDRINUSE
),
68 /// Transport endpoint is already connected.
69 already_connected
= BOOST_ASIO_SOCKET_ERROR(EISCONN
),
71 /// Operation already in progress.
72 already_started
= BOOST_ASIO_SOCKET_ERROR(EALREADY
),
75 broken_pipe
= BOOST_ASIO_WIN_OR_POSIX(
76 BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE
),
77 BOOST_ASIO_NATIVE_ERROR(EPIPE
)),
79 /// A connection has been aborted.
80 connection_aborted
= BOOST_ASIO_SOCKET_ERROR(ECONNABORTED
),
82 /// Connection refused.
83 connection_refused
= BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED
),
85 /// Connection reset by peer.
86 connection_reset
= BOOST_ASIO_SOCKET_ERROR(ECONNRESET
),
88 /// Bad file descriptor.
89 bad_descriptor
= BOOST_ASIO_SOCKET_ERROR(EBADF
),
92 fault
= BOOST_ASIO_SOCKET_ERROR(EFAULT
),
95 host_unreachable
= BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH
),
97 /// Operation now in progress.
98 in_progress
= BOOST_ASIO_SOCKET_ERROR(EINPROGRESS
),
100 /// Interrupted system call.
101 interrupted
= BOOST_ASIO_SOCKET_ERROR(EINTR
),
103 /// Invalid argument.
104 invalid_argument
= BOOST_ASIO_SOCKET_ERROR(EINVAL
),
106 /// Message too long.
107 message_size
= BOOST_ASIO_SOCKET_ERROR(EMSGSIZE
),
109 /// The name was too long.
110 name_too_long
= BOOST_ASIO_SOCKET_ERROR(ENAMETOOLONG
),
113 network_down
= BOOST_ASIO_SOCKET_ERROR(ENETDOWN
),
115 /// Network dropped connection on reset.
116 network_reset
= BOOST_ASIO_SOCKET_ERROR(ENETRESET
),
118 /// Network is unreachable.
119 network_unreachable
= BOOST_ASIO_SOCKET_ERROR(ENETUNREACH
),
121 /// Too many open files.
122 no_descriptors
= BOOST_ASIO_SOCKET_ERROR(EMFILE
),
124 /// No buffer space available.
125 no_buffer_space
= BOOST_ASIO_SOCKET_ERROR(ENOBUFS
),
127 /// Cannot allocate memory.
128 no_memory
= BOOST_ASIO_WIN_OR_POSIX(
129 BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY
),
130 BOOST_ASIO_NATIVE_ERROR(ENOMEM
)),
132 /// Operation not permitted.
133 no_permission
= BOOST_ASIO_WIN_OR_POSIX(
134 BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED
),
135 BOOST_ASIO_NATIVE_ERROR(EPERM
)),
137 /// Protocol not available.
138 no_protocol_option
= BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT
),
140 /// Transport endpoint is not connected.
141 not_connected
= BOOST_ASIO_SOCKET_ERROR(ENOTCONN
),
143 /// Socket operation on non-socket.
144 not_socket
= BOOST_ASIO_SOCKET_ERROR(ENOTSOCK
),
146 /// Operation cancelled.
147 operation_aborted
= BOOST_ASIO_WIN_OR_POSIX(
148 BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED
),
149 BOOST_ASIO_NATIVE_ERROR(ECANCELED
)),
151 /// Operation not supported.
152 operation_not_supported
= BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP
),
154 /// Cannot send after transport endpoint shutdown.
155 shut_down
= BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN
),
157 /// Connection timed out.
158 timed_out
= BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT
),
160 /// Resource temporarily unavailable.
161 try_again
= BOOST_ASIO_WIN_OR_POSIX(
162 BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY
),
163 BOOST_ASIO_NATIVE_ERROR(EAGAIN
)),
165 /// The socket is marked non-blocking and the requested operation would block.
166 would_block
= BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK
)
171 /// Host not found (authoritative).
172 host_not_found
= BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND
),
174 /// Host not found (non-authoritative).
175 host_not_found_try_again
= BOOST_ASIO_NETDB_ERROR(TRY_AGAIN
),
177 /// The query is valid but does not have associated address data.
178 no_data
= BOOST_ASIO_NETDB_ERROR(NO_DATA
),
180 /// A non-recoverable error occurred.
181 no_recovery
= BOOST_ASIO_NETDB_ERROR(NO_RECOVERY
)
186 /// The service is not supported for the given socket type.
187 service_not_found
= BOOST_ASIO_WIN_OR_POSIX(
188 BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND
),
189 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE
)),
191 /// The socket type is not supported.
192 socket_type_not_supported
= BOOST_ASIO_WIN_OR_POSIX(
193 BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT
),
194 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE
))
202 /// End of file or stream.
205 /// Element not found.
208 /// The descriptor cannot fit into the select system call's fd_set.
216 inline const boost::system::error_category
& get_system_category()
218 return boost::system::get_system_category();
221 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
225 class netdb_category
: public boost::system::error_category
228 const char* name() const
233 std::string
message(int value
) const
235 if (value
== error::host_not_found
)
236 return "Host not found (authoritative)";
237 if (value
== error::host_not_found_try_again
)
238 return "Host not found (non-authoritative), try again later";
239 if (value
== error::no_data
)
240 return "The query is valid, but it does not have associated data";
241 if (value
== error::no_recovery
)
242 return "A non-recoverable error occurred during database lookup";
243 return "asio.netdb error";
247 } // namespace detail
249 inline const boost::system::error_category
& get_netdb_category()
251 static detail::netdb_category instance
;
257 class addrinfo_category
: public boost::system::error_category
260 const char* name() const
262 return "asio.addrinfo";
265 std::string
message(int value
) const
267 if (value
== error::service_not_found
)
268 return "Service not found";
269 if (value
== error::socket_type_not_supported
)
270 return "Socket type not supported";
271 return "asio.addrinfo error";
275 } // namespace detail
277 inline const boost::system::error_category
& get_addrinfo_category()
279 static detail::addrinfo_category instance
;
283 #else // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
285 inline const boost::system::error_category
& get_netdb_category()
287 return get_system_category();
290 inline const boost::system::error_category
& get_addrinfo_category()
292 return get_system_category();
295 #endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
299 class misc_category
: public boost::system::error_category
302 const char* name() const
307 std::string
message(int value
) const
309 if (value
== error::already_open
)
310 return "Already open";
311 if (value
== error::eof
)
312 return "End of file";
313 if (value
== error::not_found
)
314 return "Element not found";
315 if (value
== error::fd_set_failure
)
316 return "The descriptor does not fit into the select call's fd_set";
317 return "asio.misc error";
321 } // namespace detail
323 inline const boost::system::error_category
& get_misc_category()
325 static detail::misc_category instance
;
331 class ssl_category
: public boost::system::error_category
334 const char* name() const
339 std::string
message(int) const
341 return "asio.ssl error";
345 } // namespace detail
347 inline const boost::system::error_category
& get_ssl_category()
349 static detail::ssl_category instance
;
353 static const boost::system::error_category
& system_category
354 = boost::asio::error::get_system_category();
355 static const boost::system::error_category
& netdb_category
356 = boost::asio::error::get_netdb_category();
357 static const boost::system::error_category
& addrinfo_category
358 = boost::asio::error::get_addrinfo_category();
359 static const boost::system::error_category
& misc_category
360 = boost::asio::error::get_misc_category();
361 static const boost::system::error_category
& ssl_category
362 = boost::asio::error::get_ssl_category();
369 template<> struct is_error_code_enum
<boost::asio::error::basic_errors
>
371 static const bool value
= true;
374 template<> struct is_error_code_enum
<boost::asio::error::netdb_errors
>
376 static const bool value
= true;
379 template<> struct is_error_code_enum
<boost::asio::error::addrinfo_errors
>
381 static const bool value
= true;
384 template<> struct is_error_code_enum
<boost::asio::error::misc_errors
>
386 static const bool value
= true;
389 template<> struct is_error_code_enum
<boost::asio::error::ssl_errors
>
391 static const bool value
= true;
394 } // namespace system
399 inline boost::system::error_code
make_error_code(basic_errors e
)
401 return boost::system::error_code(
402 static_cast<int>(e
), get_system_category());
405 inline boost::system::error_code
make_error_code(netdb_errors e
)
407 return boost::system::error_code(
408 static_cast<int>(e
), get_netdb_category());
411 inline boost::system::error_code
make_error_code(addrinfo_errors e
)
413 return boost::system::error_code(
414 static_cast<int>(e
), get_addrinfo_category());
417 inline boost::system::error_code
make_error_code(misc_errors e
)
419 return boost::system::error_code(
420 static_cast<int>(e
), get_misc_category());
423 inline boost::system::error_code
make_error_code(ssl_errors e
)
425 return boost::system::error_code(
426 static_cast<int>(e
), get_ssl_category());
433 #undef BOOST_ASIO_NATIVE_ERROR
434 #undef BOOST_ASIO_SOCKET_ERROR
435 #undef BOOST_ASIO_NETDB_ERROR
436 #undef BOOST_ASIO_GETADDRINFO_ERROR
437 #undef BOOST_ASIO_WIN_OR_POSIX
440 #include <boost/asio/detail/pop_options.hpp>
442 #endif // BOOST_ASIO_ERROR_HPP