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