basic_resolver.hpp 46 KB

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