]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/ip/resolver_service.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / ip / resolver_service.hpp
1 //
2 // ip/resolver_service.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_IP_RESOLVER_SERVICE_HPP
12 #define BOOST_ASIO_IP_RESOLVER_SERVICE_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
20 #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
21
22 #include <boost/asio/async_result.hpp>
23 #include <boost/system/error_code.hpp>
24 #include <boost/asio/io_context.hpp>
25 #include <boost/asio/ip/basic_resolver_iterator.hpp>
26 #include <boost/asio/ip/basic_resolver_query.hpp>
27 #include <boost/asio/ip/basic_resolver_results.hpp>
28
29 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
30 # include <boost/asio/detail/winrt_resolver_service.hpp>
31 #else
32 # include <boost/asio/detail/resolver_service.hpp>
33 #endif
34
35 #include <boost/asio/detail/push_options.hpp>
36
37 namespace boost {
38 namespace asio {
39 namespace ip {
40
41 /// Default service implementation for a resolver.
42 template <typename InternetProtocol>
43 class resolver_service
44 #if defined(GENERATING_DOCUMENTATION)
45 : public boost::asio::io_context::service
46 #else
47 : public boost::asio::detail::service_base<
48 resolver_service<InternetProtocol> >
49 #endif
50 {
51 public:
52 #if defined(GENERATING_DOCUMENTATION)
53 /// The unique service identifier.
54 static boost::asio::io_context::id id;
55 #endif
56
57 /// The protocol type.
58 typedef InternetProtocol protocol_type;
59
60 /// The endpoint type.
61 typedef typename InternetProtocol::endpoint endpoint_type;
62
63 /// The query type.
64 typedef basic_resolver_query<InternetProtocol> query_type;
65
66 /// The iterator type.
67 typedef basic_resolver_iterator<InternetProtocol> iterator_type;
68
69 /// The results type.
70 typedef basic_resolver_results<InternetProtocol> results_type;
71
72 private:
73 // The type of the platform-specific implementation.
74 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
75 typedef boost::asio::detail::winrt_resolver_service<InternetProtocol>
76 service_impl_type;
77 #else
78 typedef boost::asio::detail::resolver_service<InternetProtocol>
79 service_impl_type;
80 #endif
81
82 public:
83 /// The type of a resolver implementation.
84 #if defined(GENERATING_DOCUMENTATION)
85 typedef implementation_defined implementation_type;
86 #else
87 typedef typename service_impl_type::implementation_type implementation_type;
88 #endif
89
90 /// Construct a new resolver service for the specified io_context.
91 explicit resolver_service(boost::asio::io_context& io_context)
92 : boost::asio::detail::service_base<
93 resolver_service<InternetProtocol> >(io_context),
94 service_impl_(io_context)
95 {
96 }
97
98 /// Construct a new resolver implementation.
99 void construct(implementation_type& impl)
100 {
101 service_impl_.construct(impl);
102 }
103
104 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
105 /// Move-construct a new resolver implementation.
106 void move_construct(implementation_type& impl,
107 implementation_type& other_impl)
108 {
109 service_impl_.move_construct(impl, other_impl);
110 }
111
112 /// Move-assign from another resolver implementation.
113 void move_assign(implementation_type& impl,
114 resolver_service& other_service,
115 implementation_type& other_impl)
116 {
117 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
118 }
119 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
120
121 /// Destroy a resolver implementation.
122 void destroy(implementation_type& impl)
123 {
124 service_impl_.destroy(impl);
125 }
126
127 /// Cancel pending asynchronous operations.
128 void cancel(implementation_type& impl)
129 {
130 service_impl_.cancel(impl);
131 }
132
133 /// Resolve a query to a list of entries.
134 results_type resolve(implementation_type& impl, const query_type& query,
135 boost::system::error_code& ec)
136 {
137 return service_impl_.resolve(impl, query, ec);
138 }
139
140 /// Asynchronously resolve a query to a list of entries.
141 template <typename ResolveHandler>
142 BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
143 void (boost::system::error_code, results_type))
144 async_resolve(implementation_type& impl, const query_type& query,
145 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
146 {
147 boost::asio::async_completion<ResolveHandler,
148 void (boost::system::error_code, results_type)> init(handler);
149
150 service_impl_.async_resolve(impl, query, init.completion_handler);
151
152 return init.result.get();
153 }
154
155 /// Resolve an endpoint to a list of entries.
156 results_type resolve(implementation_type& impl,
157 const endpoint_type& endpoint, boost::system::error_code& ec)
158 {
159 return service_impl_.resolve(impl, endpoint, ec);
160 }
161
162 /// Asynchronously resolve an endpoint to a list of entries.
163 template <typename ResolveHandler>
164 BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
165 void (boost::system::error_code, results_type))
166 async_resolve(implementation_type& impl, const endpoint_type& endpoint,
167 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
168 {
169 boost::asio::async_completion<ResolveHandler,
170 void (boost::system::error_code, results_type)> init(handler);
171
172 service_impl_.async_resolve(impl, endpoint, init.completion_handler);
173
174 return init.result.get();
175 }
176
177 private:
178 // Destroy all user-defined handler objects owned by the service.
179 void shutdown()
180 {
181 service_impl_.shutdown();
182 }
183
184 // Perform any fork-related housekeeping.
185 void notify_fork(boost::asio::io_context::fork_event event)
186 {
187 service_impl_.notify_fork(event);
188 }
189
190 // The platform-specific implementation.
191 service_impl_type service_impl_;
192 };
193
194 } // namespace ip
195 } // namespace asio
196 } // namespace boost
197
198 #include <boost/asio/detail/pop_options.hpp>
199
200 #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
201
202 #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP