SignalHandler.qbk 1.8 KB

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