]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/detail/resolver_service_base.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / detail / resolver_service_base.hpp
1 //
2 // detail/resolver_service_base.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 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
11 #ifndef BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
12 #define BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/error.hpp>
20 #include <boost/asio/executor_work_guard.hpp>
21 #include <boost/asio/io_context.hpp>
22 #include <boost/asio/detail/mutex.hpp>
23 #include <boost/asio/detail/noncopyable.hpp>
24 #include <boost/asio/detail/resolve_op.hpp>
25 #include <boost/asio/detail/socket_ops.hpp>
26 #include <boost/asio/detail/socket_types.hpp>
27 #include <boost/asio/detail/scoped_ptr.hpp>
28 #include <boost/asio/detail/thread.hpp>
29
30 #include <boost/asio/detail/push_options.hpp>
31
32 namespace boost {
33 namespace asio {
34 namespace detail {
35
36 class resolver_service_base
37 {
38 public:
39 // The implementation type of the resolver. A cancellation token is used to
40 // indicate to the background thread that the operation has been cancelled.
41 typedef socket_ops::shared_cancel_token_type implementation_type;
42
43 // Constructor.
44 BOOST_ASIO_DECL resolver_service_base(boost::asio::io_context& io_context);
45
46 // Destructor.
47 BOOST_ASIO_DECL ~resolver_service_base();
48
49 // Destroy all user-defined handler objects owned by the service.
50 BOOST_ASIO_DECL void base_shutdown();
51
52 // Perform any fork-related housekeeping.
53 BOOST_ASIO_DECL void base_notify_fork(
54 boost::asio::io_context::fork_event fork_ev);
55
56 // Construct a new resolver implementation.
57 BOOST_ASIO_DECL void construct(implementation_type& impl);
58
59 // Destroy a resolver implementation.
60 BOOST_ASIO_DECL void destroy(implementation_type&);
61
62 // Move-construct a new resolver implementation.
63 BOOST_ASIO_DECL void move_construct(implementation_type& impl,
64 implementation_type& other_impl);
65
66 // Move-assign from another resolver implementation.
67 BOOST_ASIO_DECL void move_assign(implementation_type& impl,
68 resolver_service_base& other_service,
69 implementation_type& other_impl);
70
71 // Cancel pending asynchronous operations.
72 BOOST_ASIO_DECL void cancel(implementation_type& impl);
73
74 protected:
75 // Helper function to start an asynchronous resolve operation.
76 BOOST_ASIO_DECL void start_resolve_op(resolve_op* op);
77
78 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
79 // Helper class to perform exception-safe cleanup of addrinfo objects.
80 class auto_addrinfo
81 : private boost::asio::detail::noncopyable
82 {
83 public:
84 explicit auto_addrinfo(boost::asio::detail::addrinfo_type* ai)
85 : ai_(ai)
86 {
87 }
88
89 ~auto_addrinfo()
90 {
91 if (ai_)
92 socket_ops::freeaddrinfo(ai_);
93 }
94
95 operator boost::asio::detail::addrinfo_type*()
96 {
97 return ai_;
98 }
99
100 private:
101 boost::asio::detail::addrinfo_type* ai_;
102 };
103 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
104
105 // Helper class to run the work io_context in a thread.
106 class work_io_context_runner;
107
108 // Start the work thread if it's not already running.
109 BOOST_ASIO_DECL void start_work_thread();
110
111 // The io_context implementation used to post completions.
112 io_context_impl& io_context_impl_;
113
114 private:
115 // Mutex to protect access to internal data.
116 boost::asio::detail::mutex mutex_;
117
118 // Private io_context used for performing asynchronous host resolution.
119 boost::asio::detail::scoped_ptr<boost::asio::io_context> work_io_context_;
120
121 // The work io_context implementation used to post completions.
122 io_context_impl& work_io_context_impl_;
123
124 // Work for the private io_context to perform.
125 boost::asio::executor_work_guard<
126 boost::asio::io_context::executor_type> work_;
127
128 // Thread used for running the work io_context's run loop.
129 boost::asio::detail::scoped_ptr<boost::asio::detail::thread> work_thread_;
130 };
131
132 } // namespace detail
133 } // namespace asio
134 } // namespace boost
135
136 #include <boost/asio/detail/pop_options.hpp>
137
138 #if defined(BOOST_ASIO_HEADER_ONLY)
139 # include <boost/asio/detail/impl/resolver_service_base.ipp>
140 #endif // defined(BOOST_ASIO_HEADER_ONLY)
141
142 #endif // BOOST_ASIO_DETAIL_RESOLVER_SERVICE_BASE_HPP