2 // ip/resolver_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 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>
19 #include <boost/asio/async_result.hpp>
20 #include <boost/system/error_code.hpp>
21 #include <boost/asio/io_service.hpp>
22 #include <boost/asio/ip/basic_resolver_iterator.hpp>
23 #include <boost/asio/ip/basic_resolver_query.hpp>
25 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
26 # include <boost/asio/detail/winrt_resolver_service.hpp>
28 # include <boost/asio/detail/resolver_service.hpp>
31 #include <boost/asio/detail/push_options.hpp>
37 /// Default service implementation for a resolver.
38 template <typename InternetProtocol>
39 class resolver_service
40 #if defined(GENERATING_DOCUMENTATION)
41 : public boost::asio::io_service::service
43 : public boost::asio::detail::service_base<
44 resolver_service<InternetProtocol> >
48 #if defined(GENERATING_DOCUMENTATION)
49 /// The unique service identifier.
50 static boost::asio::io_service::id id;
53 /// The protocol type.
54 typedef InternetProtocol protocol_type;
56 /// The endpoint type.
57 typedef typename InternetProtocol::endpoint endpoint_type;
60 typedef basic_resolver_query<InternetProtocol> query_type;
62 /// The iterator type.
63 typedef basic_resolver_iterator<InternetProtocol> iterator_type;
66 // The type of the platform-specific implementation.
67 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
68 typedef boost::asio::detail::winrt_resolver_service<InternetProtocol>
71 typedef boost::asio::detail::resolver_service<InternetProtocol>
76 /// The type of a resolver implementation.
77 #if defined(GENERATING_DOCUMENTATION)
78 typedef implementation_defined implementation_type;
80 typedef typename service_impl_type::implementation_type implementation_type;
83 /// Construct a new resolver service for the specified io_service.
84 explicit resolver_service(boost::asio::io_service& io_service)
85 : boost::asio::detail::service_base<
86 resolver_service<InternetProtocol> >(io_service),
87 service_impl_(io_service)
91 /// Construct a new resolver implementation.
92 void construct(implementation_type& impl)
94 service_impl_.construct(impl);
97 /// Destroy a resolver implementation.
98 void destroy(implementation_type& impl)
100 service_impl_.destroy(impl);
103 /// Cancel pending asynchronous operations.
104 void cancel(implementation_type& impl)
106 service_impl_.cancel(impl);
109 /// Resolve a query to a list of entries.
110 iterator_type resolve(implementation_type& impl, const query_type& query,
111 boost::system::error_code& ec)
113 return service_impl_.resolve(impl, query, ec);
116 /// Asynchronously resolve a query to a list of entries.
117 template <typename ResolveHandler>
118 BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
119 void (boost::system::error_code, iterator_type))
120 async_resolve(implementation_type& impl, const query_type& query,
121 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
123 boost::asio::detail::async_result_init<
124 ResolveHandler, void (boost::system::error_code, iterator_type)> init(
125 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
127 service_impl_.async_resolve(impl, query, init.handler);
129 return init.result.get();
132 /// Resolve an endpoint to a list of entries.
133 iterator_type resolve(implementation_type& impl,
134 const endpoint_type& endpoint, boost::system::error_code& ec)
136 return service_impl_.resolve(impl, endpoint, ec);
139 /// Asynchronously resolve an endpoint to a list of entries.
140 template <typename ResolveHandler>
141 BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
142 void (boost::system::error_code, iterator_type))
143 async_resolve(implementation_type& impl, const endpoint_type& endpoint,
144 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
146 boost::asio::detail::async_result_init<
147 ResolveHandler, void (boost::system::error_code, iterator_type)> init(
148 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
150 service_impl_.async_resolve(impl, endpoint, init.handler);
152 return init.result.get();
156 // Destroy all user-defined handler objects owned by the service.
157 void shutdown_service()
159 service_impl_.shutdown_service();
162 // Perform any fork-related housekeeping.
163 void fork_service(boost::asio::io_service::fork_event event)
165 service_impl_.fork_service(event);
168 // The platform-specific implementation.
169 service_impl_type service_impl_;
176 #include <boost/asio/detail/pop_options.hpp>
178 #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP