Opened 14 years ago
Closed 11 years ago
#2879 closed Feature Requests (fixed)
[asio] Handling of unix signals
Reported by: | Owned by: | chris_kohlhoff | |
---|---|---|---|
Milestone: | Boost 1.39.0 | Component: | asio |
Version: | Boost 1.38.0 | Severity: | Problem |
Keywords: | Cc: | samjmill@… |
Description
This proposal suggests adding to asio the ability to invoke a handler whenever a unix signal arrives.
Motivation:
- The extension lets the user have a unix signal handler of an arbitrary signature.
- The extension also removes the "async-signal safe calls" restriction from a handler of a unix signal.
The extension is supposed to be used like this:
void on_signal(boost::system::error_code const& error) {
if (!error)
cout << "sigint received" << endl;
}
int main(int argc, char const* argv[])
{
boost::asio::io_service ios; boost::asio::posix::signal_handler<SIGINT> sigint(ios); while (true) {
ios.reset(); sigint.async_wait(boost::bind(on_signal, _1)); ios.poll();
}
}
The original proposal on the mail list can be found here. http://lists.boost.org/Archives/boost/2009/03/149890.php
Please find the implementation and examples in the attachments.
Attachments (6)
Change History (13)
by , 14 years ago
Attachment: | sighandler.cpp added |
---|
comment:1 by , 13 years ago
Cc: | added |
---|
adding myself, this is exactly what I've been looking for. Any chance this feature can make it into the next version of asio?
comment:3 by , 13 years ago
There was also interest aside from the mail list. So, i made a small library out of this proposal. The library can be found here http://github.com/dgoncharov/libunixsignal/. The library uses autotools. So, basically all you need to do is to type ./configure; make install.
by , 13 years ago
Attachment: | signal_handler.zip added |
---|
Signal handler based on Boost.Asio design guidelines
comment:5 by , 13 years ago
The implementation proposed in the last comment is incorrect. It uses async-signal-unsafe syscalls like locking a mutex inside a signal handler.
by , 13 years ago
Attachment: | signal_handler.2.zip added |
---|
Updated signal handler (based on Boost.Asio design patterns)
comment:6 by , 13 years ago
I've updated the signal handler's implementation. Can you (who you are anonymous :-) please check the new version? It uses a pipe now (there is only write() called in the signal handler function). The tests are still all passed.
comment:7 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
As of [72428], the release branch contains the new signal_set class.
an example