resolver_service_base.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // detail/resolver_service_base.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2025 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 BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
  11. #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/error.hpp>
  17. #include <boost/asio/execution_context.hpp>
  18. #include <boost/asio/detail/noncopyable.hpp>
  19. #include <boost/asio/detail/resolve_op.hpp>
  20. #include <boost/asio/detail/resolver_thread_pool.hpp>
  21. #include <boost/asio/detail/socket_ops.hpp>
  22. #include <boost/asio/detail/socket_types.hpp>
  23. #if defined(BOOST_ASIO_HAS_IOCP)
  24. # include <boost/asio/detail/win_iocp_io_context.hpp>
  25. #else // defined(BOOST_ASIO_HAS_IOCP)
  26. # include <boost/asio/detail/scheduler.hpp>
  27. #endif // defined(BOOST_ASIO_HAS_IOCP)
  28. #include <boost/asio/detail/push_options.hpp>
  29. namespace boost {
  30. namespace asio {
  31. namespace detail {
  32. class resolver_service_base
  33. {
  34. public:
  35. // The implementation type of the resolver. A cancellation token is used to
  36. // indicate to the background thread that the operation has been cancelled.
  37. typedef socket_ops::shared_cancel_token_type implementation_type;
  38. // Constructor.
  39. BOOST_ASIO_DECL resolver_service_base(execution_context& context);
  40. // Destructor.
  41. BOOST_ASIO_DECL ~resolver_service_base();
  42. // Construct a new resolver implementation.
  43. BOOST_ASIO_DECL void construct(implementation_type& impl);
  44. // Destroy a resolver implementation.
  45. BOOST_ASIO_DECL void destroy(implementation_type&);
  46. // Move-construct a new resolver implementation.
  47. BOOST_ASIO_DECL void move_construct(implementation_type& impl,
  48. implementation_type& other_impl);
  49. // Move-assign from another resolver implementation.
  50. BOOST_ASIO_DECL void move_assign(implementation_type& impl,
  51. resolver_service_base& other_service,
  52. implementation_type& other_impl);
  53. // Move-construct a new timer implementation.
  54. void converting_move_construct(implementation_type& impl,
  55. resolver_service_base&, implementation_type& other_impl)
  56. {
  57. move_construct(impl, other_impl);
  58. }
  59. // Move-assign from another timer implementation.
  60. void converting_move_assign(implementation_type& impl,
  61. resolver_service_base& other_service,
  62. implementation_type& other_impl)
  63. {
  64. move_assign(impl, other_service, other_impl);
  65. }
  66. // Cancel pending asynchronous operations.
  67. BOOST_ASIO_DECL void cancel(implementation_type& impl);
  68. protected:
  69. #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  70. // Helper class to perform exception-safe cleanup of addrinfo objects.
  71. class auto_addrinfo
  72. : private boost::asio::detail::noncopyable
  73. {
  74. public:
  75. explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai)
  76. : ai_(ai)
  77. {
  78. }
  79. ~auto_addrinfo()
  80. {
  81. if (ai_)
  82. socket_ops::freeaddrinfo(ai_);
  83. }
  84. operator boost::asio::detail::addrinfo_type*()
  85. {
  86. return ai_;
  87. }
  88. private:
  89. boost::asio::detail::addrinfo_type* ai_;
  90. };
  91. #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  92. // Private thread pool used for performing asynchronous host resolution.
  93. resolver_thread_pool& thread_pool_;
  94. };
  95. } // namespace detail
  96. } // namespace asio
  97. } // namespace boost
  98. #include <boost/asio/detail/pop_options.hpp>
  99. #if defined(BOOST_ASIO_HEADER_ONLY)
  100. # include <boost/asio/detail/impl/resolver_service_base.ipp>
  101. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  102. #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP