2 // ip/resolver_service.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2012 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/system/error_code.hpp>
20 #include <boost/asio/detail/resolver_service.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 #include <boost/asio/detail/push_options.hpp>
31 /// Default service implementation for a resolver.
32 template <typename InternetProtocol>
33 class resolver_service
34 #if defined(GENERATING_DOCUMENTATION)
35 : public boost::asio::io_service::service
37 : public boost::asio::detail::service_base<
38 resolver_service<InternetProtocol> >
42 #if defined(GENERATING_DOCUMENTATION)
43 /// The unique service identifier.
44 static boost::asio::io_service::id id;
47 /// The protocol type.
48 typedef InternetProtocol protocol_type;
50 /// The endpoint type.
51 typedef typename InternetProtocol::endpoint endpoint_type;
54 typedef basic_resolver_query<InternetProtocol> query_type;
56 /// The iterator type.
57 typedef basic_resolver_iterator<InternetProtocol> iterator_type;
60 // The type of the platform-specific implementation.
61 typedef boost::asio::detail::resolver_service<InternetProtocol>
65 /// The type of a resolver implementation.
66 #if defined(GENERATING_DOCUMENTATION)
67 typedef implementation_defined implementation_type;
69 typedef typename service_impl_type::implementation_type implementation_type;
72 /// Construct a new resolver service for the specified io_service.
73 explicit resolver_service(boost::asio::io_service& io_service)
74 : boost::asio::detail::service_base<
75 resolver_service<InternetProtocol> >(io_service),
76 service_impl_(io_service)
80 /// Construct a new resolver implementation.
81 void construct(implementation_type& impl)
83 service_impl_.construct(impl);
86 /// Destroy a resolver implementation.
87 void destroy(implementation_type& impl)
89 service_impl_.destroy(impl);
92 /// Cancel pending asynchronous operations.
93 void cancel(implementation_type& impl)
95 service_impl_.cancel(impl);
98 /// Resolve a query to a list of entries.
99 iterator_type resolve(implementation_type& impl, const query_type& query,
100 boost::system::error_code& ec)
102 return service_impl_.resolve(impl, query, ec);
105 /// Asynchronously resolve a query to a list of entries.
106 template <typename ResolveHandler>
107 void async_resolve(implementation_type& impl, const query_type& query,
108 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
110 service_impl_.async_resolve(impl, query,
111 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
114 /// Resolve an endpoint to a list of entries.
115 iterator_type resolve(implementation_type& impl,
116 const endpoint_type& endpoint, boost::system::error_code& ec)
118 return service_impl_.resolve(impl, endpoint, ec);
121 /// Asynchronously resolve an endpoint to a list of entries.
122 template <typename ResolveHandler>
123 void async_resolve(implementation_type& impl, const endpoint_type& endpoint,
124 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
126 return service_impl_.async_resolve(impl, endpoint,
127 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
131 // Destroy all user-defined handler objects owned by the service.
132 void shutdown_service()
134 service_impl_.shutdown_service();
137 // Perform any fork-related housekeeping.
138 void fork_service(boost::asio::io_service::fork_event event)
140 service_impl_.fork_service(event);
143 // The platform-specific implementation.
144 service_impl_type service_impl_;
151 #include <boost/asio/detail/pop_options.hpp>
153 #endif // BOOST_ASIO_IP_RESOLVER_SERVICE_HPP