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.

144 lines
4.0KB

  1. //
  2. // detail/resolver_service_base.hpp
  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_DETAIL_RESOLVER_SERVICE_BASE_HPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include "asio/error.hpp"
  17. #include "asio/execution_context.hpp"
  18. #include "asio/detail/mutex.hpp"
  19. #include "asio/detail/noncopyable.hpp"
  20. #include "asio/detail/resolve_op.hpp"
  21. #include "asio/detail/socket_ops.hpp"
  22. #include "asio/detail/socket_types.hpp"
  23. #include "asio/detail/scoped_ptr.hpp"
  24. #include "asio/detail/thread.hpp"
  25. #if defined(ASIO_HAS_IOCP)
  26. # include "asio/detail/win_iocp_io_context.hpp"
  27. #else // defined(ASIO_HAS_IOCP)
  28. # include "asio/detail/scheduler.hpp"
  29. #endif // defined(ASIO_HAS_IOCP)
  30. #include "asio/detail/push_options.hpp"
  31. namespace asio {
  32. namespace detail {
  33. class resolver_service_base
  34. {
  35. public:
  36. // The implementation type of the resolver. A cancellation token is used to
  37. // indicate to the background thread that the operation has been cancelled.
  38. typedef socket_ops::shared_cancel_token_type implementation_type;
  39. // Constructor.
  40. ASIO_DECL resolver_service_base(execution_context& context);
  41. // Destructor.
  42. ASIO_DECL ~resolver_service_base();
  43. // Destroy all user-defined handler objects owned by the service.
  44. ASIO_DECL void base_shutdown();
  45. // Perform any fork-related housekeeping.
  46. ASIO_DECL void base_notify_fork(
  47. execution_context::fork_event fork_ev);
  48. // Construct a new resolver implementation.
  49. ASIO_DECL void construct(implementation_type& impl);
  50. // Destroy a resolver implementation.
  51. ASIO_DECL void destroy(implementation_type&);
  52. // Move-construct a new resolver implementation.
  53. ASIO_DECL void move_construct(implementation_type& impl,
  54. implementation_type& other_impl);
  55. // Move-assign from another resolver implementation.
  56. ASIO_DECL void move_assign(implementation_type& impl,
  57. resolver_service_base& other_service,
  58. implementation_type& other_impl);
  59. // Cancel pending asynchronous operations.
  60. ASIO_DECL void cancel(implementation_type& impl);
  61. protected:
  62. // Helper function to start an asynchronous resolve operation.
  63. ASIO_DECL void start_resolve_op(resolve_op* op);
  64. #if !defined(ASIO_WINDOWS_RUNTIME)
  65. // Helper class to perform exception-safe cleanup of addrinfo objects.
  66. class auto_addrinfo
  67. : private asio::detail::noncopyable
  68. {
  69. public:
  70. explicit auto_addrinfo(asio::detail::addrinfo_type* ai)
  71. : ai_(ai)
  72. {
  73. }
  74. ~auto_addrinfo()
  75. {
  76. if (ai_)
  77. socket_ops::freeaddrinfo(ai_);
  78. }
  79. operator asio::detail::addrinfo_type*()
  80. {
  81. return ai_;
  82. }
  83. private:
  84. asio::detail::addrinfo_type* ai_;
  85. };
  86. #endif // !defined(ASIO_WINDOWS_RUNTIME)
  87. // Helper class to run the work scheduler in a thread.
  88. class work_scheduler_runner;
  89. // Start the work scheduler if it's not already running.
  90. ASIO_DECL void start_work_thread();
  91. // The scheduler implementation used to post completions.
  92. #if defined(ASIO_HAS_IOCP)
  93. typedef class win_iocp_io_context scheduler_impl;
  94. #else
  95. typedef class scheduler scheduler_impl;
  96. #endif
  97. scheduler_impl& scheduler_;
  98. private:
  99. // Mutex to protect access to internal data.
  100. asio::detail::mutex mutex_;
  101. // Private scheduler used for performing asynchronous host resolution.
  102. asio::detail::scoped_ptr<scheduler_impl> work_scheduler_;
  103. // Thread used for running the work io_context's run loop.
  104. asio::detail::scoped_ptr<asio::detail::thread> work_thread_;
  105. };
  106. } // namespace detail
  107. } // namespace asio
  108. #include "asio/detail/pop_options.hpp"
  109. #if defined(ASIO_HEADER_ONLY)
  110. # include "asio/detail/impl/resolver_service_base.ipp"
  111. #endif // defined(ASIO_HEADER_ONLY)
  112. #endif // ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP