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.

resolver_service.hpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // detail/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_RESOLVER_SERVICE_HPP
  11. #define ASIO_DETAIL_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/memory.hpp"
  20. #include "asio/detail/resolve_endpoint_op.hpp"
  21. #include "asio/detail/resolve_op.hpp"
  22. #include "asio/detail/resolver_service_base.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace detail {
  26. template <typename Protocol>
  27. class resolver_service : public resolver_service_base
  28. {
  29. public:
  30. // The implementation type of the resolver. A cancellation token is used to
  31. // indicate to the background thread that the operation has been cancelled.
  32. typedef socket_ops::shared_cancel_token_type implementation_type;
  33. // The endpoint type.
  34. typedef typename Protocol::endpoint endpoint_type;
  35. // The query type.
  36. typedef asio::ip::basic_resolver_query<Protocol> query_type;
  37. // The results type.
  38. typedef asio::ip::basic_resolver_results<Protocol> results_type;
  39. // Constructor.
  40. resolver_service(asio::io_context& io_context)
  41. : resolver_service_base(io_context)
  42. {
  43. }
  44. // Resolve a query to a list of entries.
  45. results_type resolve(implementation_type&, const query_type& query,
  46. asio::error_code& ec)
  47. {
  48. asio::detail::addrinfo_type* address_info = 0;
  49. socket_ops::getaddrinfo(query.host_name().c_str(),
  50. query.service_name().c_str(), query.hints(), &address_info, ec);
  51. auto_addrinfo auto_address_info(address_info);
  52. return ec ? results_type() : results_type::create(
  53. address_info, query.host_name(), query.service_name());
  54. }
  55. // Asynchronously resolve a query to a list of entries.
  56. template <typename Handler>
  57. void async_resolve(implementation_type& impl,
  58. const query_type& query, Handler& handler)
  59. {
  60. // Allocate and construct an operation to wrap the handler.
  61. typedef resolve_op<Protocol, Handler> op;
  62. typename op::ptr p = { asio::detail::addressof(handler),
  63. op::ptr::allocate(handler), 0 };
  64. p.p = new (p.v) op(impl, query, io_context_impl_, handler);
  65. ASIO_HANDLER_CREATION((io_context_impl_.context(),
  66. *p.p, "resolver", &impl, 0, "async_resolve"));
  67. start_resolve_op(p.p);
  68. p.v = p.p = 0;
  69. }
  70. // Resolve an endpoint to a list of entries.
  71. results_type resolve(implementation_type&,
  72. const endpoint_type& endpoint, asio::error_code& ec)
  73. {
  74. char host_name[NI_MAXHOST];
  75. char service_name[NI_MAXSERV];
  76. socket_ops::sync_getnameinfo(endpoint.data(), endpoint.size(),
  77. host_name, NI_MAXHOST, service_name, NI_MAXSERV,
  78. endpoint.protocol().type(), ec);
  79. return ec ? results_type() : results_type::create(
  80. endpoint, host_name, service_name);
  81. }
  82. // Asynchronously resolve an endpoint to a list of entries.
  83. template <typename Handler>
  84. void async_resolve(implementation_type& impl,
  85. const endpoint_type& endpoint, Handler& handler)
  86. {
  87. // Allocate and construct an operation to wrap the handler.
  88. typedef resolve_endpoint_op<Protocol, Handler> op;
  89. typename op::ptr p = { asio::detail::addressof(handler),
  90. op::ptr::allocate(handler), 0 };
  91. p.p = new (p.v) op(impl, endpoint, io_context_impl_, handler);
  92. ASIO_HANDLER_CREATION((io_context_impl_.context(),
  93. *p.p, "resolver", &impl, 0, "async_resolve"));
  94. start_resolve_op(p.p);
  95. p.v = p.p = 0;
  96. }
  97. };
  98. } // namespace detail
  99. } // namespace asio
  100. #include "asio/detail/pop_options.hpp"
  101. #endif // !defined(ASIO_WINDOWS_RUNTIME)
  102. #endif // ASIO_DETAIL_RESOLVER_SERVICE_HPP