PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/deps/sdk/include/boost/asio/error.hpp

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