MoveAcceptHandler.qbk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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:MoveAcceptHandler Move accept handler requirements]
  8. A move accept handler must meet the requirements for a [link
  9. boost_asio.reference.Handler handler]. A value `h` of a move accept handler class
  10. should work correctly in the expression `h(ec, s)`, where `ec` is an lvalue of
  11. type `const error_code` and `s` is an lvalue of the nested type
  12. `Protocol::socket` for the type `Protocol` of the socket class template.
  13. [heading Examples]
  14. A free function as a move accept handler:
  15. void accept_handler(
  16. const boost::system::error_code& ec, boost::asio::ip::tcp::socket s)
  17. {
  18. ...
  19. }
  20. A move accept handler function object:
  21. struct accept_handler
  22. {
  23. ...
  24. void operator()(
  25. const boost::system::error_code& ec, boost::asio::ip::tcp::socket s)
  26. {
  27. ...
  28. }
  29. ...
  30. };
  31. A lambda as a move accept handler:
  32. acceptor.async_accept(...,
  33. [](const boost::system::error_code& ec, boost::asio::ip::tcp::socket s)
  34. {
  35. ...
  36. });
  37. A non-static class member function adapted to a move accept handler using
  38. `std::bind()`:
  39. void my_class::accept_handler(
  40. const boost::system::error_code& ec, boost::asio::ip::tcp::socket socket)
  41. {
  42. ...
  43. }
  44. ...
  45. boost::asio::async_accept(...,
  46. std::bind(&my_class::accept_handler,
  47. this, std::placeholders::_1,
  48. std::placeholders::_2));
  49. [endsect]