2 // ip/basic_resolver.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2019 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_BASIC_RESOLVER_HPP
12 #define BOOST_ASIO_IP_BASIC_RESOLVER_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 #include <boost/asio/async_result.hpp>
21 #include <boost/asio/detail/handler_type_requirements.hpp>
22 #include <boost/asio/detail/io_object_impl.hpp>
23 #include <boost/asio/detail/non_const_lvalue.hpp>
24 #include <boost/asio/detail/string_view.hpp>
25 #include <boost/asio/detail/throw_error.hpp>
26 #include <boost/asio/error.hpp>
27 #include <boost/asio/execution_context.hpp>
28 #include <boost/asio/executor.hpp>
29 #include <boost/asio/ip/basic_resolver_iterator.hpp>
30 #include <boost/asio/ip/basic_resolver_query.hpp>
31 #include <boost/asio/ip/basic_resolver_results.hpp>
32 #include <boost/asio/ip/resolver_base.hpp>
33 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
34 # include <boost/asio/detail/winrt_resolver_service.hpp>
36 # include <boost/asio/detail/resolver_service.hpp>
39 #if defined(BOOST_ASIO_HAS_MOVE)
41 #endif // defined(BOOST_ASIO_HAS_MOVE)
43 #include <boost/asio/detail/push_options.hpp>
49 #if !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
50 #define BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL
52 // Forward declaration with defaulted arguments.
53 template <typename InternetProtocol, typename Executor = executor>
56 #endif // !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
58 /// Provides endpoint resolution functionality.
60 * The basic_resolver class template provides the ability to resolve a query
61 * to a list of endpoints.
64 * @e Distinct @e objects: Safe.@n
65 * @e Shared @e objects: Unsafe.
67 template <typename InternetProtocol, typename Executor>
69 : public resolver_base
72 /// The type of the executor associated with the object.
73 typedef Executor executor_type;
75 /// Rebinds the resolver type to another executor.
76 template <typename Executor1>
77 struct rebind_executor
79 /// The resolver type when rebound to the specified executor.
80 typedef basic_resolver<InternetProtocol, Executor1> other;
83 /// The protocol type.
84 typedef InternetProtocol protocol_type;
86 /// The endpoint type.
87 typedef typename InternetProtocol::endpoint endpoint_type;
89 #if !defined(BOOST_ASIO_NO_DEPRECATED)
90 /// (Deprecated.) The query type.
91 typedef basic_resolver_query<InternetProtocol> query;
93 /// (Deprecated.) The iterator type.
94 typedef basic_resolver_iterator<InternetProtocol> iterator;
95 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
98 typedef basic_resolver_results<InternetProtocol> results_type;
100 /// Construct with executor.
102 * This constructor creates a basic_resolver.
104 * @param ex The I/O executor that the resolver will use, by default, to
105 * dispatch handlers for any asynchronous operations performed on the
108 explicit basic_resolver(const executor_type& ex)
113 /// Construct with execution context.
115 * This constructor creates a basic_resolver.
117 * @param context An execution context which provides the I/O executor that
118 * the resolver will use, by default, to dispatch handlers for any
119 * asynchronous operations performed on the resolver.
121 template <typename ExecutionContext>
122 explicit basic_resolver(ExecutionContext& context,
124 is_convertible<ExecutionContext&, execution_context&>::value
130 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
131 /// Move-construct a basic_resolver from another.
133 * This constructor moves a resolver from one object to another.
135 * @param other The other basic_resolver object from which the move will
138 * @note Following the move, the moved-from object is in the same state as if
139 * constructed using the @c basic_resolver(const executor_type&) constructor.
141 basic_resolver(basic_resolver&& other)
142 : impl_(std::move(other.impl_))
146 /// Move-assign a basic_resolver from another.
148 * This assignment operator moves a resolver from one object to another.
149 * Cancels any outstanding asynchronous operations associated with the target
152 * @param other The other basic_resolver object from which the move will
155 * @note Following the move, the moved-from object is in the same state as if
156 * constructed using the @c basic_resolver(const executor_type&) constructor.
158 basic_resolver& operator=(basic_resolver&& other)
160 impl_ = std::move(other.impl_);
163 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
165 /// Destroys the resolver.
167 * This function destroys the resolver, cancelling any outstanding
168 * asynchronous wait operations associated with the resolver as if by calling
175 /// Get the executor associated with the object.
176 executor_type get_executor() BOOST_ASIO_NOEXCEPT
178 return impl_.get_executor();
181 /// Cancel any asynchronous operations that are waiting on the resolver.
183 * This function forces the completion of any pending asynchronous
184 * operations on the host resolver. The handler for each cancelled operation
185 * will be invoked with the boost::asio::error::operation_aborted error code.
189 return impl_.get_service().cancel(impl_.get_implementation());
192 #if !defined(BOOST_ASIO_NO_DEPRECATED)
193 /// (Deprecated: Use overload with separate host and service parameters.)
194 /// Perform forward resolution of a query to a list of entries.
196 * This function is used to resolve a query into a list of endpoint entries.
198 * @param q A query object that determines what endpoints will be returned.
200 * @returns A range object representing the list of endpoint entries. A
201 * successful call to this function is guaranteed to return a non-empty
204 * @throws boost::system::system_error Thrown on failure.
206 results_type resolve(const query& q)
208 boost::system::error_code ec;
209 results_type r = impl_.get_service().resolve(
210 impl_.get_implementation(), q, ec);
211 boost::asio::detail::throw_error(ec, "resolve");
215 /// (Deprecated: Use overload with separate host and service parameters.)
216 /// Perform forward resolution of a query to a list of entries.
218 * This function is used to resolve a query into a list of endpoint entries.
220 * @param q A query object that determines what endpoints will be returned.
222 * @param ec Set to indicate what error occurred, if any.
224 * @returns A range object representing the list of endpoint entries. An
225 * empty range is returned if an error occurs. A successful call to this
226 * function is guaranteed to return a non-empty range.
228 results_type resolve(const query& q, boost::system::error_code& ec)
230 return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
232 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
234 /// Perform forward resolution of a query to a list of entries.
236 * This function is used to resolve host and service names into a list of
239 * @param host A string identifying a location. May be a descriptive name or
240 * a numeric address string. If an empty string and the passive flag has been
241 * specified, the resolved endpoints are suitable for local service binding.
242 * If an empty string and passive is not specified, the resolved endpoints
243 * will use the loopback address.
245 * @param service A string identifying the requested service. This may be a
246 * descriptive name or a numeric string corresponding to a port number. May
247 * be an empty string, in which case all resolved endpoints will have a port
250 * @returns A range object representing the list of endpoint entries. A
251 * successful call to this function is guaranteed to return a non-empty
254 * @throws boost::system::system_error Thrown on failure.
256 * @note On POSIX systems, host names may be locally defined in the file
257 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
258 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
259 * resolution is performed using DNS. Operating systems may use additional
260 * locations when resolving host names (such as NETBIOS names on Windows).
262 * On POSIX systems, service names are typically defined in the file
263 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
264 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
265 * may use additional locations when resolving service names.
267 results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
268 BOOST_ASIO_STRING_VIEW_PARAM service)
270 return resolve(host, service, resolver_base::flags());
273 /// Perform forward resolution of a query to a list of entries.
275 * This function is used to resolve host and service names into a list of
278 * @param host A string identifying a location. May be a descriptive name or
279 * a numeric address string. If an empty string and the passive flag has been
280 * specified, the resolved endpoints are suitable for local service binding.
281 * If an empty string and passive is not specified, the resolved endpoints
282 * will use the loopback address.
284 * @param service A string identifying the requested service. This may be a
285 * descriptive name or a numeric string corresponding to a port number. May
286 * be an empty string, in which case all resolved endpoints will have a port
289 * @param ec Set to indicate what error occurred, if any.
291 * @returns A range object representing the list of endpoint entries. An
292 * empty range is returned if an error occurs. A successful call to this
293 * function is guaranteed to return a non-empty range.
295 * @note On POSIX systems, host names may be locally defined in the file
296 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
297 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
298 * resolution is performed using DNS. Operating systems may use additional
299 * locations when resolving host names (such as NETBIOS names on Windows).
301 * On POSIX systems, service names are typically defined in the file
302 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
303 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
304 * may use additional locations when resolving service names.
306 results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
307 BOOST_ASIO_STRING_VIEW_PARAM service, boost::system::error_code& ec)
309 return resolve(host, service, resolver_base::flags(), ec);
312 /// Perform forward resolution of a query to a list of entries.
314 * This function is used to resolve host and service names into a list of
317 * @param host A string identifying a location. May be a descriptive name or
318 * a numeric address string. If an empty string and the passive flag has been
319 * specified, the resolved endpoints are suitable for local service binding.
320 * If an empty string and passive is not specified, the resolved endpoints
321 * will use the loopback address.
323 * @param service A string identifying the requested service. This may be a
324 * descriptive name or a numeric string corresponding to a port number. May
325 * be an empty string, in which case all resolved endpoints will have a port
328 * @param resolve_flags A set of flags that determine how name resolution
329 * should be performed. The default flags are suitable for communication with
330 * remote hosts. See the @ref resolver_base documentation for the set of
333 * @returns A range object representing the list of endpoint entries. A
334 * successful call to this function is guaranteed to return a non-empty
337 * @throws boost::system::system_error Thrown on failure.
339 * @note On POSIX systems, host names may be locally defined in the file
340 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
341 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
342 * resolution is performed using DNS. Operating systems may use additional
343 * locations when resolving host names (such as NETBIOS names on Windows).
345 * On POSIX systems, service names are typically defined in the file
346 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
347 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
348 * may use additional locations when resolving service names.
350 results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
351 BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags)
353 boost::system::error_code ec;
354 basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
355 static_cast<std::string>(service), resolve_flags);
356 results_type r = impl_.get_service().resolve(
357 impl_.get_implementation(), q, ec);
358 boost::asio::detail::throw_error(ec, "resolve");
362 /// Perform forward resolution of a query to a list of entries.
364 * This function is used to resolve host and service names into a list of
367 * @param host A string identifying a location. May be a descriptive name or
368 * a numeric address string. If an empty string and the passive flag has been
369 * specified, the resolved endpoints are suitable for local service binding.
370 * If an empty string and passive is not specified, the resolved endpoints
371 * will use the loopback address.
373 * @param service A string identifying the requested service. This may be a
374 * descriptive name or a numeric string corresponding to a port number. May
375 * be an empty string, in which case all resolved endpoints will have a port
378 * @param resolve_flags A set of flags that determine how name resolution
379 * should be performed. The default flags are suitable for communication with
380 * remote hosts. See the @ref resolver_base documentation for the set of
383 * @param ec Set to indicate what error occurred, if any.
385 * @returns A range object representing the list of endpoint entries. An
386 * empty range is returned if an error occurs. A successful call to this
387 * function is guaranteed to return a non-empty range.
389 * @note On POSIX systems, host names may be locally defined in the file
390 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
391 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
392 * resolution is performed using DNS. Operating systems may use additional
393 * locations when resolving host names (such as NETBIOS names on Windows).
395 * On POSIX systems, service names are typically defined in the file
396 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
397 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
398 * may use additional locations when resolving service names.
400 results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
401 BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
402 boost::system::error_code& ec)
404 basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
405 static_cast<std::string>(service), resolve_flags);
406 return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
409 /// Perform forward resolution of a query to a list of entries.
411 * This function is used to resolve host and service names into a list of
414 * @param protocol A protocol object, normally representing either the IPv4 or
415 * IPv6 version of an internet protocol.
417 * @param host A string identifying a location. May be a descriptive name or
418 * a numeric address string. If an empty string and the passive flag has been
419 * specified, the resolved endpoints are suitable for local service binding.
420 * If an empty string and passive is not specified, the resolved endpoints
421 * will use the loopback address.
423 * @param service A string identifying the requested service. This may be a
424 * descriptive name or a numeric string corresponding to a port number. May
425 * be an empty string, in which case all resolved endpoints will have a port
428 * @returns A range object representing the list of endpoint entries. A
429 * successful call to this function is guaranteed to return a non-empty
432 * @throws boost::system::system_error Thrown on failure.
434 * @note On POSIX systems, host names may be locally defined in the file
435 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
436 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
437 * resolution is performed using DNS. Operating systems may use additional
438 * locations when resolving host names (such as NETBIOS names on Windows).
440 * On POSIX systems, service names are typically defined in the file
441 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
442 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
443 * may use additional locations when resolving service names.
445 results_type resolve(const protocol_type& protocol,
446 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service)
448 return resolve(protocol, host, service, resolver_base::flags());
451 /// Perform forward resolution of a query to a list of entries.
453 * This function is used to resolve host and service names into a list of
456 * @param protocol A protocol object, normally representing either the IPv4 or
457 * IPv6 version of an internet protocol.
459 * @param host A string identifying a location. May be a descriptive name or
460 * a numeric address string. If an empty string and the passive flag has been
461 * specified, the resolved endpoints are suitable for local service binding.
462 * If an empty string and passive is not specified, the resolved endpoints
463 * will use the loopback address.
465 * @param service A string identifying the requested service. This may be a
466 * descriptive name or a numeric string corresponding to a port number. May
467 * be an empty string, in which case all resolved endpoints will have a port
470 * @param ec Set to indicate what error occurred, if any.
472 * @returns A range object representing the list of endpoint entries. An
473 * empty range is returned if an error occurs. A successful call to this
474 * function is guaranteed to return a non-empty range.
476 * @note On POSIX systems, host names may be locally defined in the file
477 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
478 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
479 * resolution is performed using DNS. Operating systems may use additional
480 * locations when resolving host names (such as NETBIOS names on Windows).
482 * On POSIX systems, service names are typically defined in the file
483 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
484 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
485 * may use additional locations when resolving service names.
487 results_type resolve(const protocol_type& protocol,
488 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
489 boost::system::error_code& ec)
491 return resolve(protocol, host, service, resolver_base::flags(), ec);
494 /// Perform forward resolution of a query to a list of entries.
496 * This function is used to resolve host and service names into a list of
499 * @param protocol A protocol object, normally representing either the IPv4 or
500 * IPv6 version of an internet protocol.
502 * @param host A string identifying a location. May be a descriptive name or
503 * a numeric address string. If an empty string and the passive flag has been
504 * specified, the resolved endpoints are suitable for local service binding.
505 * If an empty string and passive is not specified, the resolved endpoints
506 * will use the loopback address.
508 * @param service A string identifying the requested service. This may be a
509 * descriptive name or a numeric string corresponding to a port number. May
510 * be an empty string, in which case all resolved endpoints will have a port
513 * @param resolve_flags A set of flags that determine how name resolution
514 * should be performed. The default flags are suitable for communication with
515 * remote hosts. See the @ref resolver_base documentation for the set of
518 * @returns A range object representing the list of endpoint entries. A
519 * successful call to this function is guaranteed to return a non-empty
522 * @throws boost::system::system_error Thrown on failure.
524 * @note On POSIX systems, host names may be locally defined in the file
525 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
526 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
527 * resolution is performed using DNS. Operating systems may use additional
528 * locations when resolving host names (such as NETBIOS names on Windows).
530 * On POSIX systems, service names are typically defined in the file
531 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
532 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
533 * may use additional locations when resolving service names.
535 results_type resolve(const protocol_type& protocol,
536 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
537 resolver_base::flags resolve_flags)
539 boost::system::error_code ec;
540 basic_resolver_query<protocol_type> q(
541 protocol, static_cast<std::string>(host),
542 static_cast<std::string>(service), resolve_flags);
543 results_type r = impl_.get_service().resolve(
544 impl_.get_implementation(), q, ec);
545 boost::asio::detail::throw_error(ec, "resolve");
549 /// Perform forward resolution of a query to a list of entries.
551 * This function is used to resolve host and service names into a list of
554 * @param protocol A protocol object, normally representing either the IPv4 or
555 * IPv6 version of an internet protocol.
557 * @param host A string identifying a location. May be a descriptive name or
558 * a numeric address string. If an empty string and the passive flag has been
559 * specified, the resolved endpoints are suitable for local service binding.
560 * If an empty string and passive is not specified, the resolved endpoints
561 * will use the loopback address.
563 * @param service A string identifying the requested service. This may be a
564 * descriptive name or a numeric string corresponding to a port number. May
565 * be an empty string, in which case all resolved endpoints will have a port
568 * @param resolve_flags A set of flags that determine how name resolution
569 * should be performed. The default flags are suitable for communication with
570 * remote hosts. See the @ref resolver_base documentation for the set of
573 * @param ec Set to indicate what error occurred, if any.
575 * @returns A range object representing the list of endpoint entries. An
576 * empty range is returned if an error occurs. A successful call to this
577 * function is guaranteed to return a non-empty range.
579 * @note On POSIX systems, host names may be locally defined in the file
580 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
581 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
582 * resolution is performed using DNS. Operating systems may use additional
583 * locations when resolving host names (such as NETBIOS names on Windows).
585 * On POSIX systems, service names are typically defined in the file
586 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
587 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
588 * may use additional locations when resolving service names.
590 results_type resolve(const protocol_type& protocol,
591 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
592 resolver_base::flags resolve_flags, boost::system::error_code& ec)
594 basic_resolver_query<protocol_type> q(
595 protocol, static_cast<std::string>(host),
596 static_cast<std::string>(service), resolve_flags);
597 return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
600 #if !defined(BOOST_ASIO_NO_DEPRECATED)
601 /// (Deprecated: Use overload with separate host and service parameters.)
602 /// Asynchronously perform forward resolution of a query to a list of entries.
604 * This function is used to asynchronously resolve a query into a list of
607 * @param q A query object that determines what endpoints will be returned.
609 * @param handler The handler to be called when the resolve operation
610 * completes. Copies will be made of the handler as required. The function
611 * signature of the handler must be:
612 * @code void handler(
613 * const boost::system::error_code& error, // Result of operation.
614 * resolver::results_type results // Resolved endpoints as a range.
616 * Regardless of whether the asynchronous operation completes immediately or
617 * not, the handler will not be invoked from within this function. On
618 * immediate completion, invocation of the handler will be performed in a
619 * manner equivalent to using boost::asio::post().
621 * A successful resolve operation is guaranteed to pass a non-empty range to
625 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
626 results_type)) ResolveHandler
627 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
628 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
629 void (boost::system::error_code, results_type))
630 async_resolve(const query& q,
631 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
632 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
634 return boost::asio::async_initiate<ResolveHandler,
635 void (boost::system::error_code, results_type)>(
636 initiate_async_resolve(this), handler, q);
638 #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
640 /// Asynchronously perform forward resolution of a query to a list of entries.
642 * This function is used to resolve host and service names into a list of
645 * @param host A string identifying a location. May be a descriptive name or
646 * a numeric address string. If an empty string and the passive flag has been
647 * specified, the resolved endpoints are suitable for local service binding.
648 * If an empty string and passive is not specified, the resolved endpoints
649 * will use the loopback address.
651 * @param service A string identifying the requested service. This may be a
652 * descriptive name or a numeric string corresponding to a port number. May
653 * be an empty string, in which case all resolved endpoints will have a port
656 * @param handler The handler to be called when the resolve operation
657 * completes. Copies will be made of the handler as required. The function
658 * signature of the handler must be:
659 * @code void handler(
660 * const boost::system::error_code& error, // Result of operation.
661 * resolver::results_type results // Resolved endpoints as a range.
663 * Regardless of whether the asynchronous operation completes immediately or
664 * not, the handler will not be invoked from within this function. On
665 * immediate completion, invocation of the handler will be performed in a
666 * manner equivalent to using boost::asio::post().
668 * A successful resolve operation is guaranteed to pass a non-empty range to
671 * @note On POSIX systems, host names may be locally defined in the file
672 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
673 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
674 * resolution is performed using DNS. Operating systems may use additional
675 * locations when resolving host names (such as NETBIOS names on Windows).
677 * On POSIX systems, service names are typically defined in the file
678 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
679 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
680 * may use additional locations when resolving service names.
683 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
684 results_type)) ResolveHandler
685 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
686 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
687 void (boost::system::error_code, results_type))
688 async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
689 BOOST_ASIO_STRING_VIEW_PARAM service,
690 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
691 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
693 return async_resolve(host, service, resolver_base::flags(),
694 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
697 /// Asynchronously perform forward resolution of a query to a list of entries.
699 * This function is used to resolve host and service names into a list of
702 * @param host A string identifying a location. May be a descriptive name or
703 * a numeric address string. If an empty string and the passive flag has been
704 * specified, the resolved endpoints are suitable for local service binding.
705 * If an empty string and passive is not specified, the resolved endpoints
706 * will use the loopback address.
708 * @param service A string identifying the requested service. This may be a
709 * descriptive name or a numeric string corresponding to a port number. May
710 * be an empty string, in which case all resolved endpoints will have a port
713 * @param resolve_flags A set of flags that determine how name resolution
714 * should be performed. The default flags are suitable for communication with
715 * remote hosts. See the @ref resolver_base documentation for the set of
718 * @param handler The handler to be called when the resolve operation
719 * completes. Copies will be made of the handler as required. The function
720 * signature of the handler must be:
721 * @code void handler(
722 * const boost::system::error_code& error, // Result of operation.
723 * resolver::results_type results // Resolved endpoints as a range.
725 * Regardless of whether the asynchronous operation completes immediately or
726 * not, the handler will not be invoked from within this function. On
727 * immediate completion, invocation of the handler will be performed in a
728 * manner equivalent to using boost::asio::post().
730 * A successful resolve operation is guaranteed to pass a non-empty range to
733 * @note On POSIX systems, host names may be locally defined in the file
734 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
735 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
736 * resolution is performed using DNS. Operating systems may use additional
737 * locations when resolving host names (such as NETBIOS names on Windows).
739 * On POSIX systems, service names are typically defined in the file
740 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
741 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
742 * may use additional locations when resolving service names.
745 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
746 results_type)) ResolveHandler
747 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
748 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
749 void (boost::system::error_code, results_type))
750 async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
751 BOOST_ASIO_STRING_VIEW_PARAM service,
752 resolver_base::flags resolve_flags,
753 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
754 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
756 basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
757 static_cast<std::string>(service), resolve_flags);
759 return boost::asio::async_initiate<ResolveHandler,
760 void (boost::system::error_code, results_type)>(
761 initiate_async_resolve(this), handler, q);
764 /// Asynchronously perform forward resolution of a query to a list of entries.
766 * This function is used to resolve host and service names into a list of
769 * @param protocol A protocol object, normally representing either the IPv4 or
770 * IPv6 version of an internet protocol.
772 * @param host A string identifying a location. May be a descriptive name or
773 * a numeric address string. If an empty string and the passive flag has been
774 * specified, the resolved endpoints are suitable for local service binding.
775 * If an empty string and passive is not specified, the resolved endpoints
776 * will use the loopback address.
778 * @param service A string identifying the requested service. This may be a
779 * descriptive name or a numeric string corresponding to a port number. May
780 * be an empty string, in which case all resolved endpoints will have a port
783 * @param handler The handler to be called when the resolve operation
784 * completes. Copies will be made of the handler as required. The function
785 * signature of the handler must be:
786 * @code void handler(
787 * const boost::system::error_code& error, // Result of operation.
788 * resolver::results_type results // Resolved endpoints as a range.
790 * Regardless of whether the asynchronous operation completes immediately or
791 * not, the handler will not be invoked from within this function. On
792 * immediate completion, invocation of the handler will be performed in a
793 * manner equivalent to using boost::asio::post().
795 * A successful resolve operation is guaranteed to pass a non-empty range to
798 * @note On POSIX systems, host names may be locally defined in the file
799 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
800 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
801 * resolution is performed using DNS. Operating systems may use additional
802 * locations when resolving host names (such as NETBIOS names on Windows).
804 * On POSIX systems, service names are typically defined in the file
805 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
806 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
807 * may use additional locations when resolving service names.
810 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
811 results_type)) ResolveHandler
812 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
813 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
814 void (boost::system::error_code, results_type))
815 async_resolve(const protocol_type& protocol,
816 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
817 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
818 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
820 return async_resolve(protocol, host, service, resolver_base::flags(),
821 BOOST_ASIO_MOVE_CAST(ResolveHandler)(handler));
824 /// Asynchronously perform forward resolution of a query to a list of entries.
826 * This function is used to resolve host and service names into a list of
829 * @param protocol A protocol object, normally representing either the IPv4 or
830 * IPv6 version of an internet protocol.
832 * @param host A string identifying a location. May be a descriptive name or
833 * a numeric address string. If an empty string and the passive flag has been
834 * specified, the resolved endpoints are suitable for local service binding.
835 * If an empty string and passive is not specified, the resolved endpoints
836 * will use the loopback address.
838 * @param service A string identifying the requested service. This may be a
839 * descriptive name or a numeric string corresponding to a port number. May
840 * be an empty string, in which case all resolved endpoints will have a port
843 * @param resolve_flags A set of flags that determine how name resolution
844 * should be performed. The default flags are suitable for communication with
845 * remote hosts. See the @ref resolver_base documentation for the set of
848 * @param handler The handler to be called when the resolve operation
849 * completes. Copies will be made of the handler as required. The function
850 * signature of the handler must be:
851 * @code void handler(
852 * const boost::system::error_code& error, // Result of operation.
853 * resolver::results_type results // Resolved endpoints as a range.
855 * Regardless of whether the asynchronous operation completes immediately or
856 * not, the handler will not be invoked from within this function. On
857 * immediate completion, invocation of the handler will be performed in a
858 * manner equivalent to using boost::asio::post().
860 * A successful resolve operation is guaranteed to pass a non-empty range to
863 * @note On POSIX systems, host names may be locally defined in the file
864 * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
865 * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
866 * resolution is performed using DNS. Operating systems may use additional
867 * locations when resolving host names (such as NETBIOS names on Windows).
869 * On POSIX systems, service names are typically defined in the file
870 * <tt>/etc/services</tt>. On Windows, service names may be found in the file
871 * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
872 * may use additional locations when resolving service names.
875 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
876 results_type)) ResolveHandler
877 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
878 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
879 void (boost::system::error_code, results_type))
880 async_resolve(const protocol_type& protocol,
881 BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
882 resolver_base::flags resolve_flags,
883 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
884 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
886 basic_resolver_query<protocol_type> q(
887 protocol, static_cast<std::string>(host),
888 static_cast<std::string>(service), resolve_flags);
890 return boost::asio::async_initiate<ResolveHandler,
891 void (boost::system::error_code, results_type)>(
892 initiate_async_resolve(this), handler, q);
895 /// Perform reverse resolution of an endpoint to a list of entries.
897 * This function is used to resolve an endpoint into a list of endpoint
900 * @param e An endpoint object that determines what endpoints will be
903 * @returns A range object representing the list of endpoint entries. A
904 * successful call to this function is guaranteed to return a non-empty
907 * @throws boost::system::system_error Thrown on failure.
909 results_type resolve(const endpoint_type& e)
911 boost::system::error_code ec;
912 results_type i = impl_.get_service().resolve(
913 impl_.get_implementation(), e, ec);
914 boost::asio::detail::throw_error(ec, "resolve");
918 /// Perform reverse resolution of an endpoint to a list of entries.
920 * This function is used to resolve an endpoint into a list of endpoint
923 * @param e An endpoint object that determines what endpoints will be
926 * @param ec Set to indicate what error occurred, if any.
928 * @returns A range object representing the list of endpoint entries. An
929 * empty range is returned if an error occurs. A successful call to this
930 * function is guaranteed to return a non-empty range.
932 results_type resolve(const endpoint_type& e, boost::system::error_code& ec)
934 return impl_.get_service().resolve(impl_.get_implementation(), e, ec);
937 /// Asynchronously perform reverse resolution of an endpoint to a list of
940 * This function is used to asynchronously resolve an endpoint into a list of
943 * @param e An endpoint object that determines what endpoints will be
946 * @param handler The handler to be called when the resolve operation
947 * completes. Copies will be made of the handler as required. The function
948 * signature of the handler must be:
949 * @code void handler(
950 * const boost::system::error_code& error, // Result of operation.
951 * resolver::results_type results // Resolved endpoints as a range.
953 * Regardless of whether the asynchronous operation completes immediately or
954 * not, the handler will not be invoked from within this function. On
955 * immediate completion, invocation of the handler will be performed in a
956 * manner equivalent to using boost::asio::post().
958 * A successful resolve operation is guaranteed to pass a non-empty range to
962 BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
963 results_type)) ResolveHandler
964 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type)>
965 BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(ResolveHandler,
966 void (boost::system::error_code, results_type))
967 async_resolve(const endpoint_type& e,
968 BOOST_ASIO_MOVE_ARG(ResolveHandler) handler
969 BOOST_ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
971 return boost::asio::async_initiate<ResolveHandler,
972 void (boost::system::error_code, results_type)>(
973 initiate_async_resolve(this), handler, e);
977 // Disallow copying and assignment.
978 basic_resolver(const basic_resolver&) BOOST_ASIO_DELETED;
979 basic_resolver& operator=(const basic_resolver&) BOOST_ASIO_DELETED;
981 class initiate_async_resolve
984 typedef Executor executor_type;
986 explicit initiate_async_resolve(basic_resolver* self)
991 executor_type get_executor() const BOOST_ASIO_NOEXCEPT
993 return self_->get_executor();
996 template <typename ResolveHandler, typename Query>
997 void operator()(BOOST_ASIO_MOVE_ARG(ResolveHandler) handler,
998 const Query& q) const
1000 // If you get an error on the following line it means that your handler
1001 // does not meet the documented type requirements for a ResolveHandler.
1002 BOOST_ASIO_RESOLVE_HANDLER_CHECK(
1003 ResolveHandler, handler, results_type) type_check;
1005 boost::asio::detail::non_const_lvalue<ResolveHandler> handler2(handler);
1006 self_->impl_.get_service().async_resolve(
1007 self_->impl_.get_implementation(), q, handler2.value,
1008 self_->impl_.get_implementation_executor());
1012 basic_resolver* self_;
1015 # if defined(BOOST_ASIO_WINDOWS_RUNTIME)
1016 boost::asio::detail::io_object_impl<
1017 boost::asio::detail::winrt_resolver_service<InternetProtocol>,
1020 boost::asio::detail::io_object_impl<
1021 boost::asio::detail::resolver_service<InternetProtocol>,
1028 } // namespace boost
1030 #include <boost/asio/detail/pop_options.hpp>
1032 #endif // BOOST_ASIO_IP_BASIC_RESOLVER_HPP