Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

basic_resolver.hpp 41KB

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