00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_ERROR_HPP
00012 #define ASIO_ERROR_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <cerrno>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024
00025 #include "asio/error_code.hpp"
00026 #include "asio/detail/socket_types.hpp"
00027
00028 #if defined(GENERATING_DOCUMENTATION)
00030 # define ASIO_NATIVE_ERROR(e) implementation_defined
00032 # define ASIO_SOCKET_ERROR(e) implementation_defined
00034 # define ASIO_NETDB_ERROR(e) implementation_defined
00036 # define ASIO_GETADDRINFO_ERROR(e) implementation_defined
00038 # define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
00039 #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
00040 # define ASIO_NATIVE_ERROR(e) \
00041 asio::error_code(e, \
00042 asio::native_ecat)
00043 # define ASIO_SOCKET_ERROR(e) \
00044 asio::error_code(WSA ## e, \
00045 asio::native_ecat)
00046 # define ASIO_NETDB_ERROR(e) \
00047 asio::error_code(WSA ## e, \
00048 asio::native_ecat)
00049 # define ASIO_GETADDRINFO_ERROR(e) \
00050 asio::error_code(WSA ## e, \
00051 asio::native_ecat)
00052 # define ASIO_MISC_ERROR(e) \
00053 asio::error_code(e, \
00054 asio::misc_ecat)
00055 # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
00056 #else
00057 # define ASIO_NATIVE_ERROR(e) \
00058 asio::error_code(e, \
00059 asio::native_ecat)
00060 # define ASIO_SOCKET_ERROR(e) \
00061 asio::error_code(e, \
00062 asio::native_ecat)
00063 # define ASIO_NETDB_ERROR(e) \
00064 asio::error_code(e, \
00065 asio::netdb_ecat)
00066 # define ASIO_GETADDRINFO_ERROR(e) \
00067 asio::error_code(e, \
00068 asio::addrinfo_ecat)
00069 # define ASIO_MISC_ERROR(e) \
00070 asio::error_code(e, \
00071 asio::misc_ecat)
00072 # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
00073 #endif
00074
00075 namespace asio {
00076
00077 namespace detail {
00078
00080 template <typename T>
00081 class error_base
00082 {
00083 public:
00084
00085
00087 static const asio::error_code access_denied;
00088
00090 static const asio::error_code address_family_not_supported;
00091
00093 static const asio::error_code address_in_use;
00094
00096 static const asio::error_code already_connected;
00097
00099 static const asio::error_code already_open;
00100
00102 static const asio::error_code already_started;
00103
00105 static const asio::error_code connection_aborted;
00106
00108 static const asio::error_code connection_refused;
00109
00111 static const asio::error_code connection_reset;
00112
00114 static const asio::error_code bad_descriptor;
00115
00117 static const asio::error_code eof;
00118
00120 static const asio::error_code fault;
00121
00123 static const asio::error_code host_not_found;
00124
00126 static const asio::error_code host_not_found_try_again;
00127
00129 static const asio::error_code host_unreachable;
00130
00132 static const asio::error_code in_progress;
00133
00135 static const asio::error_code interrupted;
00136
00138 static const asio::error_code invalid_argument;
00139
00141 static const asio::error_code message_size;
00142
00144 static const asio::error_code network_down;
00145
00147 static const asio::error_code network_reset;
00148
00150 static const asio::error_code network_unreachable;
00151
00153 static const asio::error_code no_descriptors;
00154
00156 static const asio::error_code no_buffer_space;
00157
00159 static const asio::error_code no_data;
00160
00162 static const asio::error_code no_memory;
00163
00165 static const asio::error_code no_permission;
00166
00168 static const asio::error_code no_protocol_option;
00169
00171 static const asio::error_code no_recovery;
00172
00174 static const asio::error_code not_connected;
00175
00177 static const asio::error_code not_found;
00178
00180 static const asio::error_code not_socket;
00181
00183 static const asio::error_code operation_aborted;
00184
00186 static const asio::error_code operation_not_supported;
00187
00189 static const asio::error_code service_not_found;
00190
00192 static const asio::error_code socket_type_not_supported;
00193
00195 static const asio::error_code shut_down;
00196
00198 static const asio::error_code timed_out;
00199
00201 static const asio::error_code try_again;
00202
00204 static const asio::error_code would_block;
00205
00206 private:
00207 error_base();
00208 };
00209
00210
00211
00212 template <typename T> const asio::error_code
00213 error_base<T>::access_denied = ASIO_SOCKET_ERROR(EACCES);
00214
00215 template <typename T> const asio::error_code
00216 error_base<T>::address_family_not_supported = ASIO_SOCKET_ERROR(
00217 EAFNOSUPPORT);
00218
00219 template <typename T> const asio::error_code
00220 error_base<T>::address_in_use = ASIO_SOCKET_ERROR(EADDRINUSE);
00221
00222 template <typename T> const asio::error_code
00223 error_base<T>::already_connected = ASIO_SOCKET_ERROR(EISCONN);
00224
00225 template <typename T> const asio::error_code
00226 error_base<T>::already_open = ASIO_MISC_ERROR(1);
00227
00228 template <typename T> const asio::error_code
00229 error_base<T>::already_started = ASIO_SOCKET_ERROR(EALREADY);
00230
00231 template <typename T> const asio::error_code
00232 error_base<T>::connection_aborted = ASIO_SOCKET_ERROR(ECONNABORTED);
00233
00234 template <typename T> const asio::error_code
00235 error_base<T>::connection_refused = ASIO_SOCKET_ERROR(ECONNREFUSED);
00236
00237 template <typename T> const asio::error_code
00238 error_base<T>::connection_reset = ASIO_SOCKET_ERROR(ECONNRESET);
00239
00240 template <typename T> const asio::error_code
00241 error_base<T>::bad_descriptor = ASIO_SOCKET_ERROR(EBADF);
00242
00243 template <typename T> const asio::error_code
00244 error_base<T>::eof = ASIO_MISC_ERROR(2);
00245
00246 template <typename T> const asio::error_code
00247 error_base<T>::fault = ASIO_SOCKET_ERROR(EFAULT);
00248
00249 template <typename T> const asio::error_code
00250 error_base<T>::host_not_found = ASIO_NETDB_ERROR(HOST_NOT_FOUND);
00251
00252 template <typename T> const asio::error_code
00253 error_base<T>::host_not_found_try_again = ASIO_NETDB_ERROR(TRY_AGAIN);
00254
00255 template <typename T> const asio::error_code
00256 error_base<T>::host_unreachable = ASIO_SOCKET_ERROR(EHOSTUNREACH);
00257
00258 template <typename T> const asio::error_code
00259 error_base<T>::in_progress = ASIO_SOCKET_ERROR(EINPROGRESS);
00260
00261 template <typename T> const asio::error_code
00262 error_base<T>::interrupted = ASIO_SOCKET_ERROR(EINTR);
00263
00264 template <typename T> const asio::error_code
00265 error_base<T>::invalid_argument = ASIO_SOCKET_ERROR(EINVAL);
00266
00267 template <typename T> const asio::error_code
00268 error_base<T>::message_size = ASIO_SOCKET_ERROR(EMSGSIZE);
00269
00270 template <typename T> const asio::error_code
00271 error_base<T>::network_down = ASIO_SOCKET_ERROR(ENETDOWN);
00272
00273 template <typename T> const asio::error_code
00274 error_base<T>::network_reset = ASIO_SOCKET_ERROR(ENETRESET);
00275
00276 template <typename T> const asio::error_code
00277 error_base<T>::network_unreachable = ASIO_SOCKET_ERROR(ENETUNREACH);
00278
00279 template <typename T> const asio::error_code
00280 error_base<T>::no_descriptors = ASIO_SOCKET_ERROR(EMFILE);
00281
00282 template <typename T> const asio::error_code
00283 error_base<T>::no_buffer_space = ASIO_SOCKET_ERROR(ENOBUFS);
00284
00285 template <typename T> const asio::error_code
00286 error_base<T>::no_data = ASIO_NETDB_ERROR(NO_DATA);
00287
00288 template <typename T> const asio::error_code
00289 error_base<T>::no_memory = ASIO_WIN_OR_POSIX(
00290 ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY),
00291 ASIO_NATIVE_ERROR(ENOMEM));
00292
00293 template <typename T> const asio::error_code
00294 error_base<T>::no_permission = ASIO_WIN_OR_POSIX(
00295 ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED),
00296 ASIO_NATIVE_ERROR(EPERM));
00297
00298 template <typename T> const asio::error_code
00299 error_base<T>::no_protocol_option = ASIO_SOCKET_ERROR(ENOPROTOOPT);
00300
00301 template <typename T> const asio::error_code
00302 error_base<T>::no_recovery = ASIO_NETDB_ERROR(NO_RECOVERY);
00303
00304 template <typename T> const asio::error_code
00305 error_base<T>::not_connected = ASIO_SOCKET_ERROR(ENOTCONN);
00306
00307 template <typename T> const asio::error_code
00308 error_base<T>::not_found = ASIO_MISC_ERROR(3);
00309
00310 template <typename T> const asio::error_code
00311 error_base<T>::not_socket = ASIO_SOCKET_ERROR(ENOTSOCK);
00312
00313 template <typename T> const asio::error_code
00314 error_base<T>::operation_aborted = ASIO_WIN_OR_POSIX(
00315 ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED),
00316 ASIO_NATIVE_ERROR(ECANCELED));
00317
00318 template <typename T> const asio::error_code
00319 error_base<T>::operation_not_supported = ASIO_SOCKET_ERROR(EOPNOTSUPP);
00320
00321 template <typename T> const asio::error_code
00322 error_base<T>::service_not_found = ASIO_WIN_OR_POSIX(
00323 ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND),
00324 ASIO_GETADDRINFO_ERROR(EAI_SERVICE));
00325
00326 template <typename T> const asio::error_code
00327 error_base<T>::socket_type_not_supported = ASIO_WIN_OR_POSIX(
00328 ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT),
00329 ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE));
00330
00331 template <typename T> const asio::error_code
00332 error_base<T>::shut_down = ASIO_SOCKET_ERROR(ESHUTDOWN);
00333
00334 template <typename T> const asio::error_code
00335 error_base<T>::timed_out = ASIO_SOCKET_ERROR(ETIMEDOUT);
00336
00337 template <typename T> const asio::error_code
00338 error_base<T>::try_again = ASIO_WIN_OR_POSIX(
00339 ASIO_NATIVE_ERROR(ERROR_RETRY),
00340 ASIO_NATIVE_ERROR(EAGAIN));
00341
00342 template <typename T> const asio::error_code
00343 error_base<T>::would_block = ASIO_SOCKET_ERROR(EWOULDBLOCK);
00344
00345 }
00346
00348 class error : public asio::detail::error_base<error>
00349 {
00350 private:
00351 error();
00352 };
00353
00354 }
00355
00356 #undef ASIO_NATIVE_ERROR
00357 #undef ASIO_SOCKET_ERROR
00358 #undef ASIO_NETDB_ERROR
00359 #undef ASIO_GETADDRINFO_ERROR
00360 #undef ASIO_MISC_ERROR
00361 #undef ASIO_WIN_OR_POSIX
00362
00363 #include "asio/impl/error_code.ipp"
00364
00365 #include "asio/detail/pop_options.hpp"
00366
00367 #endif // ASIO_ERROR_HPP