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.

83 lines
1.9KB

  1. //
  2. // detail/impl/winsock_init.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_DETAIL_IMPL_WINSOCK_INIT_IPP
  11. #define ASIO_DETAIL_IMPL_WINSOCK_INIT_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 "asio/detail/socket_types.hpp"
  18. #include "asio/detail/winsock_init.hpp"
  19. #include "asio/detail/throw_error.hpp"
  20. #include "asio/error.hpp"
  21. #include "asio/detail/push_options.hpp"
  22. namespace asio {
  23. namespace detail {
  24. void winsock_init_base::startup(data& d,
  25. unsigned char major, unsigned char minor)
  26. {
  27. if (::InterlockedIncrement(&d.init_count_) == 1)
  28. {
  29. WSADATA wsa_data;
  30. long result = ::WSAStartup(MAKEWORD(major, minor), &wsa_data);
  31. ::InterlockedExchange(&d.result_, result);
  32. }
  33. }
  34. void winsock_init_base::manual_startup(data& d)
  35. {
  36. if (::InterlockedIncrement(&d.init_count_) == 1)
  37. {
  38. ::InterlockedExchange(&d.result_, 0);
  39. }
  40. }
  41. void winsock_init_base::cleanup(data& d)
  42. {
  43. if (::InterlockedDecrement(&d.init_count_) == 0)
  44. {
  45. ::WSACleanup();
  46. }
  47. }
  48. void winsock_init_base::manual_cleanup(data& d)
  49. {
  50. ::InterlockedDecrement(&d.init_count_);
  51. }
  52. void winsock_init_base::throw_on_error(data& d)
  53. {
  54. long result = ::InterlockedExchangeAdd(&d.result_, 0);
  55. if (result != 0)
  56. {
  57. asio::error_code ec(result,
  58. asio::error::get_system_category());
  59. asio::detail::throw_error(ec, "winsock");
  60. }
  61. }
  62. } // namespace detail
  63. } // namespace asio
  64. #include "asio/detail/pop_options.hpp"
  65. #endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
  66. #endif // ASIO_DETAIL_IMPL_WINSOCK_INIT_IPP