]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/asio/doc/overview/signals.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / asio / doc / overview / signals.qbk
1 [/
2 / Copyright (c) 2003-2016 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:signals Signal Handling]
9
10 Boost.Asio supports signal handling using a class called [link
11 boost_asio.reference.signal_set signal_set]. Programs may add one or more signals to
12 the set, and then perform an `async_wait()` operation. The specified handler
13 will be called when one of the signals occurs. The same signal number may be
14 registered with multiple [link boost_asio.reference.signal_set signal_set] objects,
15 however the signal number must be used only with Boost.Asio.
16
17 void handler(
18 const boost::system::error_code& error,
19 int signal_number)
20 {
21 if (!error)
22 {
23 // A signal occurred.
24 }
25 }
26
27 ...
28
29 // Construct a signal set registered for process termination.
30 boost::asio::signal_set signals(io_service, SIGINT, SIGTERM);
31
32 // Start an asynchronous wait for one of the signals to occur.
33 signals.async_wait(handler);
34
35 Signal handling also works on Windows, as the Microsoft Visual C++ runtime
36 library maps console events like Ctrl+C to the equivalent signal.
37
38 [heading See Also]
39
40 [link boost_asio.reference.signal_set signal_set],
41 [link boost_asio.examples.cpp03_examples.http_server HTTP server example (C++03)],
42 [link boost_asio.examples.cpp11_examples.http_server HTTP server example (C++11)].
43
44 [endsect]