ResolveHandler.qbk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. [/
  2. / Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:ResolveHandler Resolve handler requirements]
  8. A resolve handler must meet the requirements for a [link boost_asio.reference.Handler
  9. handler]. A value `h` of a resolve handler class should work correctly in the
  10. expression `h(ec, r)`, where `ec` is an lvalue of type `const error_code` and
  11. `r` is an lvalue of type `const ip::basic_resolver_results<InternetProtocol>`.
  12. `InternetProtocol` is the template parameter of the [link
  13. boost_asio.reference.ip__basic_resolver `ip::basic_resolver<>`] which is used to
  14. initiate the asynchronous operation.
  15. [heading Examples]
  16. A free function as a resolve handler:
  17. void resolve_handler(
  18. const boost::system::error_code& ec,
  19. boost::asio::ip::tcp::resolver::results_type results)
  20. {
  21. ...
  22. }
  23. A resolve handler function object:
  24. struct resolve_handler
  25. {
  26. ...
  27. void operator()(
  28. const boost::system::error_code& ec,
  29. boost::asio::ip::tcp::resolver::results_type results)
  30. {
  31. ...
  32. }
  33. ...
  34. };
  35. A lambda as a resolve handler:
  36. resolver.async_resolve(...,
  37. [](const boost::system::error_code& ec,
  38. boost::asio::ip::tcp::resolver::results_type results)
  39. {
  40. ...
  41. });
  42. A non-static class member function adapted to a resolve handler using
  43. `std::bind()`:
  44. void my_class::resolve_handler(
  45. const boost::system::error_code& ec,
  46. boost::asio::ip::tcp::resolver::results_type results)
  47. {
  48. ...
  49. }
  50. ...
  51. resolver.async_resolve(...,
  52. std::bind(&my_class::resolve_handler,
  53. this, std::placeholders::_1,
  54. std::placeholders::_2));
  55. A non-static class member function adapted to a resolve handler using
  56. `boost::bind()`:
  57. void my_class::resolve_handler(
  58. const boost::system::error_code& ec,
  59. boost::asio::ip::tcp::resolver::results_type results)
  60. {
  61. ...
  62. }
  63. ...
  64. resolver.async_resolve(...,
  65. boost::bind(&my_class::resolve_handler,
  66. this, boost::asio::placeholders::error,
  67. boost::asio::placeholders::results));
  68. [endsect]