@john-lee
2021-01-03T13:40:59.000000Z
字数 745
阅读 618
Boost.Asio
Boost1.Asio 支持使用名为 signal_set 的类进行信号处理。程序可以向集合中添加一个或多个信号,然后执行async_wait()
操作。当其中一个信号出现时,将调用指定的处理程序。同一个信号可以注册到多个 signal_set 对象中,但是该信号只能用于 Boost.Asio。
void handler(
const boost::system::error_code& error,
int signal_number)
{
if (!error)
{
// A signal occurred.
}
}
...
// Construct a signal set registered for process termination.
boost::asio::signal_set signals(io_context, SIGINT, SIGTERM);
// Start an asynchronous wait for one of the signals to occur.
signals.async_wait(handler);
信号处理也适用于Windows,因为 Microsoft Visual C++ 运行库将像 Ctrl+C 这样的控制台事件映射到等效信号。
signal_set, HTTP 服务器示例(C++03), HTTP 服务器示例(C++11)。
Copyright © 2003-2020 Christopher M. Kohlhoff
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)