WaitHandler.qbk 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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:WaitHandler Wait handler requirements]
  8. A wait handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A value `h` of a wait handler class
  10. should work correctly in the expression `h(ec)`, where `ec` is an lvalue of
  11. type `const error_code`.
  12. [heading Examples]
  13. A free function as a wait handler:
  14. void wait_handler(
  15. const boost::system::error_code& ec)
  16. {
  17. ...
  18. }
  19. A wait handler function object:
  20. struct wait_handler
  21. {
  22. ...
  23. void operator()(
  24. const boost::system::error_code& ec)
  25. {
  26. ...
  27. }
  28. ...
  29. };
  30. A lambda as a wait handler:
  31. socket.async_wait(...,
  32. [](const boost::system::error_code& ec)
  33. {
  34. ...
  35. });
  36. A non-static class member function adapted to a wait handler using
  37. `std::bind()`:
  38. void my_class::wait_handler(
  39. const boost::system::error_code& ec)
  40. {
  41. ...
  42. }
  43. ...
  44. socket.async_wait(...,
  45. std::bind(&my_class::wait_handler,
  46. this, std::placeholders::_1));
  47. A non-static class member function adapted to a wait handler using
  48. `boost::bind()`:
  49. void my_class::wait_handler(
  50. const boost::system::error_code& ec)
  51. {
  52. ...
  53. }
  54. ...
  55. socket.async_wait(...,
  56. boost::bind(&my_class::wait_handler,
  57. this, boost::asio::placeholders::error));
  58. [endsect]