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_code.ipp 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // impl/error_code.ipp
  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_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. #else
  95. char buf[256] = "";
  96. using namespace std;
  97. return strerror_result(strerror_r(value, buf, sizeof(buf)), buf);
  98. #endif
  99. #endif // defined(ASIO_WINDOWS_DESKTOP) || defined(__CYGWIN__)
  100. }
  101. #if defined(ASIO_HAS_STD_ERROR_CODE)
  102. std::error_condition default_error_condition(
  103. int ev) const ASIO_ERROR_CATEGORY_NOEXCEPT
  104. {
  105. switch (ev)
  106. {
  107. case access_denied:
  108. return std::errc::permission_denied;
  109. case address_family_not_supported:
  110. return std::errc::address_family_not_supported;
  111. case address_in_use:
  112. return std::errc::address_in_use;
  113. case already_connected:
  114. return std::errc::already_connected;
  115. case already_started:
  116. return std::errc::connection_already_in_progress;
  117. case broken_pipe:
  118. return std::errc::broken_pipe;
  119. case connection_aborted:
  120. return std::errc::connection_aborted;
  121. case connection_refused:
  122. return std::errc::connection_refused;
  123. case connection_reset:
  124. return std::errc::connection_reset;
  125. case bad_descriptor:
  126. return std::errc::bad_file_descriptor;
  127. case fault:
  128. return std::errc::bad_address;
  129. case host_unreachable:
  130. return std::errc::host_unreachable;
  131. case in_progress:
  132. return std::errc::operation_in_progress;
  133. case interrupted:
  134. return std::errc::interrupted;
  135. case invalid_argument:
  136. return std::errc::invalid_argument;
  137. case message_size:
  138. return std::errc::message_size;
  139. case name_too_long:
  140. return std::errc::filename_too_long;
  141. case network_down:
  142. return std::errc::network_down;
  143. case network_reset:
  144. return std::errc::network_reset;
  145. case network_unreachable:
  146. return std::errc::network_unreachable;
  147. case no_descriptors:
  148. return std::errc::too_many_files_open;
  149. case no_buffer_space:
  150. return std::errc::no_buffer_space;
  151. case no_memory:
  152. return std::errc::not_enough_memory;
  153. case no_permission:
  154. return std::errc::operation_not_permitted;
  155. case no_protocol_option:
  156. return std::errc::no_protocol_option;
  157. case no_such_device:
  158. return std::errc::no_such_device;
  159. case not_connected:
  160. return std::errc::not_connected;
  161. case not_socket:
  162. return std::errc::not_a_socket;
  163. case operation_aborted:
  164. return std::errc::operation_canceled;
  165. case operation_not_supported:
  166. return std::errc::operation_not_supported;
  167. case shut_down:
  168. return std::make_error_condition(ev, *this);
  169. case timed_out:
  170. return std::errc::timed_out;
  171. case try_again:
  172. return std::errc::resource_unavailable_try_again;
  173. case would_block:
  174. return std::errc::operation_would_block;
  175. default:
  176. return std::make_error_condition(ev, *this);
  177. }
  178. #endif // defined(ASIO_HAS_STD_ERROR_CODE)
  179. private:
  180. // Helper function to adapt the result from glibc's variant of strerror_r.
  181. static const char* strerror_result(int, const char* s) { return s; }
  182. static const char* strerror_result(const char* s, const char*) { return s; }
  183. };
  184. } // namespace detail
  185. const error_category& system_category()
  186. {
  187. static detail::system_category instance;
  188. return instance;
  189. }
  190. } // namespace asio
  191. #include "asio/detail/pop_options.hpp"
  192. #endif // ASIO_IMPL_ERROR_CODE_IPP