Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:29:04

0001 //
0002 // ip/basic_resolver.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_HPP
0012 #define BOOST_ASIO_IP_BASIC_RESOLVER_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <string>
0020 #include <utility>
0021 #include <boost/asio/any_io_executor.hpp>
0022 #include <boost/asio/async_result.hpp>
0023 #include <boost/asio/detail/handler_type_requirements.hpp>
0024 #include <boost/asio/detail/io_object_impl.hpp>
0025 #include <boost/asio/detail/non_const_lvalue.hpp>
0026 #include <boost/asio/detail/string_view.hpp>
0027 #include <boost/asio/detail/throw_error.hpp>
0028 #include <boost/asio/error.hpp>
0029 #include <boost/asio/execution_context.hpp>
0030 #include <boost/asio/ip/basic_resolver_iterator.hpp>
0031 #include <boost/asio/ip/basic_resolver_query.hpp>
0032 #include <boost/asio/ip/basic_resolver_results.hpp>
0033 #include <boost/asio/ip/resolver_base.hpp>
0034 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
0035 # include <boost/asio/detail/winrt_resolver_service.hpp>
0036 #else
0037 # include <boost/asio/detail/resolver_service.hpp>
0038 #endif
0039 
0040 #include <boost/asio/detail/push_options.hpp>
0041 
0042 namespace boost {
0043 namespace asio {
0044 namespace ip {
0045 
0046 #if !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
0047 #define BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL
0048 
0049 // Forward declaration with defaulted arguments.
0050 template <typename InternetProtocol, typename Executor = any_io_executor>
0051 class basic_resolver;
0052 
0053 #endif // !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
0054 
0055 /// Provides endpoint resolution functionality.
0056 /**
0057  * The basic_resolver class template provides the ability to resolve a query
0058  * to a list of endpoints.
0059  *
0060  * @par Thread Safety
0061  * @e Distinct @e objects: Safe.@n
0062  * @e Shared @e objects: Unsafe.
0063  */
0064 template <typename InternetProtocol, typename Executor>
0065 class basic_resolver
0066   : public resolver_base
0067 {
0068 private:
0069   class initiate_async_resolve;
0070 
0071 public:
0072   /// The type of the executor associated with the object.
0073   typedef Executor executor_type;
0074 
0075   /// Rebinds the resolver type to another executor.
0076   template <typename Executor1>
0077   struct rebind_executor
0078   {
0079     /// The resolver type when rebound to the specified executor.
0080     typedef basic_resolver<InternetProtocol, Executor1> other;
0081   };
0082 
0083   /// The protocol type.
0084   typedef InternetProtocol protocol_type;
0085 
0086   /// The endpoint type.
0087   typedef typename InternetProtocol::endpoint endpoint_type;
0088 
0089   /// The results type.
0090   typedef basic_resolver_results<InternetProtocol> results_type;
0091 
0092   /// Construct with executor.
0093   /**
0094    * This constructor creates a basic_resolver.
0095    *
0096    * @param ex The I/O executor that the resolver will use, by default, to
0097    * dispatch handlers for any asynchronous operations performed on the
0098    * resolver.
0099    */
0100   explicit basic_resolver(const executor_type& ex)
0101     : impl_(0, ex)
0102   {
0103   }
0104 
0105   /// Construct with execution context.
0106   /**
0107    * This constructor creates a basic_resolver.
0108    *
0109    * @param context An execution context which provides the I/O executor that
0110    * the resolver will use, by default, to dispatch handlers for any
0111    * asynchronous operations performed on the resolver.
0112    */
0113   template <typename ExecutionContext>
0114   explicit basic_resolver(ExecutionContext& context,
0115       constraint_t<
0116         is_convertible<ExecutionContext&, execution_context&>::value
0117       > = 0)
0118     : impl_(0, 0, context)
0119   {
0120   }
0121 
0122   /// Move-construct a basic_resolver from another.
0123   /**
0124    * This constructor moves a resolver from one object to another.
0125    *
0126    * @param other The other basic_resolver object from which the move will
0127    * occur.
0128    *
0129    * @note Following the move, the moved-from object is in the same state as if
0130    * constructed using the @c basic_resolver(const executor_type&) constructor.
0131    */
0132   basic_resolver(basic_resolver&& other)
0133     : impl_(std::move(other.impl_))
0134   {
0135   }
0136 
0137   // All resolvers have access to each other's implementations.
0138   template <typename InternetProtocol1, typename Executor1>
0139   friend class basic_resolver;
0140 
0141   /// Move-construct a basic_resolver from another.
0142   /**
0143    * This constructor moves a resolver from one object to another.
0144    *
0145    * @param other The other basic_resolver object from which the move will
0146    * occur.
0147    *
0148    * @note Following the move, the moved-from object is in the same state as if
0149    * constructed using the @c basic_resolver(const executor_type&) constructor.
0150    */
0151   template <typename Executor1>
0152   basic_resolver(basic_resolver<InternetProtocol, Executor1>&& other,
0153       constraint_t<
0154           is_convertible<Executor1, Executor>::value
0155       > = 0)
0156     : impl_(std::move(other.impl_))
0157   {
0158   }
0159 
0160   /// Move-assign a basic_resolver from another.
0161   /**
0162    * This assignment operator moves a resolver from one object to another.
0163    * Cancels any outstanding asynchronous operations associated with the target
0164    * object.
0165    *
0166    * @param other The other basic_resolver object from which the move will
0167    * occur.
0168    *
0169    * @note Following the move, the moved-from object is in the same state as if
0170    * constructed using the @c basic_resolver(const executor_type&) constructor.
0171    */
0172   basic_resolver& operator=(basic_resolver&& other)
0173   {
0174     impl_ = std::move(other.impl_);
0175     return *this;
0176   }
0177 
0178   /// Move-assign a basic_resolver from another.
0179   /**
0180    * This assignment operator moves a resolver from one object to another.
0181    * Cancels any outstanding asynchronous operations associated with the target
0182    * object.
0183    *
0184    * @param other The other basic_resolver object from which the move will
0185    * occur.
0186    *
0187    * @note Following the move, the moved-from object is in the same state as if
0188    * constructed using the @c basic_resolver(const executor_type&) constructor.
0189    */
0190   template <typename Executor1>
0191   constraint_t<
0192     is_convertible<Executor1, Executor>::value,
0193     basic_resolver&
0194   > operator=(basic_resolver<InternetProtocol, Executor1>&& other)
0195   {
0196     basic_resolver tmp(std::move(other));
0197     impl_ = std::move(tmp.impl_);
0198     return *this;
0199   }
0200 
0201   /// Destroys the resolver.
0202   /**
0203    * This function destroys the resolver, cancelling any outstanding
0204    * asynchronous wait operations associated with the resolver as if by calling
0205    * @c cancel.
0206    */
0207   ~basic_resolver()
0208   {
0209   }
0210 
0211   /// Get the executor associated with the object.
0212   executor_type get_executor() noexcept
0213   {
0214     return impl_.get_executor();
0215   }
0216 
0217   /// Cancel any asynchronous operations that are waiting on the resolver.
0218   /**
0219    * This function forces the completion of any pending asynchronous
0220    * operations on the host resolver. The handler for each cancelled operation
0221    * will be invoked with the boost::asio::error::operation_aborted error code.
0222    */
0223   void cancel()
0224   {
0225     return impl_.get_service().cancel(impl_.get_implementation());
0226   }
0227 
0228   /// Perform forward resolution of a query to a list of entries.
0229   /**
0230    * This function is used to resolve host and service names into a list of
0231    * endpoint entries.
0232    *
0233    * @param host A string identifying a location. May be a descriptive name or
0234    * a numeric address string. If an empty string and the passive flag has been
0235    * specified, the resolved endpoints are suitable for local service binding.
0236    * If an empty string and passive is not specified, the resolved endpoints
0237    * will use the loopback address.
0238    *
0239    * @param service A string identifying the requested service. This may be a
0240    * descriptive name or a numeric string corresponding to a port number. May
0241    * be an empty string, in which case all resolved endpoints will have a port
0242    * number of 0.
0243    *
0244    * @returns A range object representing the list of endpoint entries. A
0245    * successful call to this function is guaranteed to return a non-empty
0246    * range.
0247    *
0248    * @throws boost::system::system_error Thrown on failure.
0249    *
0250    * @note On POSIX systems, host names may be locally defined in the file
0251    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0252    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0253    * resolution is performed using DNS. Operating systems may use additional
0254    * locations when resolving host names (such as NETBIOS names on Windows).
0255    *
0256    * On POSIX systems, service names are typically defined in the file
0257    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0258    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0259    * may use additional locations when resolving service names.
0260    */
0261   results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0262       BOOST_ASIO_STRING_VIEW_PARAM service)
0263   {
0264     return resolve(host, service, resolver_base::flags());
0265   }
0266 
0267   /// Perform forward resolution of a query to a list of entries.
0268   /**
0269    * This function is used to resolve host and service names into a list of
0270    * endpoint entries.
0271    *
0272    * @param host A string identifying a location. May be a descriptive name or
0273    * a numeric address string. If an empty string and the passive flag has been
0274    * specified, the resolved endpoints are suitable for local service binding.
0275    * If an empty string and passive is not specified, the resolved endpoints
0276    * will use the loopback address.
0277    *
0278    * @param service A string identifying the requested service. This may be a
0279    * descriptive name or a numeric string corresponding to a port number. May
0280    * be an empty string, in which case all resolved endpoints will have a port
0281    * number of 0.
0282    *
0283    * @param ec Set to indicate what error occurred, if any.
0284    *
0285    * @returns A range object representing the list of endpoint entries. An
0286    * empty range is returned if an error occurs. A successful call to this
0287    * function is guaranteed to return a non-empty range.
0288    *
0289    * @note On POSIX systems, host names may be locally defined in the file
0290    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0291    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0292    * resolution is performed using DNS. Operating systems may use additional
0293    * locations when resolving host names (such as NETBIOS names on Windows).
0294    *
0295    * On POSIX systems, service names are typically defined in the file
0296    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0297    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0298    * may use additional locations when resolving service names.
0299    */
0300   results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0301       BOOST_ASIO_STRING_VIEW_PARAM service, boost::system::error_code& ec)
0302   {
0303     return resolve(host, service, resolver_base::flags(), ec);
0304   }
0305 
0306   /// Perform forward resolution of a query to a list of entries.
0307   /**
0308    * This function is used to resolve host and service names into a list of
0309    * endpoint entries.
0310    *
0311    * @param host A string identifying a location. May be a descriptive name or
0312    * a numeric address string. If an empty string and the passive flag has been
0313    * specified, the resolved endpoints are suitable for local service binding.
0314    * If an empty string and passive is not specified, the resolved endpoints
0315    * will use the loopback address.
0316    *
0317    * @param service A string identifying the requested service. This may be a
0318    * descriptive name or a numeric string corresponding to a port number. May
0319    * be an empty string, in which case all resolved endpoints will have a port
0320    * number of 0.
0321    *
0322    * @param resolve_flags A set of flags that determine how name resolution
0323    * should be performed. The default flags are suitable for communication with
0324    * remote hosts. See the @ref resolver_base documentation for the set of
0325    * available flags.
0326    *
0327    * @returns A range object representing the list of endpoint entries. A
0328    * successful call to this function is guaranteed to return a non-empty
0329    * range.
0330    *
0331    * @throws boost::system::system_error Thrown on failure.
0332    *
0333    * @note On POSIX systems, host names may be locally defined in the file
0334    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0335    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0336    * resolution is performed using DNS. Operating systems may use additional
0337    * locations when resolving host names (such as NETBIOS names on Windows).
0338    *
0339    * On POSIX systems, service names are typically defined in the file
0340    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0341    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0342    * may use additional locations when resolving service names.
0343    */
0344   results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0345       BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags)
0346   {
0347     boost::system::error_code ec;
0348     basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
0349         static_cast<std::string>(service), resolve_flags);
0350     results_type r = impl_.get_service().resolve(
0351         impl_.get_implementation(), q, ec);
0352     boost::asio::detail::throw_error(ec, "resolve");
0353     return r;
0354   }
0355 
0356   /// Perform forward resolution of a query to a list of entries.
0357   /**
0358    * This function is used to resolve host and service names into a list of
0359    * endpoint entries.
0360    *
0361    * @param host A string identifying a location. May be a descriptive name or
0362    * a numeric address string. If an empty string and the passive flag has been
0363    * specified, the resolved endpoints are suitable for local service binding.
0364    * If an empty string and passive is not specified, the resolved endpoints
0365    * will use the loopback address.
0366    *
0367    * @param service A string identifying the requested service. This may be a
0368    * descriptive name or a numeric string corresponding to a port number. May
0369    * be an empty string, in which case all resolved endpoints will have a port
0370    * number of 0.
0371    *
0372    * @param resolve_flags A set of flags that determine how name resolution
0373    * should be performed. The default flags are suitable for communication with
0374    * remote hosts. See the @ref resolver_base documentation for the set of
0375    * available flags.
0376    *
0377    * @param ec Set to indicate what error occurred, if any.
0378    *
0379    * @returns A range object representing the list of endpoint entries. An
0380    * empty range is returned if an error occurs. A successful call to this
0381    * function is guaranteed to return a non-empty range.
0382    *
0383    * @note On POSIX systems, host names may be locally defined in the file
0384    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0385    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0386    * resolution is performed using DNS. Operating systems may use additional
0387    * locations when resolving host names (such as NETBIOS names on Windows).
0388    *
0389    * On POSIX systems, service names are typically defined in the file
0390    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0391    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0392    * may use additional locations when resolving service names.
0393    */
0394   results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0395       BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
0396       boost::system::error_code& ec)
0397   {
0398     basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
0399         static_cast<std::string>(service), resolve_flags);
0400     return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
0401   }
0402 
0403   /// Perform forward resolution of a query to a list of entries.
0404   /**
0405    * This function is used to resolve host and service names into a list of
0406    * endpoint entries.
0407    *
0408    * @param protocol A protocol object, normally representing either the IPv4 or
0409    * IPv6 version of an internet protocol.
0410    *
0411    * @param host A string identifying a location. May be a descriptive name or
0412    * a numeric address string. If an empty string and the passive flag has been
0413    * specified, the resolved endpoints are suitable for local service binding.
0414    * If an empty string and passive is not specified, the resolved endpoints
0415    * will use the loopback address.
0416    *
0417    * @param service A string identifying the requested service. This may be a
0418    * descriptive name or a numeric string corresponding to a port number. May
0419    * be an empty string, in which case all resolved endpoints will have a port
0420    * number of 0.
0421    *
0422    * @returns A range object representing the list of endpoint entries. A
0423    * successful call to this function is guaranteed to return a non-empty
0424    * range.
0425    *
0426    * @throws boost::system::system_error Thrown on failure.
0427    *
0428    * @note On POSIX systems, host names may be locally defined in the file
0429    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0430    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0431    * resolution is performed using DNS. Operating systems may use additional
0432    * locations when resolving host names (such as NETBIOS names on Windows).
0433    *
0434    * On POSIX systems, service names are typically defined in the file
0435    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0436    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0437    * may use additional locations when resolving service names.
0438    */
0439   results_type resolve(const protocol_type& protocol,
0440       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service)
0441   {
0442     return resolve(protocol, host, service, resolver_base::flags());
0443   }
0444 
0445   /// Perform forward resolution of a query to a list of entries.
0446   /**
0447    * This function is used to resolve host and service names into a list of
0448    * endpoint entries.
0449    *
0450    * @param protocol A protocol object, normally representing either the IPv4 or
0451    * IPv6 version of an internet protocol.
0452    *
0453    * @param host A string identifying a location. May be a descriptive name or
0454    * a numeric address string. If an empty string and the passive flag has been
0455    * specified, the resolved endpoints are suitable for local service binding.
0456    * If an empty string and passive is not specified, the resolved endpoints
0457    * will use the loopback address.
0458    *
0459    * @param service A string identifying the requested service. This may be a
0460    * descriptive name or a numeric string corresponding to a port number. May
0461    * be an empty string, in which case all resolved endpoints will have a port
0462    * number of 0.
0463    *
0464    * @param ec Set to indicate what error occurred, if any.
0465    *
0466    * @returns A range object representing the list of endpoint entries. An
0467    * empty range is returned if an error occurs. A successful call to this
0468    * function is guaranteed to return a non-empty range.
0469    *
0470    * @note On POSIX systems, host names may be locally defined in the file
0471    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0472    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0473    * resolution is performed using DNS. Operating systems may use additional
0474    * locations when resolving host names (such as NETBIOS names on Windows).
0475    *
0476    * On POSIX systems, service names are typically defined in the file
0477    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0478    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0479    * may use additional locations when resolving service names.
0480    */
0481   results_type resolve(const protocol_type& protocol,
0482       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
0483       boost::system::error_code& ec)
0484   {
0485     return resolve(protocol, host, service, resolver_base::flags(), ec);
0486   }
0487 
0488   /// Perform forward resolution of a query to a list of entries.
0489   /**
0490    * This function is used to resolve host and service names into a list of
0491    * endpoint entries.
0492    *
0493    * @param protocol A protocol object, normally representing either the IPv4 or
0494    * IPv6 version of an internet protocol.
0495    *
0496    * @param host A string identifying a location. May be a descriptive name or
0497    * a numeric address string. If an empty string and the passive flag has been
0498    * specified, the resolved endpoints are suitable for local service binding.
0499    * If an empty string and passive is not specified, the resolved endpoints
0500    * will use the loopback address.
0501    *
0502    * @param service A string identifying the requested service. This may be a
0503    * descriptive name or a numeric string corresponding to a port number. May
0504    * be an empty string, in which case all resolved endpoints will have a port
0505    * number of 0.
0506    *
0507    * @param resolve_flags A set of flags that determine how name resolution
0508    * should be performed. The default flags are suitable for communication with
0509    * remote hosts. See the @ref resolver_base documentation for the set of
0510    * available flags.
0511    *
0512    * @returns A range object representing the list of endpoint entries. A
0513    * successful call to this function is guaranteed to return a non-empty
0514    * range.
0515    *
0516    * @throws boost::system::system_error Thrown on failure.
0517    *
0518    * @note On POSIX systems, host names may be locally defined in the file
0519    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0520    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0521    * resolution is performed using DNS. Operating systems may use additional
0522    * locations when resolving host names (such as NETBIOS names on Windows).
0523    *
0524    * On POSIX systems, service names are typically defined in the file
0525    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0526    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0527    * may use additional locations when resolving service names.
0528    */
0529   results_type resolve(const protocol_type& protocol,
0530       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
0531       resolver_base::flags resolve_flags)
0532   {
0533     boost::system::error_code ec;
0534     basic_resolver_query<protocol_type> q(
0535         protocol, static_cast<std::string>(host),
0536         static_cast<std::string>(service), resolve_flags);
0537     results_type r = impl_.get_service().resolve(
0538         impl_.get_implementation(), q, ec);
0539     boost::asio::detail::throw_error(ec, "resolve");
0540     return r;
0541   }
0542 
0543   /// Perform forward resolution of a query to a list of entries.
0544   /**
0545    * This function is used to resolve host and service names into a list of
0546    * endpoint entries.
0547    *
0548    * @param protocol A protocol object, normally representing either the IPv4 or
0549    * IPv6 version of an internet protocol.
0550    *
0551    * @param host A string identifying a location. May be a descriptive name or
0552    * a numeric address string. If an empty string and the passive flag has been
0553    * specified, the resolved endpoints are suitable for local service binding.
0554    * If an empty string and passive is not specified, the resolved endpoints
0555    * will use the loopback address.
0556    *
0557    * @param service A string identifying the requested service. This may be a
0558    * descriptive name or a numeric string corresponding to a port number. May
0559    * be an empty string, in which case all resolved endpoints will have a port
0560    * number of 0.
0561    *
0562    * @param resolve_flags A set of flags that determine how name resolution
0563    * should be performed. The default flags are suitable for communication with
0564    * remote hosts. See the @ref resolver_base documentation for the set of
0565    * available flags.
0566    *
0567    * @param ec Set to indicate what error occurred, if any.
0568    *
0569    * @returns A range object representing the list of endpoint entries. An
0570    * empty range is returned if an error occurs. A successful call to this
0571    * function is guaranteed to return a non-empty range.
0572    *
0573    * @note On POSIX systems, host names may be locally defined in the file
0574    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0575    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0576    * resolution is performed using DNS. Operating systems may use additional
0577    * locations when resolving host names (such as NETBIOS names on Windows).
0578    *
0579    * On POSIX systems, service names are typically defined in the file
0580    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0581    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0582    * may use additional locations when resolving service names.
0583    */
0584   results_type resolve(const protocol_type& protocol,
0585       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
0586       resolver_base::flags resolve_flags, boost::system::error_code& ec)
0587   {
0588     basic_resolver_query<protocol_type> q(
0589         protocol, static_cast<std::string>(host),
0590         static_cast<std::string>(service), resolve_flags);
0591     return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
0592   }
0593 
0594   /// Asynchronously perform forward resolution of a query to a list of entries.
0595   /**
0596    * This function is used to resolve host and service names into a list of
0597    * endpoint entries.
0598    *
0599    * @param host A string identifying a location. May be a descriptive name or
0600    * a numeric address string. If an empty string and the passive flag has been
0601    * specified, the resolved endpoints are suitable for local service binding.
0602    * If an empty string and passive is not specified, the resolved endpoints
0603    * will use the loopback address.
0604    *
0605    * @param service A string identifying the requested service. This may be a
0606    * descriptive name or a numeric string corresponding to a port number. May
0607    * be an empty string, in which case all resolved endpoints will have a port
0608    * number of 0.
0609    *
0610    * @param token The @ref completion_token that will be used to produce a
0611    * completion handler, which will be called when the resolve completes.
0612    * Potential completion tokens include @ref use_future, @ref use_awaitable,
0613    * @ref yield_context, or a function object with the correct completion
0614    * signature. The function signature of the completion handler must be:
0615    * @code void handler(
0616    *   const boost::system::error_code& error, // Result of operation.
0617    *   resolver::results_type results // Resolved endpoints as a range.
0618    * ); @endcode
0619    * Regardless of whether the asynchronous operation completes immediately or
0620    * not, the completion handler will not be invoked from within this function.
0621    * On immediate completion, invocation of the handler will be performed in a
0622    * manner equivalent to using boost::asio::async_immediate().
0623    *
0624    * A successful resolve operation is guaranteed to pass a non-empty range to
0625    * the handler.
0626    *
0627    * @par Completion Signature
0628    * @code void(boost::system::error_code, results_type) @endcode
0629    *
0630    * @note On POSIX systems, host names may be locally defined in the file
0631    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0632    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0633    * resolution is performed using DNS. Operating systems may use additional
0634    * locations when resolving host names (such as NETBIOS names on Windows).
0635    *
0636    * On POSIX systems, service names are typically defined in the file
0637    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0638    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0639    * may use additional locations when resolving service names.
0640    */
0641   template <
0642       BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0643         results_type)) ResolveToken = default_completion_token_t<executor_type>>
0644   auto async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0645       BOOST_ASIO_STRING_VIEW_PARAM service,
0646       ResolveToken&& token = default_completion_token_t<executor_type>())
0647     -> decltype(
0648       boost::asio::async_initiate<ResolveToken,
0649         void (boost::system::error_code, results_type)>(
0650           declval<initiate_async_resolve>(), token,
0651           declval<basic_resolver_query<protocol_type>&>()))
0652   {
0653     return async_resolve(host, service, resolver_base::flags(),
0654         static_cast<ResolveToken&&>(token));
0655   }
0656 
0657   /// Asynchronously perform forward resolution of a query to a list of entries.
0658   /**
0659    * This function is used to resolve host and service names into a list of
0660    * endpoint entries. It is an initiating function for an @ref
0661    * asynchronous_operation, and always returns immediately.
0662    *
0663    * @param host A string identifying a location. May be a descriptive name or
0664    * a numeric address string. If an empty string and the passive flag has been
0665    * specified, the resolved endpoints are suitable for local service binding.
0666    * If an empty string and passive is not specified, the resolved endpoints
0667    * will use the loopback address.
0668    *
0669    * @param service A string identifying the requested service. This may be a
0670    * descriptive name or a numeric string corresponding to a port number. May
0671    * be an empty string, in which case all resolved endpoints will have a port
0672    * number of 0.
0673    *
0674    * @param resolve_flags A set of flags that determine how name resolution
0675    * should be performed. The default flags are suitable for communication with
0676    * remote hosts. See the @ref resolver_base documentation for the set of
0677    * available flags.
0678    *
0679    * @param token The @ref completion_token that will be used to produce a
0680    * completion handler, which will be called when the resolve completes.
0681    * Potential completion tokens include @ref use_future, @ref use_awaitable,
0682    * @ref yield_context, or a function object with the correct completion
0683    * signature. The function signature of the completion handler must be:
0684    * @code void handler(
0685    *   const boost::system::error_code& error, // Result of operation.
0686    *   resolver::results_type results // Resolved endpoints as a range.
0687    * ); @endcode
0688    * Regardless of whether the asynchronous operation completes immediately or
0689    * not, the completion handler will not be invoked from within this function.
0690    * On immediate completion, invocation of the handler will be performed in a
0691    * manner equivalent to using boost::asio::async_immediate().
0692    *
0693    * A successful resolve operation is guaranteed to pass a non-empty range to
0694    * the handler.
0695    *
0696    * @par Completion Signature
0697    * @code void(boost::system::error_code, results_type) @endcode
0698    *
0699    * @note On POSIX systems, host names may be locally defined in the file
0700    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0701    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0702    * resolution is performed using DNS. Operating systems may use additional
0703    * locations when resolving host names (such as NETBIOS names on Windows).
0704    *
0705    * On POSIX systems, service names are typically defined in the file
0706    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0707    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0708    * may use additional locations when resolving service names.
0709    */
0710   template <
0711       BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0712         results_type)) ResolveToken = default_completion_token_t<executor_type>>
0713   auto async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
0714       BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
0715       ResolveToken&& token = default_completion_token_t<executor_type>())
0716     -> decltype(
0717       boost::asio::async_initiate<ResolveToken,
0718         void (boost::system::error_code, results_type)>(
0719           declval<initiate_async_resolve>(), token,
0720           declval<basic_resolver_query<protocol_type>&>()))
0721   {
0722     basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
0723         static_cast<std::string>(service), resolve_flags);
0724 
0725     return boost::asio::async_initiate<ResolveToken,
0726       void (boost::system::error_code, results_type)>(
0727         initiate_async_resolve(this), token, q);
0728   }
0729 
0730   /// Asynchronously perform forward resolution of a query to a list of entries.
0731   /**
0732    * This function is used to resolve host and service names into a list of
0733    * endpoint entries. It is an initiating function for an @ref
0734    * asynchronous_operation, and always returns immediately.
0735    *
0736    * @param protocol A protocol object, normally representing either the IPv4 or
0737    * IPv6 version of an internet protocol.
0738    *
0739    * @param host A string identifying a location. May be a descriptive name or
0740    * a numeric address string. If an empty string and the passive flag has been
0741    * specified, the resolved endpoints are suitable for local service binding.
0742    * If an empty string and passive is not specified, the resolved endpoints
0743    * will use the loopback address.
0744    *
0745    * @param service A string identifying the requested service. This may be a
0746    * descriptive name or a numeric string corresponding to a port number. May
0747    * be an empty string, in which case all resolved endpoints will have a port
0748    * number of 0.
0749    *
0750    * @param token The @ref completion_token that will be used to produce a
0751    * completion handler, which will be called when the resolve completes.
0752    * Potential completion tokens include @ref use_future, @ref use_awaitable,
0753    * @ref yield_context, or a function object with the correct completion
0754    * signature. The function signature of the completion handler must be:
0755    * @code void handler(
0756    *   const boost::system::error_code& error, // Result of operation.
0757    *   resolver::results_type results // Resolved endpoints as a range.
0758    * ); @endcode
0759    * Regardless of whether the asynchronous operation completes immediately or
0760    * not, the completion handler will not be invoked from within this function.
0761    * On immediate completion, invocation of the handler will be performed in a
0762    * manner equivalent to using boost::asio::async_immediate().
0763    *
0764    * A successful resolve operation is guaranteed to pass a non-empty range to
0765    * the handler.
0766    *
0767    * @par Completion Signature
0768    * @code void(boost::system::error_code, results_type) @endcode
0769    *
0770    * @note On POSIX systems, host names may be locally defined in the file
0771    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0772    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0773    * resolution is performed using DNS. Operating systems may use additional
0774    * locations when resolving host names (such as NETBIOS names on Windows).
0775    *
0776    * On POSIX systems, service names are typically defined in the file
0777    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0778    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0779    * may use additional locations when resolving service names.
0780    */
0781   template <
0782       BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0783         results_type)) ResolveToken = default_completion_token_t<executor_type>>
0784   auto async_resolve(const protocol_type& protocol,
0785       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
0786       ResolveToken&& token = default_completion_token_t<executor_type>())
0787     -> decltype(
0788       boost::asio::async_initiate<ResolveToken,
0789         void (boost::system::error_code, results_type)>(
0790           declval<initiate_async_resolve>(), token,
0791           declval<basic_resolver_query<protocol_type>&>()))
0792   {
0793     return async_resolve(protocol, host, service, resolver_base::flags(),
0794         static_cast<ResolveToken&&>(token));
0795   }
0796 
0797   /// Asynchronously perform forward resolution of a query to a list of entries.
0798   /**
0799    * This function is used to resolve host and service names into a list of
0800    * endpoint entries. It is an initiating function for an @ref
0801    * asynchronous_operation, and always returns immediately.
0802    *
0803    * @param protocol A protocol object, normally representing either the IPv4 or
0804    * IPv6 version of an internet protocol.
0805    *
0806    * @param host A string identifying a location. May be a descriptive name or
0807    * a numeric address string. If an empty string and the passive flag has been
0808    * specified, the resolved endpoints are suitable for local service binding.
0809    * If an empty string and passive is not specified, the resolved endpoints
0810    * will use the loopback address.
0811    *
0812    * @param service A string identifying the requested service. This may be a
0813    * descriptive name or a numeric string corresponding to a port number. May
0814    * be an empty string, in which case all resolved endpoints will have a port
0815    * number of 0.
0816    *
0817    * @param resolve_flags A set of flags that determine how name resolution
0818    * should be performed. The default flags are suitable for communication with
0819    * remote hosts. See the @ref resolver_base documentation for the set of
0820    * available flags.
0821    *
0822    * @param token The @ref completion_token that will be used to produce a
0823    * completion handler, which will be called when the resolve completes.
0824    * Potential completion tokens include @ref use_future, @ref use_awaitable,
0825    * @ref yield_context, or a function object with the correct completion
0826    * signature. The function signature of the completion handler must be:
0827    * @code void handler(
0828    *   const boost::system::error_code& error, // Result of operation.
0829    *   resolver::results_type results // Resolved endpoints as a range.
0830    * ); @endcode
0831    * Regardless of whether the asynchronous operation completes immediately or
0832    * not, the completion handler will not be invoked from within this function.
0833    * On immediate completion, invocation of the handler will be performed in a
0834    * manner equivalent to using boost::asio::async_immediate().
0835    *
0836    * A successful resolve operation is guaranteed to pass a non-empty range to
0837    * the handler.
0838    *
0839    * @par Completion Signature
0840    * @code void(boost::system::error_code, results_type) @endcode
0841    *
0842    * @note On POSIX systems, host names may be locally defined in the file
0843    * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
0844    * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
0845    * resolution is performed using DNS. Operating systems may use additional
0846    * locations when resolving host names (such as NETBIOS names on Windows).
0847    *
0848    * On POSIX systems, service names are typically defined in the file
0849    * <tt>/etc/services</tt>. On Windows, service names may be found in the file
0850    * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
0851    * may use additional locations when resolving service names.
0852    */
0853   template <
0854       BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0855         results_type)) ResolveToken = default_completion_token_t<executor_type>>
0856   auto async_resolve(const protocol_type& protocol,
0857       BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
0858       resolver_base::flags resolve_flags,
0859       ResolveToken&& token = default_completion_token_t<executor_type>())
0860     -> decltype(
0861       boost::asio::async_initiate<ResolveToken,
0862         void (boost::system::error_code, results_type)>(
0863           declval<initiate_async_resolve>(), token,
0864           declval<basic_resolver_query<protocol_type>&>()))
0865   {
0866     basic_resolver_query<protocol_type> q(
0867         protocol, static_cast<std::string>(host),
0868         static_cast<std::string>(service), resolve_flags);
0869 
0870     return boost::asio::async_initiate<ResolveToken,
0871       void (boost::system::error_code, results_type)>(
0872         initiate_async_resolve(this), token, q);
0873   }
0874 
0875   /// Perform reverse resolution of an endpoint to a list of entries.
0876   /**
0877    * This function is used to resolve an endpoint into a list of endpoint
0878    * entries.
0879    *
0880    * @param e An endpoint object that determines what endpoints will be
0881    * returned.
0882    *
0883    * @returns A range object representing the list of endpoint entries. A
0884    * successful call to this function is guaranteed to return a non-empty
0885    * range.
0886    *
0887    * @throws boost::system::system_error Thrown on failure.
0888    */
0889   results_type resolve(const endpoint_type& e)
0890   {
0891     boost::system::error_code ec;
0892     results_type i = impl_.get_service().resolve(
0893         impl_.get_implementation(), e, ec);
0894     boost::asio::detail::throw_error(ec, "resolve");
0895     return i;
0896   }
0897 
0898   /// Perform reverse resolution of an endpoint to a list of entries.
0899   /**
0900    * This function is used to resolve an endpoint into a list of endpoint
0901    * entries.
0902    *
0903    * @param e An endpoint object that determines what endpoints will be
0904    * returned.
0905    *
0906    * @param ec Set to indicate what error occurred, if any.
0907    *
0908    * @returns A range object representing the list of endpoint entries. An
0909    * empty range is returned if an error occurs. A successful call to this
0910    * function is guaranteed to return a non-empty range.
0911    */
0912   results_type resolve(const endpoint_type& e, boost::system::error_code& ec)
0913   {
0914     return impl_.get_service().resolve(impl_.get_implementation(), e, ec);
0915   }
0916 
0917   /// Asynchronously perform reverse resolution of an endpoint to a list of
0918   /// entries.
0919   /**
0920    * This function is used to asynchronously resolve an endpoint into a list of
0921    * endpoint entries. It is an initiating function for an @ref
0922    * asynchronous_operation, and always returns immediately.
0923    *
0924    * @param e An endpoint object that determines what endpoints will be
0925    * returned.
0926    *
0927    * @param token The @ref completion_token that will be used to produce a
0928    * completion handler, which will be called when the resolve completes.
0929    * Potential completion tokens include @ref use_future, @ref use_awaitable,
0930    * @ref yield_context, or a function object with the correct completion
0931    * signature. The function signature of the completion handler must be:
0932    * @code void handler(
0933    *   const boost::system::error_code& error, // Result of operation.
0934    *   resolver::results_type results // Resolved endpoints as a range.
0935    * ); @endcode
0936    * Regardless of whether the asynchronous operation completes immediately or
0937    * not, the completion handler will not be invoked from within this function.
0938    * On immediate completion, invocation of the handler will be performed in a
0939    * manner equivalent to using boost::asio::async_immediate().
0940    *
0941    * A successful resolve operation is guaranteed to pass a non-empty range to
0942    * the handler.
0943    *
0944    * @par Completion Signature
0945    * @code void(boost::system::error_code, results_type) @endcode
0946    */
0947   template <
0948       BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
0949         results_type)) ResolveToken = default_completion_token_t<executor_type>>
0950   auto async_resolve(const endpoint_type& e,
0951       ResolveToken&& token = default_completion_token_t<executor_type>())
0952     -> decltype(
0953       boost::asio::async_initiate<ResolveToken,
0954         void (boost::system::error_code, results_type)>(
0955           declval<initiate_async_resolve>(), token, e))
0956   {
0957     return boost::asio::async_initiate<ResolveToken,
0958       void (boost::system::error_code, results_type)>(
0959         initiate_async_resolve(this), token, e);
0960   }
0961 
0962 private:
0963   // Disallow copying and assignment.
0964   basic_resolver(const basic_resolver&) = delete;
0965   basic_resolver& operator=(const basic_resolver&) = delete;
0966 
0967   class initiate_async_resolve
0968   {
0969   public:
0970     typedef Executor executor_type;
0971 
0972     explicit initiate_async_resolve(basic_resolver* self)
0973       : self_(self)
0974     {
0975     }
0976 
0977     executor_type get_executor() const noexcept
0978     {
0979       return self_->get_executor();
0980     }
0981 
0982     template <typename ResolveHandler, typename Query>
0983     void operator()(ResolveHandler&& handler,
0984         const Query& q) const
0985     {
0986       // If you get an error on the following line it means that your handler
0987       // does not meet the documented type requirements for a ResolveHandler.
0988       BOOST_ASIO_RESOLVE_HANDLER_CHECK(
0989           ResolveHandler, handler, results_type) type_check;
0990 
0991       boost::asio::detail::non_const_lvalue<ResolveHandler> handler2(handler);
0992       self_->impl_.get_service().async_resolve(
0993           self_->impl_.get_implementation(), q,
0994           handler2.value, self_->impl_.get_executor());
0995     }
0996 
0997   private:
0998     basic_resolver* self_;
0999   };
1000 
1001 # if defined(BOOST_ASIO_WINDOWS_RUNTIME)
1002   boost::asio::detail::io_object_impl<
1003     boost::asio::detail::winrt_resolver_service<InternetProtocol>,
1004     Executor> impl_;
1005 # else
1006   boost::asio::detail::io_object_impl<
1007     boost::asio::detail::resolver_service<InternetProtocol>,
1008     Executor> impl_;
1009 # endif
1010 };
1011 
1012 } // namespace ip
1013 } // namespace asio
1014 } // namespace boost
1015 
1016 #include <boost/asio/detail/pop_options.hpp>
1017 
1018 #endif // BOOST_ASIO_IP_BASIC_RESOLVER_HPP