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