basic_resolver.hpp 49 KB

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