PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/include/asio/error.hpp

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