basic_resolver.hpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. //
  2. // ip/basic_resolver.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IP_BASIC_RESOLVER_HPP
  11. #define BOOST_ASIO_IP_BASIC_RESOLVER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <string>
  17. #include <utility>
  18. #include <boost/asio/any_io_executor.hpp>
  19. #include <boost/asio/async_result.hpp>
  20. #include <boost/asio/detail/handler_type_requirements.hpp>
  21. #include <boost/asio/detail/io_object_impl.hpp>
  22. #include <boost/asio/detail/non_const_lvalue.hpp>
  23. #include <boost/asio/detail/string_view.hpp>
  24. #include <boost/asio/detail/throw_error.hpp>
  25. #include <boost/asio/error.hpp>
  26. #include <boost/asio/execution_context.hpp>
  27. #include <boost/asio/ip/basic_resolver_iterator.hpp>
  28. #include <boost/asio/ip/basic_resolver_query.hpp>
  29. #include <boost/asio/ip/basic_resolver_results.hpp>
  30. #include <boost/asio/ip/resolver_base.hpp>
  31. #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  32. # include <boost/asio/detail/winrt_resolver_service.hpp>
  33. #else
  34. # include <boost/asio/detail/resolver_service.hpp>
  35. #endif
  36. #include <boost/asio/detail/push_options.hpp>
  37. namespace boost {
  38. namespace asio {
  39. namespace ip {
  40. #if !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
  41. #define BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL
  42. // Forward declaration with defaulted arguments.
  43. template <typename InternetProtocol, typename Executor = any_io_executor>
  44. class basic_resolver;
  45. #endif // !defined(BOOST_ASIO_IP_BASIC_RESOLVER_FWD_DECL)
  46. /// Provides endpoint resolution functionality.
  47. /**
  48. * The basic_resolver class template provides the ability to resolve a query
  49. * to a list of endpoints.
  50. *
  51. * @par Thread Safety
  52. * @e Distinct @e objects: Safe.@n
  53. * @e Shared @e objects: Unsafe.
  54. */
  55. template <typename InternetProtocol, typename Executor>
  56. class basic_resolver
  57. : public resolver_base
  58. {
  59. private:
  60. class initiate_async_resolve;
  61. public:
  62. /// The type of the executor associated with the object.
  63. typedef Executor executor_type;
  64. /// Rebinds the resolver type to another executor.
  65. template <typename Executor1>
  66. struct rebind_executor
  67. {
  68. /// The resolver type when rebound to the specified executor.
  69. typedef basic_resolver<InternetProtocol, Executor1> other;
  70. };
  71. /// The protocol type.
  72. typedef InternetProtocol protocol_type;
  73. /// The endpoint type.
  74. typedef typename InternetProtocol::endpoint endpoint_type;
  75. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  76. /// (Deprecated.) The query type.
  77. typedef basic_resolver_query<InternetProtocol> query;
  78. /// (Deprecated.) The iterator type.
  79. typedef basic_resolver_iterator<InternetProtocol> iterator;
  80. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  81. /// The results type.
  82. typedef basic_resolver_results<InternetProtocol> results_type;
  83. /// Construct with executor.
  84. /**
  85. * This constructor creates a basic_resolver.
  86. *
  87. * @param ex The I/O executor that the resolver will use, by default, to
  88. * dispatch handlers for any asynchronous operations performed on the
  89. * resolver.
  90. */
  91. explicit basic_resolver(const executor_type& ex)
  92. : impl_(0, ex)
  93. {
  94. }
  95. /// Construct with execution context.
  96. /**
  97. * This constructor creates a basic_resolver.
  98. *
  99. * @param context An execution context which provides the I/O executor that
  100. * the resolver will use, by default, to dispatch handlers for any
  101. * asynchronous operations performed on the resolver.
  102. */
  103. template <typename ExecutionContext>
  104. explicit basic_resolver(ExecutionContext& context,
  105. constraint_t<
  106. is_convertible<ExecutionContext&, execution_context&>::value
  107. > = 0)
  108. : impl_(0, 0, context)
  109. {
  110. }
  111. /// Move-construct a basic_resolver from another.
  112. /**
  113. * This constructor moves a resolver from one object to another.
  114. *
  115. * @param other The other basic_resolver object from which the move will
  116. * occur.
  117. *
  118. * @note Following the move, the moved-from object is in the same state as if
  119. * constructed using the @c basic_resolver(const executor_type&) constructor.
  120. */
  121. basic_resolver(basic_resolver&& other)
  122. : impl_(std::move(other.impl_))
  123. {
  124. }
  125. // All resolvers have access to each other's implementations.
  126. template <typename InternetProtocol1, typename Executor1>
  127. friend class basic_resolver;
  128. /// Move-construct a basic_resolver from another.
  129. /**
  130. * This constructor moves a resolver from one object to another.
  131. *
  132. * @param other The other basic_resolver object from which the move will
  133. * occur.
  134. *
  135. * @note Following the move, the moved-from object is in the same state as if
  136. * constructed using the @c basic_resolver(const executor_type&) constructor.
  137. */
  138. template <typename Executor1>
  139. basic_resolver(basic_resolver<InternetProtocol, Executor1>&& other,
  140. constraint_t<
  141. is_convertible<Executor1, Executor>::value
  142. > = 0)
  143. : impl_(std::move(other.impl_))
  144. {
  145. }
  146. /// Move-assign a basic_resolver from another.
  147. /**
  148. * This assignment operator moves a resolver from one object to another.
  149. * Cancels any outstanding asynchronous operations associated with the target
  150. * object.
  151. *
  152. * @param other The other basic_resolver object from which the move will
  153. * occur.
  154. *
  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.
  157. */
  158. basic_resolver& operator=(basic_resolver&& other)
  159. {
  160. impl_ = std::move(other.impl_);
  161. return *this;
  162. }
  163. /// Move-assign a basic_resolver from another.
  164. /**
  165. * This assignment operator moves a resolver from one object to another.
  166. * Cancels any outstanding asynchronous operations associated with the target
  167. * object.
  168. *
  169. * @param other The other basic_resolver object from which the move will
  170. * occur.
  171. *
  172. * @note Following the move, the moved-from object is in the same state as if
  173. * constructed using the @c basic_resolver(const executor_type&) constructor.
  174. */
  175. template <typename Executor1>
  176. constraint_t<
  177. is_convertible<Executor1, Executor>::value,
  178. basic_resolver&
  179. > operator=(basic_resolver<InternetProtocol, Executor1>&& other)
  180. {
  181. basic_resolver tmp(std::move(other));
  182. impl_ = std::move(tmp.impl_);
  183. return *this;
  184. }
  185. /// Destroys the resolver.
  186. /**
  187. * This function destroys the resolver, cancelling any outstanding
  188. * asynchronous wait operations associated with the resolver as if by calling
  189. * @c cancel.
  190. */
  191. ~basic_resolver()
  192. {
  193. }
  194. /// Get the executor associated with the object.
  195. executor_type get_executor() noexcept
  196. {
  197. return impl_.get_executor();
  198. }
  199. /// Cancel any asynchronous operations that are waiting on the resolver.
  200. /**
  201. * This function forces the completion of any pending asynchronous
  202. * operations on the host resolver. The handler for each cancelled operation
  203. * will be invoked with the boost::asio::error::operation_aborted error code.
  204. */
  205. void cancel()
  206. {
  207. return impl_.get_service().cancel(impl_.get_implementation());
  208. }
  209. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  210. /// (Deprecated: Use overload with separate host and service parameters.)
  211. /// Perform forward resolution of a query to a list of entries.
  212. /**
  213. * This function is used to resolve a query into a list of endpoint entries.
  214. *
  215. * @param q A query object that determines what endpoints will be returned.
  216. *
  217. * @returns A range object representing the list of endpoint entries. A
  218. * successful call to this function is guaranteed to return a non-empty
  219. * range.
  220. *
  221. * @throws boost::system::system_error Thrown on failure.
  222. */
  223. results_type resolve(const query& q)
  224. {
  225. boost::system::error_code ec;
  226. results_type r = impl_.get_service().resolve(
  227. impl_.get_implementation(), q, ec);
  228. boost::asio::detail::throw_error(ec, "resolve");
  229. return r;
  230. }
  231. /// (Deprecated: Use overload with separate host and service parameters.)
  232. /// Perform forward resolution of a query to a list of entries.
  233. /**
  234. * This function is used to resolve a query into a list of endpoint entries.
  235. *
  236. * @param q A query object that determines what endpoints will be returned.
  237. *
  238. * @param ec Set to indicate what error occurred, if any.
  239. *
  240. * @returns A range object representing the list of endpoint entries. An
  241. * empty range is returned if an error occurs. A successful call to this
  242. * function is guaranteed to return a non-empty range.
  243. */
  244. results_type resolve(const query& q, boost::system::error_code& ec)
  245. {
  246. return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
  247. }
  248. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  249. /// Perform forward resolution of a query to a list of entries.
  250. /**
  251. * This function is used to resolve host and service names into a list of
  252. * endpoint entries.
  253. *
  254. * @param host A string identifying a location. May be a descriptive name or
  255. * a numeric address string. If an empty string and the passive flag has been
  256. * specified, the resolved endpoints are suitable for local service binding.
  257. * If an empty string and passive is not specified, the resolved endpoints
  258. * will use the loopback address.
  259. *
  260. * @param service A string identifying the requested service. This may be a
  261. * descriptive name or a numeric string corresponding to a port number. May
  262. * be an empty string, in which case all resolved endpoints will have a port
  263. * number of 0.
  264. *
  265. * @returns A range object representing the list of endpoint entries. A
  266. * successful call to this function is guaranteed to return a non-empty
  267. * range.
  268. *
  269. * @throws boost::system::system_error Thrown on failure.
  270. *
  271. * @note On POSIX systems, host names may be locally defined in the file
  272. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  273. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  274. * resolution is performed using DNS. Operating systems may use additional
  275. * locations when resolving host names (such as NETBIOS names on Windows).
  276. *
  277. * On POSIX systems, service names are typically defined in the file
  278. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  279. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  280. * may use additional locations when resolving service names.
  281. */
  282. results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  283. BOOST_ASIO_STRING_VIEW_PARAM service)
  284. {
  285. return resolve(host, service, resolver_base::flags());
  286. }
  287. /// Perform forward resolution of a query to a list of entries.
  288. /**
  289. * This function is used to resolve host and service names into a list of
  290. * endpoint entries.
  291. *
  292. * @param host A string identifying a location. May be a descriptive name or
  293. * a numeric address string. If an empty string and the passive flag has been
  294. * specified, the resolved endpoints are suitable for local service binding.
  295. * If an empty string and passive is not specified, the resolved endpoints
  296. * will use the loopback address.
  297. *
  298. * @param service A string identifying the requested service. This may be a
  299. * descriptive name or a numeric string corresponding to a port number. May
  300. * be an empty string, in which case all resolved endpoints will have a port
  301. * number of 0.
  302. *
  303. * @param ec Set to indicate what error occurred, if any.
  304. *
  305. * @returns A range object representing the list of endpoint entries. An
  306. * empty range is returned if an error occurs. A successful call to this
  307. * function is guaranteed to return a non-empty range.
  308. *
  309. * @note On POSIX systems, host names may be locally defined in the file
  310. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  311. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  312. * resolution is performed using DNS. Operating systems may use additional
  313. * locations when resolving host names (such as NETBIOS names on Windows).
  314. *
  315. * On POSIX systems, service names are typically defined in the file
  316. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  317. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  318. * may use additional locations when resolving service names.
  319. */
  320. results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  321. BOOST_ASIO_STRING_VIEW_PARAM service, boost::system::error_code& ec)
  322. {
  323. return resolve(host, service, resolver_base::flags(), ec);
  324. }
  325. /// Perform forward resolution of a query to a list of entries.
  326. /**
  327. * This function is used to resolve host and service names into a list of
  328. * endpoint entries.
  329. *
  330. * @param host A string identifying a location. May be a descriptive name or
  331. * a numeric address string. If an empty string and the passive flag has been
  332. * specified, the resolved endpoints are suitable for local service binding.
  333. * If an empty string and passive is not specified, the resolved endpoints
  334. * will use the loopback address.
  335. *
  336. * @param service A string identifying the requested service. This may be a
  337. * descriptive name or a numeric string corresponding to a port number. May
  338. * be an empty string, in which case all resolved endpoints will have a port
  339. * number of 0.
  340. *
  341. * @param resolve_flags A set of flags that determine how name resolution
  342. * should be performed. The default flags are suitable for communication with
  343. * remote hosts. See the @ref resolver_base documentation for the set of
  344. * available flags.
  345. *
  346. * @returns A range object representing the list of endpoint entries. A
  347. * successful call to this function is guaranteed to return a non-empty
  348. * range.
  349. *
  350. * @throws boost::system::system_error Thrown on failure.
  351. *
  352. * @note On POSIX systems, host names may be locally defined in the file
  353. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  354. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  355. * resolution is performed using DNS. Operating systems may use additional
  356. * locations when resolving host names (such as NETBIOS names on Windows).
  357. *
  358. * On POSIX systems, service names are typically defined in the file
  359. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  360. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  361. * may use additional locations when resolving service names.
  362. */
  363. results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  364. BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags)
  365. {
  366. boost::system::error_code ec;
  367. basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
  368. static_cast<std::string>(service), resolve_flags);
  369. results_type r = impl_.get_service().resolve(
  370. impl_.get_implementation(), q, ec);
  371. boost::asio::detail::throw_error(ec, "resolve");
  372. return r;
  373. }
  374. /// Perform forward resolution of a query to a list of entries.
  375. /**
  376. * This function is used to resolve host and service names into a list of
  377. * endpoint entries.
  378. *
  379. * @param host A string identifying a location. May be a descriptive name or
  380. * a numeric address string. If an empty string and the passive flag has been
  381. * specified, the resolved endpoints are suitable for local service binding.
  382. * If an empty string and passive is not specified, the resolved endpoints
  383. * will use the loopback address.
  384. *
  385. * @param service A string identifying the requested service. This may be a
  386. * descriptive name or a numeric string corresponding to a port number. May
  387. * be an empty string, in which case all resolved endpoints will have a port
  388. * number of 0.
  389. *
  390. * @param resolve_flags A set of flags that determine how name resolution
  391. * should be performed. The default flags are suitable for communication with
  392. * remote hosts. See the @ref resolver_base documentation for the set of
  393. * available flags.
  394. *
  395. * @param ec Set to indicate what error occurred, if any.
  396. *
  397. * @returns A range object representing the list of endpoint entries. An
  398. * empty range is returned if an error occurs. A successful call to this
  399. * function is guaranteed to return a non-empty range.
  400. *
  401. * @note On POSIX systems, host names may be locally defined in the file
  402. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  403. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  404. * resolution is performed using DNS. Operating systems may use additional
  405. * locations when resolving host names (such as NETBIOS names on Windows).
  406. *
  407. * On POSIX systems, service names are typically defined in the file
  408. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  409. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  410. * may use additional locations when resolving service names.
  411. */
  412. results_type resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  413. BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
  414. boost::system::error_code& ec)
  415. {
  416. basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
  417. static_cast<std::string>(service), resolve_flags);
  418. return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
  419. }
  420. /// Perform forward resolution of a query to a list of entries.
  421. /**
  422. * This function is used to resolve host and service names into a list of
  423. * endpoint entries.
  424. *
  425. * @param protocol A protocol object, normally representing either the IPv4 or
  426. * IPv6 version of an internet protocol.
  427. *
  428. * @param host A string identifying a location. May be a descriptive name or
  429. * a numeric address string. If an empty string and the passive flag has been
  430. * specified, the resolved endpoints are suitable for local service binding.
  431. * If an empty string and passive is not specified, the resolved endpoints
  432. * will use the loopback address.
  433. *
  434. * @param service A string identifying the requested service. This may be a
  435. * descriptive name or a numeric string corresponding to a port number. May
  436. * be an empty string, in which case all resolved endpoints will have a port
  437. * number of 0.
  438. *
  439. * @returns A range object representing the list of endpoint entries. A
  440. * successful call to this function is guaranteed to return a non-empty
  441. * range.
  442. *
  443. * @throws boost::system::system_error Thrown on failure.
  444. *
  445. * @note On POSIX systems, host names may be locally defined in the file
  446. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  447. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  448. * resolution is performed using DNS. Operating systems may use additional
  449. * locations when resolving host names (such as NETBIOS names on Windows).
  450. *
  451. * On POSIX systems, service names are typically defined in the file
  452. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  453. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  454. * may use additional locations when resolving service names.
  455. */
  456. results_type resolve(const protocol_type& protocol,
  457. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service)
  458. {
  459. return resolve(protocol, host, service, resolver_base::flags());
  460. }
  461. /// Perform forward resolution of a query to a list of entries.
  462. /**
  463. * This function is used to resolve host and service names into a list of
  464. * endpoint entries.
  465. *
  466. * @param protocol A protocol object, normally representing either the IPv4 or
  467. * IPv6 version of an internet protocol.
  468. *
  469. * @param host A string identifying a location. May be a descriptive name or
  470. * a numeric address string. If an empty string and the passive flag has been
  471. * specified, the resolved endpoints are suitable for local service binding.
  472. * If an empty string and passive is not specified, the resolved endpoints
  473. * will use the loopback address.
  474. *
  475. * @param service A string identifying the requested service. This may be a
  476. * descriptive name or a numeric string corresponding to a port number. May
  477. * be an empty string, in which case all resolved endpoints will have a port
  478. * number of 0.
  479. *
  480. * @param ec Set to indicate what error occurred, if any.
  481. *
  482. * @returns A range object representing the list of endpoint entries. An
  483. * empty range is returned if an error occurs. A successful call to this
  484. * function is guaranteed to return a non-empty range.
  485. *
  486. * @note On POSIX systems, host names may be locally defined in the file
  487. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  488. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  489. * resolution is performed using DNS. Operating systems may use additional
  490. * locations when resolving host names (such as NETBIOS names on Windows).
  491. *
  492. * On POSIX systems, service names are typically defined in the file
  493. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  494. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  495. * may use additional locations when resolving service names.
  496. */
  497. results_type resolve(const protocol_type& protocol,
  498. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
  499. boost::system::error_code& ec)
  500. {
  501. return resolve(protocol, host, service, resolver_base::flags(), ec);
  502. }
  503. /// Perform forward resolution of a query to a list of entries.
  504. /**
  505. * This function is used to resolve host and service names into a list of
  506. * endpoint entries.
  507. *
  508. * @param protocol A protocol object, normally representing either the IPv4 or
  509. * IPv6 version of an internet protocol.
  510. *
  511. * @param host A string identifying a location. May be a descriptive name or
  512. * a numeric address string. If an empty string and the passive flag has been
  513. * specified, the resolved endpoints are suitable for local service binding.
  514. * If an empty string and passive is not specified, the resolved endpoints
  515. * will use the loopback address.
  516. *
  517. * @param service A string identifying the requested service. This may be a
  518. * descriptive name or a numeric string corresponding to a port number. May
  519. * be an empty string, in which case all resolved endpoints will have a port
  520. * number of 0.
  521. *
  522. * @param resolve_flags A set of flags that determine how name resolution
  523. * should be performed. The default flags are suitable for communication with
  524. * remote hosts. See the @ref resolver_base documentation for the set of
  525. * available flags.
  526. *
  527. * @returns A range object representing the list of endpoint entries. A
  528. * successful call to this function is guaranteed to return a non-empty
  529. * range.
  530. *
  531. * @throws boost::system::system_error Thrown on failure.
  532. *
  533. * @note On POSIX systems, host names may be locally defined in the file
  534. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  535. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  536. * resolution is performed using DNS. Operating systems may use additional
  537. * locations when resolving host names (such as NETBIOS names on Windows).
  538. *
  539. * On POSIX systems, service names are typically defined in the file
  540. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  541. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  542. * may use additional locations when resolving service names.
  543. */
  544. results_type resolve(const protocol_type& protocol,
  545. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
  546. resolver_base::flags resolve_flags)
  547. {
  548. boost::system::error_code ec;
  549. basic_resolver_query<protocol_type> q(
  550. protocol, static_cast<std::string>(host),
  551. static_cast<std::string>(service), resolve_flags);
  552. results_type r = impl_.get_service().resolve(
  553. impl_.get_implementation(), q, ec);
  554. boost::asio::detail::throw_error(ec, "resolve");
  555. return r;
  556. }
  557. /// Perform forward resolution of a query to a list of entries.
  558. /**
  559. * This function is used to resolve host and service names into a list of
  560. * endpoint entries.
  561. *
  562. * @param protocol A protocol object, normally representing either the IPv4 or
  563. * IPv6 version of an internet protocol.
  564. *
  565. * @param host A string identifying a location. May be a descriptive name or
  566. * a numeric address string. If an empty string and the passive flag has been
  567. * specified, the resolved endpoints are suitable for local service binding.
  568. * If an empty string and passive is not specified, the resolved endpoints
  569. * will use the loopback address.
  570. *
  571. * @param service A string identifying the requested service. This may be a
  572. * descriptive name or a numeric string corresponding to a port number. May
  573. * be an empty string, in which case all resolved endpoints will have a port
  574. * number of 0.
  575. *
  576. * @param resolve_flags A set of flags that determine how name resolution
  577. * should be performed. The default flags are suitable for communication with
  578. * remote hosts. See the @ref resolver_base documentation for the set of
  579. * available flags.
  580. *
  581. * @param ec Set to indicate what error occurred, if any.
  582. *
  583. * @returns A range object representing the list of endpoint entries. An
  584. * empty range is returned if an error occurs. A successful call to this
  585. * function is guaranteed to return a non-empty range.
  586. *
  587. * @note On POSIX systems, host names may be locally defined in the file
  588. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  589. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  590. * resolution is performed using DNS. Operating systems may use additional
  591. * locations when resolving host names (such as NETBIOS names on Windows).
  592. *
  593. * On POSIX systems, service names are typically defined in the file
  594. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  595. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  596. * may use additional locations when resolving service names.
  597. */
  598. results_type resolve(const protocol_type& protocol,
  599. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
  600. resolver_base::flags resolve_flags, boost::system::error_code& ec)
  601. {
  602. basic_resolver_query<protocol_type> q(
  603. protocol, static_cast<std::string>(host),
  604. static_cast<std::string>(service), resolve_flags);
  605. return impl_.get_service().resolve(impl_.get_implementation(), q, ec);
  606. }
  607. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  608. /// (Deprecated: Use overload with separate host and service parameters.)
  609. /// Asynchronously perform forward resolution of a query to a list of entries.
  610. /**
  611. * This function is used to asynchronously resolve a query into a list of
  612. * endpoint entries. It is an initiating function for an @ref
  613. * asynchronous_operation, and always returns immediately.
  614. *
  615. * @param q A query object that determines what endpoints will be returned.
  616. *
  617. * @param token The @ref completion_token that will be used to produce a
  618. * completion handler, which will be called when the resolve completes.
  619. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  620. * @ref yield_context, or a function object with the correct completion
  621. * signature. The function signature of the completion handler must be:
  622. * @code void handler(
  623. * const boost::system::error_code& error, // Result of operation.
  624. * resolver::results_type results // Resolved endpoints as a range.
  625. * ); @endcode
  626. * Regardless of whether the asynchronous operation completes immediately or
  627. * not, the completion handler will not be invoked from within this function.
  628. * On immediate completion, invocation of the handler will be performed in a
  629. * manner equivalent to using boost::asio::async_immediate().
  630. *
  631. * A successful resolve operation is guaranteed to pass a non-empty range to
  632. * the handler.
  633. *
  634. * @par Completion Signature
  635. * @code void(boost::system::error_code, results_type) @endcode
  636. */
  637. template <
  638. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  639. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  640. auto async_resolve(const query& q,
  641. ResolveToken&& token = default_completion_token_t<executor_type>())
  642. -> decltype(
  643. boost::asio::async_initiate<ResolveToken,
  644. void (boost::system::error_code, results_type)>(
  645. declval<initiate_async_resolve>(), token, q))
  646. {
  647. return boost::asio::async_initiate<ResolveToken,
  648. void (boost::system::error_code, results_type)>(
  649. initiate_async_resolve(this), token, q);
  650. }
  651. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  652. /// Asynchronously perform forward resolution of a query to a list of entries.
  653. /**
  654. * This function is used to resolve host and service names into a list of
  655. * endpoint entries.
  656. *
  657. * @param host A string identifying a location. May be a descriptive name or
  658. * a numeric address string. If an empty string and the passive flag has been
  659. * specified, the resolved endpoints are suitable for local service binding.
  660. * If an empty string and passive is not specified, the resolved endpoints
  661. * will use the loopback address.
  662. *
  663. * @param service A string identifying the requested service. This may be a
  664. * descriptive name or a numeric string corresponding to a port number. May
  665. * be an empty string, in which case all resolved endpoints will have a port
  666. * number of 0.
  667. *
  668. * @param token The @ref completion_token that will be used to produce a
  669. * completion handler, which will be called when the resolve completes.
  670. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  671. * @ref yield_context, or a function object with the correct completion
  672. * signature. The function signature of the completion handler must be:
  673. * @code void handler(
  674. * const boost::system::error_code& error, // Result of operation.
  675. * resolver::results_type results // Resolved endpoints as a range.
  676. * ); @endcode
  677. * Regardless of whether the asynchronous operation completes immediately or
  678. * not, the completion handler will not be invoked from within this function.
  679. * On immediate completion, invocation of the handler will be performed in a
  680. * manner equivalent to using boost::asio::async_immediate().
  681. *
  682. * A successful resolve operation is guaranteed to pass a non-empty range to
  683. * the handler.
  684. *
  685. * @par Completion Signature
  686. * @code void(boost::system::error_code, results_type) @endcode
  687. *
  688. * @note On POSIX systems, host names may be locally defined in the file
  689. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  690. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  691. * resolution is performed using DNS. Operating systems may use additional
  692. * locations when resolving host names (such as NETBIOS names on Windows).
  693. *
  694. * On POSIX systems, service names are typically defined in the file
  695. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  696. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  697. * may use additional locations when resolving service names.
  698. */
  699. template <
  700. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  701. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  702. auto async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  703. BOOST_ASIO_STRING_VIEW_PARAM service,
  704. ResolveToken&& token = default_completion_token_t<executor_type>())
  705. -> decltype(
  706. boost::asio::async_initiate<ResolveToken,
  707. void (boost::system::error_code, results_type)>(
  708. declval<initiate_async_resolve>(), token,
  709. declval<basic_resolver_query<protocol_type>&>()))
  710. {
  711. return async_resolve(host, service, resolver_base::flags(),
  712. static_cast<ResolveToken&&>(token));
  713. }
  714. /// Asynchronously perform forward resolution of a query to a list of entries.
  715. /**
  716. * This function is used to resolve host and service names into a list of
  717. * endpoint entries. It is an initiating function for an @ref
  718. * asynchronous_operation, and always returns immediately.
  719. *
  720. * @param host A string identifying a location. May be a descriptive name or
  721. * a numeric address string. If an empty string and the passive flag has been
  722. * specified, the resolved endpoints are suitable for local service binding.
  723. * If an empty string and passive is not specified, the resolved endpoints
  724. * will use the loopback address.
  725. *
  726. * @param service A string identifying the requested service. This may be a
  727. * descriptive name or a numeric string corresponding to a port number. May
  728. * be an empty string, in which case all resolved endpoints will have a port
  729. * number of 0.
  730. *
  731. * @param resolve_flags A set of flags that determine how name resolution
  732. * should be performed. The default flags are suitable for communication with
  733. * remote hosts. See the @ref resolver_base documentation for the set of
  734. * available flags.
  735. *
  736. * @param token The @ref completion_token that will be used to produce a
  737. * completion handler, which will be called when the resolve completes.
  738. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  739. * @ref yield_context, or a function object with the correct completion
  740. * signature. The function signature of the completion handler must be:
  741. * @code void handler(
  742. * const boost::system::error_code& error, // Result of operation.
  743. * resolver::results_type results // Resolved endpoints as a range.
  744. * ); @endcode
  745. * Regardless of whether the asynchronous operation completes immediately or
  746. * not, the completion handler will not be invoked from within this function.
  747. * On immediate completion, invocation of the handler will be performed in a
  748. * manner equivalent to using boost::asio::async_immediate().
  749. *
  750. * A successful resolve operation is guaranteed to pass a non-empty range to
  751. * the handler.
  752. *
  753. * @par Completion Signature
  754. * @code void(boost::system::error_code, results_type) @endcode
  755. *
  756. * @note On POSIX systems, host names may be locally defined in the file
  757. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  758. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  759. * resolution is performed using DNS. Operating systems may use additional
  760. * locations when resolving host names (such as NETBIOS names on Windows).
  761. *
  762. * On POSIX systems, service names are typically defined in the file
  763. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  764. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  765. * may use additional locations when resolving service names.
  766. */
  767. template <
  768. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  769. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  770. auto async_resolve(BOOST_ASIO_STRING_VIEW_PARAM host,
  771. BOOST_ASIO_STRING_VIEW_PARAM service, resolver_base::flags resolve_flags,
  772. ResolveToken&& token = default_completion_token_t<executor_type>())
  773. -> decltype(
  774. boost::asio::async_initiate<ResolveToken,
  775. void (boost::system::error_code, results_type)>(
  776. declval<initiate_async_resolve>(), token,
  777. declval<basic_resolver_query<protocol_type>&>()))
  778. {
  779. basic_resolver_query<protocol_type> q(static_cast<std::string>(host),
  780. static_cast<std::string>(service), resolve_flags);
  781. return boost::asio::async_initiate<ResolveToken,
  782. void (boost::system::error_code, results_type)>(
  783. initiate_async_resolve(this), token, q);
  784. }
  785. /// Asynchronously perform forward resolution of a query to a list of entries.
  786. /**
  787. * This function is used to resolve host and service names into a list of
  788. * endpoint entries. It is an initiating function for an @ref
  789. * asynchronous_operation, and always returns immediately.
  790. *
  791. * @param protocol A protocol object, normally representing either the IPv4 or
  792. * IPv6 version of an internet protocol.
  793. *
  794. * @param host A string identifying a location. May be a descriptive name or
  795. * a numeric address string. If an empty string and the passive flag has been
  796. * specified, the resolved endpoints are suitable for local service binding.
  797. * If an empty string and passive is not specified, the resolved endpoints
  798. * will use the loopback address.
  799. *
  800. * @param service A string identifying the requested service. This may be a
  801. * descriptive name or a numeric string corresponding to a port number. May
  802. * be an empty string, in which case all resolved endpoints will have a port
  803. * number of 0.
  804. *
  805. * @param token The @ref completion_token that will be used to produce a
  806. * completion handler, which will be called when the resolve completes.
  807. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  808. * @ref yield_context, or a function object with the correct completion
  809. * signature. The function signature of the completion handler must be:
  810. * @code void handler(
  811. * const boost::system::error_code& error, // Result of operation.
  812. * resolver::results_type results // Resolved endpoints as a range.
  813. * ); @endcode
  814. * Regardless of whether the asynchronous operation completes immediately or
  815. * not, the completion handler will not be invoked from within this function.
  816. * On immediate completion, invocation of the handler will be performed in a
  817. * manner equivalent to using boost::asio::async_immediate().
  818. *
  819. * A successful resolve operation is guaranteed to pass a non-empty range to
  820. * the handler.
  821. *
  822. * @par Completion Signature
  823. * @code void(boost::system::error_code, results_type) @endcode
  824. *
  825. * @note On POSIX systems, host names may be locally defined in the file
  826. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  827. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  828. * resolution is performed using DNS. Operating systems may use additional
  829. * locations when resolving host names (such as NETBIOS names on Windows).
  830. *
  831. * On POSIX systems, service names are typically defined in the file
  832. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  833. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  834. * may use additional locations when resolving service names.
  835. */
  836. template <
  837. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  838. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  839. auto async_resolve(const protocol_type& protocol,
  840. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
  841. ResolveToken&& token = default_completion_token_t<executor_type>())
  842. -> decltype(
  843. boost::asio::async_initiate<ResolveToken,
  844. void (boost::system::error_code, results_type)>(
  845. declval<initiate_async_resolve>(), token,
  846. declval<basic_resolver_query<protocol_type>&>()))
  847. {
  848. return async_resolve(protocol, host, service, resolver_base::flags(),
  849. static_cast<ResolveToken&&>(token));
  850. }
  851. /// Asynchronously perform forward resolution of a query to a list of entries.
  852. /**
  853. * This function is used to resolve host and service names into a list of
  854. * endpoint entries. It is an initiating function for an @ref
  855. * asynchronous_operation, and always returns immediately.
  856. *
  857. * @param protocol A protocol object, normally representing either the IPv4 or
  858. * IPv6 version of an internet protocol.
  859. *
  860. * @param host A string identifying a location. May be a descriptive name or
  861. * a numeric address string. If an empty string and the passive flag has been
  862. * specified, the resolved endpoints are suitable for local service binding.
  863. * If an empty string and passive is not specified, the resolved endpoints
  864. * will use the loopback address.
  865. *
  866. * @param service A string identifying the requested service. This may be a
  867. * descriptive name or a numeric string corresponding to a port number. May
  868. * be an empty string, in which case all resolved endpoints will have a port
  869. * number of 0.
  870. *
  871. * @param resolve_flags A set of flags that determine how name resolution
  872. * should be performed. The default flags are suitable for communication with
  873. * remote hosts. See the @ref resolver_base documentation for the set of
  874. * available flags.
  875. *
  876. * @param token The @ref completion_token that will be used to produce a
  877. * completion handler, which will be called when the resolve completes.
  878. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  879. * @ref yield_context, or a function object with the correct completion
  880. * signature. The function signature of the completion handler must be:
  881. * @code void handler(
  882. * const boost::system::error_code& error, // Result of operation.
  883. * resolver::results_type results // Resolved endpoints as a range.
  884. * ); @endcode
  885. * Regardless of whether the asynchronous operation completes immediately or
  886. * not, the completion handler will not be invoked from within this function.
  887. * On immediate completion, invocation of the handler will be performed in a
  888. * manner equivalent to using boost::asio::async_immediate().
  889. *
  890. * A successful resolve operation is guaranteed to pass a non-empty range to
  891. * the handler.
  892. *
  893. * @par Completion Signature
  894. * @code void(boost::system::error_code, results_type) @endcode
  895. *
  896. * @note On POSIX systems, host names may be locally defined in the file
  897. * <tt>/etc/hosts</tt>. On Windows, host names may be defined in the file
  898. * <tt>c:\\windows\\system32\\drivers\\etc\\hosts</tt>. Remote host name
  899. * resolution is performed using DNS. Operating systems may use additional
  900. * locations when resolving host names (such as NETBIOS names on Windows).
  901. *
  902. * On POSIX systems, service names are typically defined in the file
  903. * <tt>/etc/services</tt>. On Windows, service names may be found in the file
  904. * <tt>c:\\windows\\system32\\drivers\\etc\\services</tt>. Operating systems
  905. * may use additional locations when resolving service names.
  906. */
  907. template <
  908. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  909. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  910. auto async_resolve(const protocol_type& protocol,
  911. BOOST_ASIO_STRING_VIEW_PARAM host, BOOST_ASIO_STRING_VIEW_PARAM service,
  912. resolver_base::flags resolve_flags,
  913. ResolveToken&& token = default_completion_token_t<executor_type>())
  914. -> decltype(
  915. boost::asio::async_initiate<ResolveToken,
  916. void (boost::system::error_code, results_type)>(
  917. declval<initiate_async_resolve>(), token,
  918. declval<basic_resolver_query<protocol_type>&>()))
  919. {
  920. basic_resolver_query<protocol_type> q(
  921. protocol, static_cast<std::string>(host),
  922. static_cast<std::string>(service), resolve_flags);
  923. return boost::asio::async_initiate<ResolveToken,
  924. void (boost::system::error_code, results_type)>(
  925. initiate_async_resolve(this), token, q);
  926. }
  927. /// Perform reverse resolution of an endpoint to a list of entries.
  928. /**
  929. * This function is used to resolve an endpoint into a list of endpoint
  930. * entries.
  931. *
  932. * @param e An endpoint object that determines what endpoints will be
  933. * returned.
  934. *
  935. * @returns A range object representing the list of endpoint entries. A
  936. * successful call to this function is guaranteed to return a non-empty
  937. * range.
  938. *
  939. * @throws boost::system::system_error Thrown on failure.
  940. */
  941. results_type resolve(const endpoint_type& e)
  942. {
  943. boost::system::error_code ec;
  944. results_type i = impl_.get_service().resolve(
  945. impl_.get_implementation(), e, ec);
  946. boost::asio::detail::throw_error(ec, "resolve");
  947. return i;
  948. }
  949. /// Perform reverse resolution of an endpoint to a list of entries.
  950. /**
  951. * This function is used to resolve an endpoint into a list of endpoint
  952. * entries.
  953. *
  954. * @param e An endpoint object that determines what endpoints will be
  955. * returned.
  956. *
  957. * @param ec Set to indicate what error occurred, if any.
  958. *
  959. * @returns A range object representing the list of endpoint entries. An
  960. * empty range is returned if an error occurs. A successful call to this
  961. * function is guaranteed to return a non-empty range.
  962. */
  963. results_type resolve(const endpoint_type& e, boost::system::error_code& ec)
  964. {
  965. return impl_.get_service().resolve(impl_.get_implementation(), e, ec);
  966. }
  967. /// Asynchronously perform reverse resolution of an endpoint to a list of
  968. /// entries.
  969. /**
  970. * This function is used to asynchronously resolve an endpoint into a list of
  971. * endpoint entries. It is an initiating function for an @ref
  972. * asynchronous_operation, and always returns immediately.
  973. *
  974. * @param e An endpoint object that determines what endpoints will be
  975. * returned.
  976. *
  977. * @param token The @ref completion_token that will be used to produce a
  978. * completion handler, which will be called when the resolve completes.
  979. * Potential completion tokens include @ref use_future, @ref use_awaitable,
  980. * @ref yield_context, or a function object with the correct completion
  981. * signature. The function signature of the completion handler must be:
  982. * @code void handler(
  983. * const boost::system::error_code& error, // Result of operation.
  984. * resolver::results_type results // Resolved endpoints as a range.
  985. * ); @endcode
  986. * Regardless of whether the asynchronous operation completes immediately or
  987. * not, the completion handler will not be invoked from within this function.
  988. * On immediate completion, invocation of the handler will be performed in a
  989. * manner equivalent to using boost::asio::async_immediate().
  990. *
  991. * A successful resolve operation is guaranteed to pass a non-empty range to
  992. * the handler.
  993. *
  994. * @par Completion Signature
  995. * @code void(boost::system::error_code, results_type) @endcode
  996. */
  997. template <
  998. BOOST_ASIO_COMPLETION_TOKEN_FOR(void (boost::system::error_code,
  999. results_type)) ResolveToken = default_completion_token_t<executor_type>>
  1000. auto async_resolve(const endpoint_type& e,
  1001. ResolveToken&& token = default_completion_token_t<executor_type>())
  1002. -> decltype(
  1003. boost::asio::async_initiate<ResolveToken,
  1004. void (boost::system::error_code, results_type)>(
  1005. declval<initiate_async_resolve>(), token, e))
  1006. {
  1007. return boost::asio::async_initiate<ResolveToken,
  1008. void (boost::system::error_code, results_type)>(
  1009. initiate_async_resolve(this), token, e);
  1010. }
  1011. private:
  1012. // Disallow copying and assignment.
  1013. basic_resolver(const basic_resolver&) = delete;
  1014. basic_resolver& operator=(const basic_resolver&) = delete;
  1015. class initiate_async_resolve
  1016. {
  1017. public:
  1018. typedef Executor executor_type;
  1019. explicit initiate_async_resolve(basic_resolver* self)
  1020. : self_(self)
  1021. {
  1022. }
  1023. executor_type get_executor() const noexcept
  1024. {
  1025. return self_->get_executor();
  1026. }
  1027. template <typename ResolveHandler, typename Query>
  1028. void operator()(ResolveHandler&& handler,
  1029. const Query& q) const
  1030. {
  1031. // If you get an error on the following line it means that your handler
  1032. // does not meet the documented type requirements for a ResolveHandler.
  1033. BOOST_ASIO_RESOLVE_HANDLER_CHECK(
  1034. ResolveHandler, handler, results_type) type_check;
  1035. boost::asio::detail::non_const_lvalue<ResolveHandler> handler2(handler);
  1036. self_->impl_.get_service().async_resolve(
  1037. self_->impl_.get_implementation(), q,
  1038. handler2.value, self_->impl_.get_executor());
  1039. }
  1040. private:
  1041. basic_resolver* self_;
  1042. };
  1043. # if defined(BOOST_ASIO_WINDOWS_RUNTIME)
  1044. boost::asio::detail::io_object_impl<
  1045. boost::asio::detail::winrt_resolver_service<InternetProtocol>,
  1046. Executor> impl_;
  1047. # else
  1048. boost::asio::detail::io_object_impl<
  1049. boost::asio::detail::resolver_service<InternetProtocol>,
  1050. Executor> impl_;
  1051. # endif
  1052. };
  1053. } // namespace ip
  1054. } // namespace asio
  1055. } // namespace boost
  1056. #include <boost/asio/detail/pop_options.hpp>
  1057. #endif // BOOST_ASIO_IP_BASIC_RESOLVER_HPP