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.

error.hpp 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. //
  2. // error.hpp
  3. // ~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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&
  197. system_category ASIO_UNUSED_VARIABLE
  198. = asio::error::get_system_category();
  199. static const asio::error_category&
  200. netdb_category ASIO_UNUSED_VARIABLE
  201. = asio::error::get_netdb_category();
  202. static const asio::error_category&
  203. addrinfo_category ASIO_UNUSED_VARIABLE
  204. = asio::error::get_addrinfo_category();
  205. static const asio::error_category&
  206. misc_category ASIO_UNUSED_VARIABLE
  207. = asio::error::get_misc_category();
  208. } // namespace error
  209. } // namespace asio
  210. #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
  211. namespace std {
  212. template<> struct is_error_code_enum<asio::error::basic_errors>
  213. {
  214. static const bool value = true;
  215. };
  216. template<> struct is_error_code_enum<asio::error::netdb_errors>
  217. {
  218. static const bool value = true;
  219. };
  220. template<> struct is_error_code_enum<asio::error::addrinfo_errors>
  221. {
  222. static const bool value = true;
  223. };
  224. template<> struct is_error_code_enum<asio::error::misc_errors>
  225. {
  226. static const bool value = true;
  227. };
  228. } // namespace std
  229. #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
  230. namespace asio {
  231. namespace error {
  232. inline asio::error_code make_error_code(basic_errors e)
  233. {
  234. return asio::error_code(
  235. static_cast<int>(e), get_system_category());
  236. }
  237. inline asio::error_code make_error_code(netdb_errors e)
  238. {
  239. return asio::error_code(
  240. static_cast<int>(e), get_netdb_category());
  241. }
  242. inline asio::error_code make_error_code(addrinfo_errors e)
  243. {
  244. return asio::error_code(
  245. static_cast<int>(e), get_addrinfo_category());
  246. }
  247. inline asio::error_code make_error_code(misc_errors e)
  248. {
  249. return asio::error_code(
  250. static_cast<int>(e), get_misc_category());
  251. }
  252. } // namespace error
  253. namespace stream_errc {
  254. // Simulates the proposed stream_errc scoped enum.
  255. using error::eof;
  256. using error::not_found;
  257. } // namespace stream_errc
  258. namespace socket_errc {
  259. // Simulates the proposed socket_errc scoped enum.
  260. using error::already_open;
  261. using error::not_found;
  262. } // namespace socket_errc
  263. namespace resolver_errc {
  264. // Simulates the proposed resolver_errc scoped enum.
  265. using error::host_not_found;
  266. const error::netdb_errors try_again = error::host_not_found_try_again;
  267. using error::service_not_found;
  268. } // namespace resolver_errc
  269. } // namespace asio
  270. #include "asio/detail/pop_options.hpp"
  271. #undef ASIO_NATIVE_ERROR
  272. #undef ASIO_SOCKET_ERROR
  273. #undef ASIO_NETDB_ERROR
  274. #undef ASIO_GETADDRINFO_ERROR
  275. #undef ASIO_WIN_OR_POSIX
  276. #if defined(ASIO_HEADER_ONLY)
  277. # include "asio/impl/error.ipp"
  278. #endif // defined(ASIO_HEADER_ONLY)
  279. #endif // ASIO_ERROR_HPP