Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
9.1KB

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