2 // ip/resolver_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_IP_RESOLVER_SERVICE_HPP
12 #define BOOST_ASIO_IP_RESOLVER_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
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>
29 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
30 # include <boost/asio/detail/winrt_resolver_service.hpp>
32 # include <boost/asio/detail/resolver_service.hpp>
35 #include <boost/asio/detail/push_options.hpp>
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
47 : public boost::asio::detail::service_base<
48 resolver_service<InternetProtocol> >
52 #if defined(GENERATING_DOCUMENTATION)
53 /// The unique service identifier.
54 static boost::asio::io_context::id id;
57 /// The protocol type.
58 typedef InternetProtocol protocol_type;
60 /// The endpoint type.
61 typedef typename InternetProtocol::endpoint endpoint_type;
64 typedef basic_resolver_query<InternetProtocol> query_type;
66 /// The iterator type.
67 typedef basic_resolver_iterator<InternetProtocol> iterator_type;
70 typedef basic_resolver_results<InternetProtocol> results_type;
73 // The type of the platform-specific implementation.
74 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
75 typedef boost::asio::detail::winrt_resolver_service<InternetProtocol>
78 typedef boost::asio::detail::resolver_service<InternetProtocol>
83 /// The type of a resolver implementation.
84 #if defined(GENERATING_DOCUMENTATION)
85 typedef implementation_defined implementation_type;
87 typedef typename service_impl_type::implementation_type implementation_type;
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)
98 /// Construct a new resolver implementation.
99 void construct(implementation_type& impl)
101 service_impl_.construct(impl);
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)
109 service_impl_.move_construct(impl, other_impl);
112 /// Move-assign from another resolver implementation.
113 void move_assign(implementation_type& impl,
114 resolver_service& other_service,
115 implementation_type& other_impl)
117 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
119 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
121 /// Destroy a resolver implementation.
122 void destroy(implementation_type& impl)
124 service_impl_.destroy(impl);
127 /// Cancel pending asynchronous operations.
128 void cancel(implementation_type& impl)
130 service_impl_.cancel(impl);
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)
137 return service_impl_.resolve(impl, query, ec);
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)
147 boost::asio::async_completion<ResolveHandler,
148 void (boost::system::error_code, results_type)> init(handler);
150 service_impl_.async_resolve(impl, query, init.completion_handler);
152 return init.result.get();
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)
159 return service_impl_.resolve(impl, endpoint, ec);
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)
169 boost::asio::async_completion<ResolveHandler,
170 void (boost::system::error_code, results_type)> init(handler);
172 service_impl_.async_resolve(impl, endpoint, init.completion_handler);
174 return init.result.get();
178 // Destroy all user-defined handler objects owned by the service.
181 service_impl_.shutdown();
184 // Perform any fork-related housekeeping.
185 void notify_fork(boost::asio::io_context::fork_event event)
187 service_impl_.notify_fork(event);
190 // The platform-specific implementation.
191 service_impl_type service_impl_;
198 #include <boost/asio/detail/pop_options.hpp>
200 #endif // defined(BOOST_ASIO_ENABLE_OLD_SERVICES)
202 #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP