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.

209 lines
6.2KB

  1. //
  2. // impl/error_code.ipp
  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_IMPL_ERROR_CODE_IPP
  11. #define ASIO_IMPL_ERROR_CODE_IPP
  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(ASIO_WINDOWS) || defined(__CYGWIN__)
  17. # include <winerror.h>
  18. #elif defined(ASIO_WINDOWS_RUNTIME)
  19. # include <windows.h>
  20. #else
  21. # include <cerrno>
  22. # include <cstring>
  23. # include <string>
  24. #endif
  25. #include "asio/detail/local_free_on_block_exit.hpp"
  26. #include "asio/detail/socket_types.hpp"
  27. #include "asio/error_code.hpp"
  28. #include "asio/detail/push_options.hpp"
  29. namespace asio {
  30. namespace detail {
  31. class system_category : public error_category
  32. {
  33. public:
  34. const char* name() const ASIO_ERROR_CATEGORY_NOEXCEPT
  35. {
  36. return "asio.system";
  37. }
  38. std::string message(int value) const
  39. {
  40. #if defined(ASIO_WINDOWS_RUNTIME) || defined(ASIO_WINDOWS_APP)
  41. std::wstring wmsg(128, wchar_t());
  42. for (;;)
  43. {
  44. DWORD wlength = ::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
  45. | FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
  46. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  47. &wmsg[0], static_cast<DWORD>(wmsg.size()), 0);
  48. if (wlength == 0 && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
  49. {
  50. wmsg.resize(wmsg.size() + wmsg.size() / 2);
  51. continue;
  52. }
  53. if (wlength && wmsg[wlength - 1] == '\n')
  54. --wlength;
  55. if (wlength && wmsg[wlength - 1] == '\r')
  56. --wlength;
  57. if (wlength)
  58. {
  59. std::string msg(wlength * 2, char());
  60. int length = ::WideCharToMultiByte(CP_ACP, 0,
  61. wmsg.c_str(), static_cast<int>(wlength),
  62. &msg[0], static_cast<int>(wlength * 2), 0, 0);
  63. if (length <= 0)
  64. return "asio.system error";
  65. msg.resize(static_cast<std::size_t>(length));
  66. return msg;
  67. }
  68. else
  69. return "asio.system error";
  70. }
  71. #elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
  72. char* msg = 0;
  73. DWORD length = ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
  74. | FORMAT_MESSAGE_FROM_SYSTEM
  75. | FORMAT_MESSAGE_IGNORE_INSERTS, 0, value,
  76. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&msg, 0, 0);
  77. detail::local_free_on_block_exit local_free_obj(msg);
  78. if (length && msg[length - 1] == '\n')
  79. msg[--length] = '\0';
  80. if (length && msg[length - 1] == '\r')
  81. msg[--length] = '\0';
  82. if (length)
  83. return msg;
  84. else
  85. return "asio.system error";
  86. #else // defined(ASIO_WINDOWS_DESKTOP) || defined(__CYGWIN__)
  87. #if !defined(__sun)
  88. if (value == ECANCELED)
  89. return "Operation aborted.";
  90. #endif // !defined(__sun)
  91. #if defined(__sun) || defined(__QNX__) || defined(__SYMBIAN32__)
  92. using namespace std;
  93. return strerror(value);
  94. #elif defined(__MACH__) && defined(__APPLE__) \
  95. || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
  96. || defined(_AIX) || defined(__hpux) || defined(__osf__) \
  97. || defined(__ANDROID__)
  98. char buf[256] = "";
  99. using namespace std;
  100. strerror_r(value, buf, sizeof(buf));
  101. return buf;
  102. #else
  103. char buf[256] = "";
  104. return strerror_r(value, buf, sizeof(buf));
  105. #endif
  106. #endif // defined(ASIO_WINDOWS_DESKTOP) || defined(__CYGWIN__)
  107. }
  108. #if defined(ASIO_HAS_STD_ERROR_CODE)
  109. std::error_condition default_error_condition(
  110. int ev) const ASIO_ERROR_CATEGORY_NOEXCEPT
  111. {
  112. switch (ev)
  113. {
  114. case access_denied:
  115. return std::errc::permission_denied;
  116. case address_family_not_supported:
  117. return std::errc::address_family_not_supported;
  118. case address_in_use:
  119. return std::errc::address_in_use;
  120. case already_connected:
  121. return std::errc::already_connected;
  122. case already_started:
  123. return std::errc::connection_already_in_progress;
  124. case broken_pipe:
  125. return std::errc::broken_pipe;
  126. case connection_aborted:
  127. return std::errc::connection_aborted;
  128. case connection_refused:
  129. return std::errc::connection_refused;
  130. case connection_reset:
  131. return std::errc::connection_reset;
  132. case bad_descriptor:
  133. return std::errc::bad_file_descriptor;
  134. case fault:
  135. return std::errc::bad_address;
  136. case host_unreachable:
  137. return std::errc::host_unreachable;
  138. case in_progress:
  139. return std::errc::operation_in_progress;
  140. case interrupted:
  141. return std::errc::interrupted;
  142. case invalid_argument:
  143. return std::errc::invalid_argument;
  144. case message_size:
  145. return std::errc::message_size;
  146. case name_too_long:
  147. return std::errc::filename_too_long;
  148. case network_down:
  149. return std::errc::network_down;
  150. case network_reset:
  151. return std::errc::network_reset;
  152. case network_unreachable:
  153. return std::errc::network_unreachable;
  154. case no_descriptors:
  155. return std::errc::too_many_files_open;
  156. case no_buffer_space:
  157. return std::errc::no_buffer_space;
  158. case no_memory:
  159. return std::errc::not_enough_memory;
  160. case no_permission:
  161. return std::errc::operation_not_permitted;
  162. case no_protocol_option:
  163. return std::errc::no_protocol_option;
  164. case no_such_device:
  165. return std::errc::no_such_device;
  166. case not_connected:
  167. return std::errc::not_connected;
  168. case not_socket:
  169. return std::errc::not_a_socket;
  170. case operation_aborted:
  171. return std::errc::operation_canceled;
  172. case operation_not_supported:
  173. return std::errc::operation_not_supported;
  174. case shut_down:
  175. return std::make_error_condition(ev, *this);
  176. case timed_out:
  177. return std::errc::timed_out;
  178. case try_again:
  179. return std::errc::resource_unavailable_try_again;
  180. case would_block:
  181. return std::errc::operation_would_block;
  182. default:
  183. return std::make_error_condition(ev, *this);
  184. }
  185. #endif // defined(ASIO_HAS_STD_ERROR_CODE)
  186. };
  187. } // namespace detail
  188. const error_category& system_category()
  189. {
  190. static detail::system_category instance;
  191. return instance;
  192. }
  193. } // namespace asio
  194. #include "asio/detail/pop_options.hpp"
  195. #endif // ASIO_IMPL_ERROR_CODE_IPP