1//
2// ip/resolver_service.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
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#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>
24
25#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
26# include <boost/asio/detail/winrt_resolver_service.hpp>
27#else
28# include <boost/asio/detail/resolver_service.hpp>
29#endif
30
31#include <boost/asio/detail/push_options.hpp>
32
33namespace boost {
34namespace asio {
35namespace ip {
36
37/// Default service implementation for a resolver.
38template <typename InternetProtocol>
39class resolver_service
40#if defined(GENERATING_DOCUMENTATION)
41 : public boost::asio::io_service::service
42#else
43 : public boost::asio::detail::service_base<
44 resolver_service<InternetProtocol> >
45#endif
46{
47public:
48#if defined(GENERATING_DOCUMENTATION)
49 /// The unique service identifier.
50 static boost::asio::io_service::id id;
51#endif
52
53 /// The protocol type.
54 typedef InternetProtocol protocol_type;
55
56 /// The endpoint type.
57 typedef typename InternetProtocol::endpoint endpoint_type;
58
59 /// The query type.
60 typedef basic_resolver_query<InternetProtocol> query_type;
61
62 /// The iterator type.
63 typedef basic_resolver_iterator<InternetProtocol> iterator_type;
64
65private:
66 // The type of the platform-specific implementation.
67#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
68 typedef boost::asio::detail::winrt_resolver_service<InternetProtocol>
69 service_impl_type;
70#else
71 typedef boost::asio::detail::resolver_service<InternetProtocol>
72 service_impl_type;
73#endif
74
75public:
76 /// The type of a resolver implementation.
77#if defined(GENERATING_DOCUMENTATION)
78 typedef implementation_defined implementation_type;
79#else
80 typedef typename service_impl_type::implementation_type implementation_type;
81#endif
82
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)
88 {
89 }
90
91 /// Construct a new resolver implementation.
92 void construct(implementation_type& impl)
93 {
94 service_impl_.construct(impl);
95 }
96
97 /// Destroy a resolver implementation.
98 void destroy(implementation_type& impl)
99 {
100 service_impl_.destroy(impl);
101 }
102
103 /// Cancel pending asynchronous operations.
104 void cancel(implementation_type& impl)
105 {
106 service_impl_.cancel(impl);
107 }
108
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)
112 {
113 return service_impl_.resolve(impl, query, ec);
114 }
115
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)
122 {
123 boost::asio::detail::async_result_init<
124 ResolveHandler, void (boost::system::error_code, iterator_type)> init(
125 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
126
127 service_impl_.async_resolve(impl, query, init.handler);
128
129 return init.result.get();
130 }
131
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)
135 {
136 return service_impl_.resolve(impl, endpoint, ec);
137 }
138
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)
145 {
146 boost::asio::detail::async_result_init<
147 ResolveHandler, void (boost::system::error_code, iterator_type)> init(
148 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
149
150 service_impl_.async_resolve(impl, endpoint, init.handler);
151
152 return init.result.get();
153 }
154
155private:
156 // Destroy all user-defined handler objects owned by the service.
157 void shutdown_service()
158 {
159 service_impl_.shutdown_service();
160 }
161
162 // Perform any fork-related housekeeping.
163 void fork_service(boost::asio::io_service::fork_event event)
164 {
165 service_impl_.fork_service(event);
166 }
167
168 // The platform-specific implementation.
169 service_impl_type service_impl_;
170};
171
172} // namespace ip
173} // namespace asio
174} // namespace boost
175
176#include <boost/asio/detail/pop_options.hpp>
177
178#endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP
179

source code of boost/boost/asio/ip/resolver_service.hpp