Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / ip / basic_resolver.hpp @ 2486

History | View | Annotate | Download (9.4 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// ip/basic_resolver.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_IP_BASIC_RESOLVER_HPP
12 2486 sjacqu01
#define BOOST_ASIO_IP_BASIC_RESOLVER_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <boost/asio/basic_io_object.hpp>
20 2486 sjacqu01
#include <boost/asio/detail/handler_type_requirements.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/throw_error.hpp>
22 2486 sjacqu01
#include <boost/asio/error.hpp>
23 2486 sjacqu01
#include <boost/asio/ip/basic_resolver_iterator.hpp>
24 2486 sjacqu01
#include <boost/asio/ip/basic_resolver_query.hpp>
25 2486 sjacqu01
#include <boost/asio/ip/resolver_service.hpp>
26 2486 sjacqu01
27 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
28 2486 sjacqu01
29 2486 sjacqu01
namespace boost {
30 2486 sjacqu01
namespace asio {
31 2486 sjacqu01
namespace ip {
32 2486 sjacqu01
33 2486 sjacqu01
/// Provides endpoint resolution functionality.
34 2486 sjacqu01
/**
35 2486 sjacqu01
 * The basic_resolver class template provides the ability to resolve a query
36 2486 sjacqu01
 * to a list of endpoints.
37 2486 sjacqu01
 *
38 2486 sjacqu01
 * @par Thread Safety
39 2486 sjacqu01
 * @e Distinct @e objects: Safe.@n
40 2486 sjacqu01
 * @e Shared @e objects: Unsafe.
41 2486 sjacqu01
 */
42 2486 sjacqu01
template <typename InternetProtocol,
43 2486 sjacqu01
    typename ResolverService = resolver_service<InternetProtocol> >
44 2486 sjacqu01
class basic_resolver
45 2486 sjacqu01
  : public basic_io_object<ResolverService>
46 2486 sjacqu01
{
47 2486 sjacqu01
public:
48 2486 sjacqu01
  /// The protocol type.
49 2486 sjacqu01
  typedef InternetProtocol protocol_type;
50 2486 sjacqu01
51 2486 sjacqu01
  /// The endpoint type.
52 2486 sjacqu01
  typedef typename InternetProtocol::endpoint endpoint_type;
53 2486 sjacqu01
54 2486 sjacqu01
  /// The query type.
55 2486 sjacqu01
  typedef basic_resolver_query<InternetProtocol> query;
56 2486 sjacqu01
57 2486 sjacqu01
  /// The iterator type.
58 2486 sjacqu01
  typedef basic_resolver_iterator<InternetProtocol> iterator;
59 2486 sjacqu01
60 2486 sjacqu01
  /// Constructor.
61 2486 sjacqu01
  /**
62 2486 sjacqu01
   * This constructor creates a basic_resolver.
63 2486 sjacqu01
   *
64 2486 sjacqu01
   * @param io_service The io_service object that the resolver will use to
65 2486 sjacqu01
   * dispatch handlers for any asynchronous operations performed on the timer.
66 2486 sjacqu01
   */
67 2486 sjacqu01
  explicit basic_resolver(boost::asio::io_service& io_service)
68 2486 sjacqu01
    : basic_io_object<ResolverService>(io_service)
69 2486 sjacqu01
  {
70 2486 sjacqu01
  }
71 2486 sjacqu01
72 2486 sjacqu01
  /// Cancel any asynchronous operations that are waiting on the resolver.
73 2486 sjacqu01
  /**
74 2486 sjacqu01
   * This function forces the completion of any pending asynchronous
75 2486 sjacqu01
   * operations on the host resolver. The handler for each cancelled operation
76 2486 sjacqu01
   * will be invoked with the boost::asio::error::operation_aborted error code.
77 2486 sjacqu01
   */
78 2486 sjacqu01
  void cancel()
79 2486 sjacqu01
  {
80 2486 sjacqu01
    return this->service.cancel(this->implementation);
81 2486 sjacqu01
  }
82 2486 sjacqu01
83 2486 sjacqu01
  /// Perform forward resolution of a query to a list of entries.
84 2486 sjacqu01
  /**
85 2486 sjacqu01
   * This function is used to resolve a query into a list of endpoint entries.
86 2486 sjacqu01
   *
87 2486 sjacqu01
   * @param q A query object that determines what endpoints will be returned.
88 2486 sjacqu01
   *
89 2486 sjacqu01
   * @returns A forward-only iterator that can be used to traverse the list
90 2486 sjacqu01
   * of endpoint entries.
91 2486 sjacqu01
   *
92 2486 sjacqu01
   * @throws boost::system::system_error Thrown on failure.
93 2486 sjacqu01
   *
94 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
95 2486 sjacqu01
   *
96 2486 sjacqu01
   * A successful call to this function is guaranteed to return at least one
97 2486 sjacqu01
   * entry.
98 2486 sjacqu01
   */
99 2486 sjacqu01
  iterator resolve(const query& q)
100 2486 sjacqu01
  {
101 2486 sjacqu01
    boost::system::error_code ec;
102 2486 sjacqu01
    iterator i = this->service.resolve(this->implementation, q, ec);
103 2486 sjacqu01
    boost::asio::detail::throw_error(ec, "resolve");
104 2486 sjacqu01
    return i;
105 2486 sjacqu01
  }
106 2486 sjacqu01
107 2486 sjacqu01
  /// Perform forward resolution of a query to a list of entries.
108 2486 sjacqu01
  /**
109 2486 sjacqu01
   * This function is used to resolve a query into a list of endpoint entries.
110 2486 sjacqu01
   *
111 2486 sjacqu01
   * @param q A query object that determines what endpoints will be returned.
112 2486 sjacqu01
   *
113 2486 sjacqu01
   * @param ec Set to indicate what error occurred, if any.
114 2486 sjacqu01
   *
115 2486 sjacqu01
   * @returns A forward-only iterator that can be used to traverse the list
116 2486 sjacqu01
   * of endpoint entries. Returns a default constructed iterator if an error
117 2486 sjacqu01
   * occurs.
118 2486 sjacqu01
   *
119 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
120 2486 sjacqu01
   *
121 2486 sjacqu01
   * A successful call to this function is guaranteed to return at least one
122 2486 sjacqu01
   * entry.
123 2486 sjacqu01
   */
124 2486 sjacqu01
  iterator resolve(const query& q, boost::system::error_code& ec)
125 2486 sjacqu01
  {
126 2486 sjacqu01
    return this->service.resolve(this->implementation, q, ec);
127 2486 sjacqu01
  }
128 2486 sjacqu01
129 2486 sjacqu01
  /// Asynchronously perform forward resolution of a query to a list of entries.
130 2486 sjacqu01
  /**
131 2486 sjacqu01
   * This function is used to asynchronously resolve a query into a list of
132 2486 sjacqu01
   * endpoint entries.
133 2486 sjacqu01
   *
134 2486 sjacqu01
   * @param q A query object that determines what endpoints will be returned.
135 2486 sjacqu01
   *
136 2486 sjacqu01
   * @param handler The handler to be called when the resolve operation
137 2486 sjacqu01
   * completes. Copies will be made of the handler as required. The function
138 2486 sjacqu01
   * signature of the handler must be:
139 2486 sjacqu01
   * @code void handler(
140 2486 sjacqu01
   *   const boost::system::error_code& error, // Result of operation.
141 2486 sjacqu01
   *   resolver::iterator iterator             // Forward-only iterator that can
142 2486 sjacqu01
   *                                           // be used to traverse the list
143 2486 sjacqu01
   *                                           // of endpoint entries.
144 2486 sjacqu01
   * ); @endcode
145 2486 sjacqu01
   * Regardless of whether the asynchronous operation completes immediately or
146 2486 sjacqu01
   * not, the handler will not be invoked from within this function. Invocation
147 2486 sjacqu01
   * of the handler will be performed in a manner equivalent to using
148 2486 sjacqu01
   * boost::asio::io_service::post().
149 2486 sjacqu01
   *
150 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
151 2486 sjacqu01
   *
152 2486 sjacqu01
   * A successful resolve operation is guaranteed to pass at least one entry to
153 2486 sjacqu01
   * the handler.
154 2486 sjacqu01
   */
155 2486 sjacqu01
  template <typename ResolveHandler>
156 2486 sjacqu01
  BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
157 2486 sjacqu01
      void (boost::system::error_code, iterator))
158 2486 sjacqu01
  async_resolve(const query& q,
159 2486 sjacqu01
      BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
160 2486 sjacqu01
  {
161 2486 sjacqu01
    // If you get an error on the following line it means that your handler does
162 2486 sjacqu01
    // not meet the documented type requirements for a ResolveHandler.
163 2486 sjacqu01
    BOOST_ASIO_RESOLVE_HANDLER_CHECK(
164 2486 sjacqu01
        ResolveHandler, handler, iterator) type_check;
165 2486 sjacqu01
166 2486 sjacqu01
    return this->service.async_resolve(this->implementation, q,
167 2486 sjacqu01
        BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
168 2486 sjacqu01
  }
169 2486 sjacqu01
170 2486 sjacqu01
  /// Perform reverse resolution of an endpoint to a list of entries.
171 2486 sjacqu01
  /**
172 2486 sjacqu01
   * This function is used to resolve an endpoint into a list of endpoint
173 2486 sjacqu01
   * entries.
174 2486 sjacqu01
   *
175 2486 sjacqu01
   * @param e An endpoint object that determines what endpoints will be
176 2486 sjacqu01
   * returned.
177 2486 sjacqu01
   *
178 2486 sjacqu01
   * @returns A forward-only iterator that can be used to traverse the list
179 2486 sjacqu01
   * of endpoint entries.
180 2486 sjacqu01
   *
181 2486 sjacqu01
   * @throws boost::system::system_error Thrown on failure.
182 2486 sjacqu01
   *
183 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
184 2486 sjacqu01
   *
185 2486 sjacqu01
   * A successful call to this function is guaranteed to return at least one
186 2486 sjacqu01
   * entry.
187 2486 sjacqu01
   */
188 2486 sjacqu01
  iterator resolve(const endpoint_type& e)
189 2486 sjacqu01
  {
190 2486 sjacqu01
    boost::system::error_code ec;
191 2486 sjacqu01
    iterator i = this->service.resolve(this->implementation, e, ec);
192 2486 sjacqu01
    boost::asio::detail::throw_error(ec, "resolve");
193 2486 sjacqu01
    return i;
194 2486 sjacqu01
  }
195 2486 sjacqu01
196 2486 sjacqu01
  /// Perform reverse resolution of an endpoint to a list of entries.
197 2486 sjacqu01
  /**
198 2486 sjacqu01
   * This function is used to resolve an endpoint into a list of endpoint
199 2486 sjacqu01
   * entries.
200 2486 sjacqu01
   *
201 2486 sjacqu01
   * @param e An endpoint object that determines what endpoints will be
202 2486 sjacqu01
   * returned.
203 2486 sjacqu01
   *
204 2486 sjacqu01
   * @param ec Set to indicate what error occurred, if any.
205 2486 sjacqu01
   *
206 2486 sjacqu01
   * @returns A forward-only iterator that can be used to traverse the list
207 2486 sjacqu01
   * of endpoint entries. Returns a default constructed iterator if an error
208 2486 sjacqu01
   * occurs.
209 2486 sjacqu01
   *
210 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
211 2486 sjacqu01
   *
212 2486 sjacqu01
   * A successful call to this function is guaranteed to return at least one
213 2486 sjacqu01
   * entry.
214 2486 sjacqu01
   */
215 2486 sjacqu01
  iterator resolve(const endpoint_type& e, boost::system::error_code& ec)
216 2486 sjacqu01
  {
217 2486 sjacqu01
    return this->service.resolve(this->implementation, e, ec);
218 2486 sjacqu01
  }
219 2486 sjacqu01
220 2486 sjacqu01
  /// Asynchronously perform reverse resolution of an endpoint to a list of
221 2486 sjacqu01
  /// entries.
222 2486 sjacqu01
  /**
223 2486 sjacqu01
   * This function is used to asynchronously resolve an endpoint into a list of
224 2486 sjacqu01
   * endpoint entries.
225 2486 sjacqu01
   *
226 2486 sjacqu01
   * @param e An endpoint object that determines what endpoints will be
227 2486 sjacqu01
   * returned.
228 2486 sjacqu01
   *
229 2486 sjacqu01
   * @param handler The handler to be called when the resolve operation
230 2486 sjacqu01
   * completes. Copies will be made of the handler as required. The function
231 2486 sjacqu01
   * signature of the handler must be:
232 2486 sjacqu01
   * @code void handler(
233 2486 sjacqu01
   *   const boost::system::error_code& error, // Result of operation.
234 2486 sjacqu01
   *   resolver::iterator iterator             // Forward-only iterator that can
235 2486 sjacqu01
   *                                           // be used to traverse the list
236 2486 sjacqu01
   *                                           // of endpoint entries.
237 2486 sjacqu01
   * ); @endcode
238 2486 sjacqu01
   * Regardless of whether the asynchronous operation completes immediately or
239 2486 sjacqu01
   * not, the handler will not be invoked from within this function. Invocation
240 2486 sjacqu01
   * of the handler will be performed in a manner equivalent to using
241 2486 sjacqu01
   * boost::asio::io_service::post().
242 2486 sjacqu01
   *
243 2486 sjacqu01
   * @note A default constructed iterator represents the end of the list.
244 2486 sjacqu01
   *
245 2486 sjacqu01
   * A successful resolve operation is guaranteed to pass at least one entry to
246 2486 sjacqu01
   * the handler.
247 2486 sjacqu01
   */
248 2486 sjacqu01
  template <typename ResolveHandler>
249 2486 sjacqu01
  BOOST_ASIO_INITFN_RESULT_TYPE(ResolveHandler,
250 2486 sjacqu01
      void (boost::system::error_code, iterator))
251 2486 sjacqu01
  async_resolve(const endpoint_type& e,
252 2486 sjacqu01
      BOOST_ASIO_MOVE_ARG(ResolveHandler) handler)
253 2486 sjacqu01
  {
254 2486 sjacqu01
    // If you get an error on the following line it means that your handler does
255 2486 sjacqu01
    // not meet the documented type requirements for a ResolveHandler.
256 2486 sjacqu01
    BOOST_ASIO_RESOLVE_HANDLER_CHECK(
257 2486 sjacqu01
        ResolveHandler, handler, iterator) type_check;
258 2486 sjacqu01
259 2486 sjacqu01
    return this->service.async_resolve(this->implementation, e,
260 2486 sjacqu01
        BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
261 2486 sjacqu01
  }
262 2486 sjacqu01
};
263 2486 sjacqu01
264 2486 sjacqu01
} // namespace ip
265 2486 sjacqu01
} // namespace asio
266 2486 sjacqu01
} // namespace boost
267 2486 sjacqu01
268 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
269 2486 sjacqu01
270 2486 sjacqu01
#endif // BOOST_ASIO_IP_BASIC_RESOLVER_HPP