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.

130 lines
3.5KB

  1. //
  2. // detail/resolver_service_base.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_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/io_context.hpp"
  18. #include "asio/detail/mutex.hpp"
  19. #include "asio/detail/noncopyable.hpp"
  20. #include "asio/detail/operation.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. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. namespace detail {
  28. class resolver_service_base
  29. {
  30. public:
  31. // The implementation type of the resolver. A cancellation token is used to
  32. // indicate to the background thread that the operation has been cancelled.
  33. typedef socket_ops::shared_cancel_token_type implementation_type;
  34. // Constructor.
  35. ASIO_DECL resolver_service_base(asio::io_context& io_context);
  36. // Destructor.
  37. ASIO_DECL ~resolver_service_base();
  38. // Destroy all user-defined handler objects owned by the service.
  39. ASIO_DECL void shutdown();
  40. // Perform any fork-related housekeeping.
  41. ASIO_DECL void notify_fork(
  42. asio::io_context::fork_event fork_ev);
  43. // Construct a new resolver implementation.
  44. ASIO_DECL void construct(implementation_type& impl);
  45. // Destroy a resolver implementation.
  46. ASIO_DECL void destroy(implementation_type&);
  47. // Cancel pending asynchronous operations.
  48. ASIO_DECL void cancel(implementation_type& impl);
  49. protected:
  50. // Helper function to start an asynchronous resolve operation.
  51. ASIO_DECL void start_resolve_op(operation* op);
  52. #if !defined(ASIO_WINDOWS_RUNTIME)
  53. // Helper class to perform exception-safe cleanup of addrinfo objects.
  54. class auto_addrinfo
  55. : private asio::detail::noncopyable
  56. {
  57. public:
  58. explicit auto_addrinfo(asio::detail::addrinfo_type* ai)
  59. : ai_(ai)
  60. {
  61. }
  62. ~auto_addrinfo()
  63. {
  64. if (ai_)
  65. socket_ops::freeaddrinfo(ai_);
  66. }
  67. operator asio::detail::addrinfo_type*()
  68. {
  69. return ai_;
  70. }
  71. private:
  72. asio::detail::addrinfo_type* ai_;
  73. };
  74. #endif // !defined(ASIO_WINDOWS_RUNTIME)
  75. // Helper class to run the work io_context in a thread.
  76. class work_io_context_runner;
  77. // Start the work thread if it's not already running.
  78. ASIO_DECL void start_work_thread();
  79. // The io_context implementation used to post completions.
  80. io_context_impl& io_context_impl_;
  81. private:
  82. // Mutex to protect access to internal data.
  83. asio::detail::mutex mutex_;
  84. // Private io_context used for performing asynchronous host resolution.
  85. asio::detail::scoped_ptr<asio::io_context> work_io_context_;
  86. // The work io_context implementation used to post completions.
  87. io_context_impl& work_io_context_impl_;
  88. // Work for the private io_context to perform.
  89. asio::detail::scoped_ptr<asio::io_context::work> work_;
  90. // Thread used for running the work io_context's run loop.
  91. asio::detail::scoped_ptr<asio::detail::thread> work_thread_;
  92. };
  93. } // namespace detail
  94. } // namespace asio
  95. #include "asio/detail/pop_options.hpp"
  96. #if defined(ASIO_HEADER_ONLY)
  97. # include "asio/detail/impl/resolver_service_base.ipp"
  98. #endif // defined(ASIO_HEADER_ONLY)
  99. #endif // ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP