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.

winrt_resolver_service.hpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // detail/winrt_resolver_service.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_DETAIL_WINRT_RESOLVER_SERVICE_HPP
  11. #define ASIO_DETAIL_WINRT_RESOLVER_SERVICE_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. #if defined(ASIO_WINDOWS_RUNTIME)
  17. #include "asio/ip/basic_resolver_query.hpp"
  18. #include "asio/ip/basic_resolver_results.hpp"
  19. #include "asio/detail/bind_handler.hpp"
  20. #include "asio/detail/memory.hpp"
  21. #include "asio/detail/socket_ops.hpp"
  22. #include "asio/detail/winrt_async_manager.hpp"
  23. #include "asio/detail/winrt_resolve_op.hpp"
  24. #include "asio/detail/winrt_utils.hpp"
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. namespace detail {
  28. template <typename Protocol>
  29. class winrt_resolver_service
  30. {
  31. public:
  32. // The implementation type of the resolver. A cancellation token is used to
  33. // indicate to the asynchronous operation that the operation has been
  34. // cancelled.
  35. typedef socket_ops::shared_cancel_token_type implementation_type;
  36. // The endpoint type.
  37. typedef typename Protocol::endpoint endpoint_type;
  38. // The query type.
  39. typedef asio::ip::basic_resolver_query<Protocol> query_type;
  40. // The results type.
  41. typedef asio::ip::basic_resolver_results<Protocol> results_type;
  42. // Constructor.
  43. winrt_resolver_service(asio::io_context& io_context)
  44. : io_context_(use_service<io_context_impl>(io_context)),
  45. async_manager_(use_service<winrt_async_manager>(io_context))
  46. {
  47. }
  48. // Destructor.
  49. ~winrt_resolver_service()
  50. {
  51. }
  52. // Destroy all user-defined handler objects owned by the service.
  53. void shutdown()
  54. {
  55. }
  56. // Perform any fork-related housekeeping.
  57. void notify_fork(asio::io_context::fork_event)
  58. {
  59. }
  60. // Construct a new resolver implementation.
  61. void construct(implementation_type&)
  62. {
  63. }
  64. // Destroy a resolver implementation.
  65. void destroy(implementation_type&)
  66. {
  67. }
  68. // Cancel pending asynchronous operations.
  69. void cancel(implementation_type&)
  70. {
  71. }
  72. // Resolve a query to a list of entries.
  73. results_type resolve(implementation_type&,
  74. const query_type& query, asio::error_code& ec)
  75. {
  76. try
  77. {
  78. using namespace Windows::Networking::Sockets;
  79. auto endpoint_pairs = async_manager_.sync(
  80. DatagramSocket::GetEndpointPairsAsync(
  81. winrt_utils::host_name(query.host_name()),
  82. winrt_utils::string(query.service_name())), ec);
  83. if (ec)
  84. return results_type();
  85. return results_type::create(
  86. endpoint_pairs, query.hints(),
  87. query.host_name(), query.service_name());
  88. }
  89. catch (Platform::Exception^ e)
  90. {
  91. ec = asio::error_code(e->HResult,
  92. asio::system_category());
  93. return results_type();
  94. }
  95. }
  96. // Asynchronously resolve a query to a list of entries.
  97. template <typename Handler>
  98. void async_resolve(implementation_type& impl,
  99. const query_type& query, Handler& handler)
  100. {
  101. bool is_continuation =
  102. asio_handler_cont_helpers::is_continuation(handler);
  103. // Allocate and construct an operation to wrap the handler.
  104. typedef winrt_resolve_op<Protocol, Handler> op;
  105. typename op::ptr p = { asio::detail::addressof(handler),
  106. op::ptr::allocate(handler), 0 };
  107. p.p = new (p.v) op(query, handler);
  108. ASIO_HANDLER_CREATION((io_context_.context(),
  109. *p.p, "resolver", &impl, 0, "async_resolve"));
  110. (void)impl;
  111. try
  112. {
  113. using namespace Windows::Networking::Sockets;
  114. async_manager_.async(DatagramSocket::GetEndpointPairsAsync(
  115. winrt_utils::host_name(query.host_name()),
  116. winrt_utils::string(query.service_name())), p.p);
  117. p.v = p.p = 0;
  118. }
  119. catch (Platform::Exception^ e)
  120. {
  121. p.p->ec_ = asio::error_code(
  122. e->HResult, asio::system_category());
  123. io_context_.post_immediate_completion(p.p, is_continuation);
  124. p.v = p.p = 0;
  125. }
  126. }
  127. // Resolve an endpoint to a list of entries.
  128. results_type resolve(implementation_type&,
  129. const endpoint_type&, asio::error_code& ec)
  130. {
  131. ec = asio::error::operation_not_supported;
  132. return results_type();
  133. }
  134. // Asynchronously resolve an endpoint to a list of entries.
  135. template <typename Handler>
  136. void async_resolve(implementation_type&,
  137. const endpoint_type&, Handler& handler)
  138. {
  139. asio::error_code ec = asio::error::operation_not_supported;
  140. const results_type results;
  141. io_context_.get_io_context().post(
  142. detail::bind_handler(handler, ec, results));
  143. }
  144. private:
  145. io_context_impl& io_context_;
  146. winrt_async_manager& async_manager_;
  147. };
  148. } // namespace detail
  149. } // namespace asio
  150. #include "asio/detail/pop_options.hpp"
  151. #endif // defined(ASIO_WINDOWS_RUNTIME)
  152. #endif // ASIO_DETAIL_WINRT_RESOLVER_SERVICE_HPP