Chris@16
|
1 //
|
Chris@16
|
2 // error.hpp
|
Chris@16
|
3 // ~~~~~~~~~
|
Chris@16
|
4 //
|
Chris@16
|
5 // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
Chris@16
|
6 //
|
Chris@16
|
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_ASIO_ERROR_HPP
|
Chris@16
|
12 #define BOOST_ASIO_ERROR_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
15 # pragma once
|
Chris@16
|
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/asio/detail/config.hpp>
|
Chris@16
|
19 #include <boost/cerrno.hpp>
|
Chris@16
|
20 #include <boost/system/error_code.hpp>
|
Chris@16
|
21 #if defined(BOOST_ASIO_WINDOWS) \
|
Chris@16
|
22 || defined(__CYGWIN__) \
|
Chris@16
|
23 || defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
24 # include <winerror.h>
|
Chris@16
|
25 #else
|
Chris@16
|
26 # include <cerrno>
|
Chris@16
|
27 # include <netdb.h>
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 #if defined(GENERATING_DOCUMENTATION)
|
Chris@16
|
31 /// INTERNAL ONLY.
|
Chris@16
|
32 # define BOOST_ASIO_NATIVE_ERROR(e) implementation_defined
|
Chris@16
|
33 /// INTERNAL ONLY.
|
Chris@16
|
34 # define BOOST_ASIO_SOCKET_ERROR(e) implementation_defined
|
Chris@16
|
35 /// INTERNAL ONLY.
|
Chris@16
|
36 # define BOOST_ASIO_NETDB_ERROR(e) implementation_defined
|
Chris@16
|
37 /// INTERNAL ONLY.
|
Chris@16
|
38 # define BOOST_ASIO_GETADDRINFO_ERROR(e) implementation_defined
|
Chris@16
|
39 /// INTERNAL ONLY.
|
Chris@16
|
40 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
|
Chris@16
|
41 #elif defined(BOOST_ASIO_WINDOWS_RUNTIME)
|
Chris@16
|
42 # define BOOST_ASIO_NATIVE_ERROR(e) __HRESULT_FROM_WIN32(e)
|
Chris@16
|
43 # define BOOST_ASIO_SOCKET_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
|
Chris@16
|
44 # define BOOST_ASIO_NETDB_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
|
Chris@16
|
45 # define BOOST_ASIO_GETADDRINFO_ERROR(e) __HRESULT_FROM_WIN32(WSA ## e)
|
Chris@16
|
46 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
|
Chris@16
|
47 #elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
|
Chris@16
|
48 # define BOOST_ASIO_NATIVE_ERROR(e) e
|
Chris@16
|
49 # define BOOST_ASIO_SOCKET_ERROR(e) WSA ## e
|
Chris@16
|
50 # define BOOST_ASIO_NETDB_ERROR(e) WSA ## e
|
Chris@16
|
51 # define BOOST_ASIO_GETADDRINFO_ERROR(e) WSA ## e
|
Chris@16
|
52 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
|
Chris@16
|
53 #else
|
Chris@16
|
54 # define BOOST_ASIO_NATIVE_ERROR(e) e
|
Chris@16
|
55 # define BOOST_ASIO_SOCKET_ERROR(e) e
|
Chris@16
|
56 # define BOOST_ASIO_NETDB_ERROR(e) e
|
Chris@16
|
57 # define BOOST_ASIO_GETADDRINFO_ERROR(e) e
|
Chris@16
|
58 # define BOOST_ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
|
Chris@16
|
59 #endif
|
Chris@16
|
60
|
Chris@16
|
61 #include <boost/asio/detail/push_options.hpp>
|
Chris@16
|
62
|
Chris@16
|
63 namespace boost {
|
Chris@16
|
64 namespace asio {
|
Chris@16
|
65 namespace error {
|
Chris@16
|
66
|
Chris@16
|
67 enum basic_errors
|
Chris@16
|
68 {
|
Chris@16
|
69 /// Permission denied.
|
Chris@16
|
70 access_denied = BOOST_ASIO_SOCKET_ERROR(EACCES),
|
Chris@16
|
71
|
Chris@16
|
72 /// Address family not supported by protocol.
|
Chris@16
|
73 address_family_not_supported = BOOST_ASIO_SOCKET_ERROR(EAFNOSUPPORT),
|
Chris@16
|
74
|
Chris@16
|
75 /// Address already in use.
|
Chris@16
|
76 address_in_use = BOOST_ASIO_SOCKET_ERROR(EADDRINUSE),
|
Chris@16
|
77
|
Chris@16
|
78 /// Transport endpoint is already connected.
|
Chris@16
|
79 already_connected = BOOST_ASIO_SOCKET_ERROR(EISCONN),
|
Chris@16
|
80
|
Chris@16
|
81 /// Operation already in progress.
|
Chris@16
|
82 already_started = BOOST_ASIO_SOCKET_ERROR(EALREADY),
|
Chris@16
|
83
|
Chris@16
|
84 /// Broken pipe.
|
Chris@16
|
85 broken_pipe = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
86 BOOST_ASIO_NATIVE_ERROR(ERROR_BROKEN_PIPE),
|
Chris@16
|
87 BOOST_ASIO_NATIVE_ERROR(EPIPE)),
|
Chris@16
|
88
|
Chris@16
|
89 /// A connection has been aborted.
|
Chris@16
|
90 connection_aborted = BOOST_ASIO_SOCKET_ERROR(ECONNABORTED),
|
Chris@16
|
91
|
Chris@16
|
92 /// Connection refused.
|
Chris@16
|
93 connection_refused = BOOST_ASIO_SOCKET_ERROR(ECONNREFUSED),
|
Chris@16
|
94
|
Chris@16
|
95 /// Connection reset by peer.
|
Chris@16
|
96 connection_reset = BOOST_ASIO_SOCKET_ERROR(ECONNRESET),
|
Chris@16
|
97
|
Chris@16
|
98 /// Bad file descriptor.
|
Chris@16
|
99 bad_descriptor = BOOST_ASIO_SOCKET_ERROR(EBADF),
|
Chris@16
|
100
|
Chris@16
|
101 /// Bad address.
|
Chris@16
|
102 fault = BOOST_ASIO_SOCKET_ERROR(EFAULT),
|
Chris@16
|
103
|
Chris@16
|
104 /// No route to host.
|
Chris@16
|
105 host_unreachable = BOOST_ASIO_SOCKET_ERROR(EHOSTUNREACH),
|
Chris@16
|
106
|
Chris@16
|
107 /// Operation now in progress.
|
Chris@16
|
108 in_progress = BOOST_ASIO_SOCKET_ERROR(EINPROGRESS),
|
Chris@16
|
109
|
Chris@16
|
110 /// Interrupted system call.
|
Chris@16
|
111 interrupted = BOOST_ASIO_SOCKET_ERROR(EINTR),
|
Chris@16
|
112
|
Chris@16
|
113 /// Invalid argument.
|
Chris@16
|
114 invalid_argument = BOOST_ASIO_SOCKET_ERROR(EINVAL),
|
Chris@16
|
115
|
Chris@16
|
116 /// Message too long.
|
Chris@16
|
117 message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE),
|
Chris@16
|
118
|
Chris@16
|
119 /// The name was too long.
|
Chris@16
|
120 name_too_long = BOOST_ASIO_SOCKET_ERROR(ENAMETOOLONG),
|
Chris@16
|
121
|
Chris@16
|
122 /// Network is down.
|
Chris@16
|
123 network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN),
|
Chris@16
|
124
|
Chris@16
|
125 /// Network dropped connection on reset.
|
Chris@16
|
126 network_reset = BOOST_ASIO_SOCKET_ERROR(ENETRESET),
|
Chris@16
|
127
|
Chris@16
|
128 /// Network is unreachable.
|
Chris@16
|
129 network_unreachable = BOOST_ASIO_SOCKET_ERROR(ENETUNREACH),
|
Chris@16
|
130
|
Chris@16
|
131 /// Too many open files.
|
Chris@16
|
132 no_descriptors = BOOST_ASIO_SOCKET_ERROR(EMFILE),
|
Chris@16
|
133
|
Chris@16
|
134 /// No buffer space available.
|
Chris@16
|
135 no_buffer_space = BOOST_ASIO_SOCKET_ERROR(ENOBUFS),
|
Chris@16
|
136
|
Chris@16
|
137 /// Cannot allocate memory.
|
Chris@16
|
138 no_memory = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
139 BOOST_ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY),
|
Chris@16
|
140 BOOST_ASIO_NATIVE_ERROR(ENOMEM)),
|
Chris@16
|
141
|
Chris@16
|
142 /// Operation not permitted.
|
Chris@16
|
143 no_permission = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
144 BOOST_ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED),
|
Chris@16
|
145 BOOST_ASIO_NATIVE_ERROR(EPERM)),
|
Chris@16
|
146
|
Chris@16
|
147 /// Protocol not available.
|
Chris@16
|
148 no_protocol_option = BOOST_ASIO_SOCKET_ERROR(ENOPROTOOPT),
|
Chris@16
|
149
|
Chris@16
|
150 /// Transport endpoint is not connected.
|
Chris@16
|
151 not_connected = BOOST_ASIO_SOCKET_ERROR(ENOTCONN),
|
Chris@16
|
152
|
Chris@16
|
153 /// Socket operation on non-socket.
|
Chris@16
|
154 not_socket = BOOST_ASIO_SOCKET_ERROR(ENOTSOCK),
|
Chris@16
|
155
|
Chris@16
|
156 /// Operation cancelled.
|
Chris@16
|
157 operation_aborted = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
158 BOOST_ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED),
|
Chris@16
|
159 BOOST_ASIO_NATIVE_ERROR(ECANCELED)),
|
Chris@16
|
160
|
Chris@16
|
161 /// Operation not supported.
|
Chris@16
|
162 operation_not_supported = BOOST_ASIO_SOCKET_ERROR(EOPNOTSUPP),
|
Chris@16
|
163
|
Chris@16
|
164 /// Cannot send after transport endpoint shutdown.
|
Chris@16
|
165 shut_down = BOOST_ASIO_SOCKET_ERROR(ESHUTDOWN),
|
Chris@16
|
166
|
Chris@16
|
167 /// Connection timed out.
|
Chris@16
|
168 timed_out = BOOST_ASIO_SOCKET_ERROR(ETIMEDOUT),
|
Chris@16
|
169
|
Chris@16
|
170 /// Resource temporarily unavailable.
|
Chris@16
|
171 try_again = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
172 BOOST_ASIO_NATIVE_ERROR(ERROR_RETRY),
|
Chris@16
|
173 BOOST_ASIO_NATIVE_ERROR(EAGAIN)),
|
Chris@16
|
174
|
Chris@16
|
175 /// The socket is marked non-blocking and the requested operation would block.
|
Chris@16
|
176 would_block = BOOST_ASIO_SOCKET_ERROR(EWOULDBLOCK)
|
Chris@16
|
177 };
|
Chris@16
|
178
|
Chris@16
|
179 enum netdb_errors
|
Chris@16
|
180 {
|
Chris@16
|
181 /// Host not found (authoritative).
|
Chris@16
|
182 host_not_found = BOOST_ASIO_NETDB_ERROR(HOST_NOT_FOUND),
|
Chris@16
|
183
|
Chris@16
|
184 /// Host not found (non-authoritative).
|
Chris@16
|
185 host_not_found_try_again = BOOST_ASIO_NETDB_ERROR(TRY_AGAIN),
|
Chris@16
|
186
|
Chris@16
|
187 /// The query is valid but does not have associated address data.
|
Chris@16
|
188 no_data = BOOST_ASIO_NETDB_ERROR(NO_DATA),
|
Chris@16
|
189
|
Chris@16
|
190 /// A non-recoverable error occurred.
|
Chris@16
|
191 no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY)
|
Chris@16
|
192 };
|
Chris@16
|
193
|
Chris@16
|
194 enum addrinfo_errors
|
Chris@16
|
195 {
|
Chris@16
|
196 /// The service is not supported for the given socket type.
|
Chris@16
|
197 service_not_found = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
198 BOOST_ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND),
|
Chris@16
|
199 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SERVICE)),
|
Chris@16
|
200
|
Chris@16
|
201 /// The socket type is not supported.
|
Chris@16
|
202 socket_type_not_supported = BOOST_ASIO_WIN_OR_POSIX(
|
Chris@16
|
203 BOOST_ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT),
|
Chris@16
|
204 BOOST_ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE))
|
Chris@16
|
205 };
|
Chris@16
|
206
|
Chris@16
|
207 enum misc_errors
|
Chris@16
|
208 {
|
Chris@16
|
209 /// Already open.
|
Chris@16
|
210 already_open = 1,
|
Chris@16
|
211
|
Chris@16
|
212 /// End of file or stream.
|
Chris@16
|
213 eof,
|
Chris@16
|
214
|
Chris@16
|
215 /// Element not found.
|
Chris@16
|
216 not_found,
|
Chris@16
|
217
|
Chris@16
|
218 /// The descriptor cannot fit into the select system call's fd_set.
|
Chris@16
|
219 fd_set_failure
|
Chris@16
|
220 };
|
Chris@16
|
221
|
Chris@16
|
222 inline const boost::system::error_category& get_system_category()
|
Chris@16
|
223 {
|
Chris@16
|
224 return boost::system::system_category();
|
Chris@16
|
225 }
|
Chris@16
|
226
|
Chris@16
|
227 #if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
|
Chris@16
|
228
|
Chris@16
|
229 extern BOOST_ASIO_DECL
|
Chris@16
|
230 const boost::system::error_category& get_netdb_category();
|
Chris@16
|
231
|
Chris@16
|
232 extern BOOST_ASIO_DECL
|
Chris@16
|
233 const boost::system::error_category& get_addrinfo_category();
|
Chris@16
|
234
|
Chris@16
|
235 #else // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
|
Chris@16
|
236
|
Chris@16
|
237 inline const boost::system::error_category& get_netdb_category()
|
Chris@16
|
238 {
|
Chris@16
|
239 return get_system_category();
|
Chris@16
|
240 }
|
Chris@16
|
241
|
Chris@16
|
242 inline const boost::system::error_category& get_addrinfo_category()
|
Chris@16
|
243 {
|
Chris@16
|
244 return get_system_category();
|
Chris@16
|
245 }
|
Chris@16
|
246
|
Chris@16
|
247 #endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
|
Chris@16
|
248
|
Chris@16
|
249 extern BOOST_ASIO_DECL
|
Chris@16
|
250 const boost::system::error_category& get_misc_category();
|
Chris@16
|
251
|
Chris@16
|
252 static const boost::system::error_category& system_category
|
Chris@16
|
253 = boost::asio::error::get_system_category();
|
Chris@16
|
254 static const boost::system::error_category& netdb_category
|
Chris@16
|
255 = boost::asio::error::get_netdb_category();
|
Chris@16
|
256 static const boost::system::error_category& addrinfo_category
|
Chris@16
|
257 = boost::asio::error::get_addrinfo_category();
|
Chris@16
|
258 static const boost::system::error_category& misc_category
|
Chris@16
|
259 = boost::asio::error::get_misc_category();
|
Chris@16
|
260
|
Chris@16
|
261 } // namespace error
|
Chris@16
|
262 } // namespace asio
|
Chris@16
|
263 } // namespace boost
|
Chris@16
|
264
|
Chris@16
|
265 namespace boost {
|
Chris@16
|
266 namespace system {
|
Chris@16
|
267
|
Chris@16
|
268 template<> struct is_error_code_enum<boost::asio::error::basic_errors>
|
Chris@16
|
269 {
|
Chris@16
|
270 static const bool value = true;
|
Chris@16
|
271 };
|
Chris@16
|
272
|
Chris@16
|
273 template<> struct is_error_code_enum<boost::asio::error::netdb_errors>
|
Chris@16
|
274 {
|
Chris@16
|
275 static const bool value = true;
|
Chris@16
|
276 };
|
Chris@16
|
277
|
Chris@16
|
278 template<> struct is_error_code_enum<boost::asio::error::addrinfo_errors>
|
Chris@16
|
279 {
|
Chris@16
|
280 static const bool value = true;
|
Chris@16
|
281 };
|
Chris@16
|
282
|
Chris@16
|
283 template<> struct is_error_code_enum<boost::asio::error::misc_errors>
|
Chris@16
|
284 {
|
Chris@16
|
285 static const bool value = true;
|
Chris@16
|
286 };
|
Chris@16
|
287
|
Chris@16
|
288 } // namespace system
|
Chris@16
|
289 } // namespace boost
|
Chris@16
|
290
|
Chris@16
|
291 namespace boost {
|
Chris@16
|
292 namespace asio {
|
Chris@16
|
293 namespace error {
|
Chris@16
|
294
|
Chris@16
|
295 inline boost::system::error_code make_error_code(basic_errors e)
|
Chris@16
|
296 {
|
Chris@16
|
297 return boost::system::error_code(
|
Chris@16
|
298 static_cast<int>(e), get_system_category());
|
Chris@16
|
299 }
|
Chris@16
|
300
|
Chris@16
|
301 inline boost::system::error_code make_error_code(netdb_errors e)
|
Chris@16
|
302 {
|
Chris@16
|
303 return boost::system::error_code(
|
Chris@16
|
304 static_cast<int>(e), get_netdb_category());
|
Chris@16
|
305 }
|
Chris@16
|
306
|
Chris@16
|
307 inline boost::system::error_code make_error_code(addrinfo_errors e)
|
Chris@16
|
308 {
|
Chris@16
|
309 return boost::system::error_code(
|
Chris@16
|
310 static_cast<int>(e), get_addrinfo_category());
|
Chris@16
|
311 }
|
Chris@16
|
312
|
Chris@16
|
313 inline boost::system::error_code make_error_code(misc_errors e)
|
Chris@16
|
314 {
|
Chris@16
|
315 return boost::system::error_code(
|
Chris@16
|
316 static_cast<int>(e), get_misc_category());
|
Chris@16
|
317 }
|
Chris@16
|
318
|
Chris@16
|
319 } // namespace error
|
Chris@16
|
320 } // namespace asio
|
Chris@16
|
321 } // namespace boost
|
Chris@16
|
322
|
Chris@16
|
323 #include <boost/asio/detail/pop_options.hpp>
|
Chris@16
|
324
|
Chris@16
|
325 #undef BOOST_ASIO_NATIVE_ERROR
|
Chris@16
|
326 #undef BOOST_ASIO_SOCKET_ERROR
|
Chris@16
|
327 #undef BOOST_ASIO_NETDB_ERROR
|
Chris@16
|
328 #undef BOOST_ASIO_GETADDRINFO_ERROR
|
Chris@16
|
329 #undef BOOST_ASIO_WIN_OR_POSIX
|
Chris@16
|
330
|
Chris@16
|
331 #if defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
332 # include <boost/asio/impl/error.ipp>
|
Chris@16
|
333 #endif // defined(BOOST_ASIO_HEADER_ONLY)
|
Chris@16
|
334
|
Chris@16
|
335 #endif // BOOST_ASIO_ERROR_HPP
|