PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/boost/boost/asio/error.hpp

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