RangeConnectHandler.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:RangeConnectHandler Range connect handler requirements]
  8. A range connect handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A value `h` of a range connect handler class
  10. should work correctly in the expression `h(ec, ep)`, where `ec` is an lvalue of
  11. type `const error_code` and `ep` is an lvalue of the type `Protocol::endpoint`
  12. for the `Protocol` type in the corresponding `connect()` or async_connect()`
  13. function.
  14. [heading Examples]
  15. A free function as a range connect handler:
  16. void connect_handler(
  17. const boost::system::error_code& ec,
  18. const boost::asio::ip::tcp::endpoint& endpoint)
  19. {
  20. ...
  21. }
  22. A range connect handler function object:
  23. struct connect_handler
  24. {
  25. ...
  26. template <typename Range>
  27. void operator()(
  28. const boost::system::error_code& ec,
  29. const boost::asio::ip::tcp::endpoint& endpoint)
  30. {
  31. ...
  32. }
  33. ...
  34. };
  35. A lambda as a range connect handler:
  36. boost::asio::async_connect(...,
  37. [](const boost::system::error_code& ec,
  38. const boost::asio::ip::tcp::endpoint& endpoint)
  39. {
  40. ...
  41. });
  42. A non-static class member function adapted to a range connect handler using
  43. `std::bind()`:
  44. void my_class::connect_handler(
  45. const boost::system::error_code& ec,
  46. const boost::asio::ip::tcp::endpoint& endpoint)
  47. {
  48. ...
  49. }
  50. ...
  51. boost::asio::async_connect(...,
  52. std::bind(&my_class::connect_handler,
  53. this, std::placeholders::_1,
  54. std::placeholders::_2));
  55. A non-static class member function adapted to a range connect handler using
  56. `boost::bind()`:
  57. void my_class::connect_handler(
  58. const boost::system::error_code& ec,
  59. const boost::asio::ip::tcp::endpoint& endpoint)
  60. {
  61. ...
  62. }
  63. ...
  64. boost::asio::async_connect(...,
  65. boost::bind(&my_class::connect_handler,
  66. this, boost::asio::placeholders::error,
  67. boost::asio::placeholders::endpoint));
  68. [endsect]