Opened 14 years ago

Closed 11 years ago

#2879 closed Feature Requests (fixed)

[asio] Handling of unix signals

Reported by: dgoncharov@… 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:

  1. The extension lets the user have a unix signal handler of an arbitrary signature.
  1. 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)

sighandler.cpp (2.0 KB ) - added by dgoncharov@… 14 years ago.
an example
signalfd.hpp (2.3 KB ) - added by dgoncharov@… 14 years ago.
implementation
signal_handler.hpp (1.2 KB ) - added by dgoncharov@… 14 years ago.
implementation
sigselect.cpp (2.0 KB ) - added by dgoncharov@… 14 years ago.
an example
signal_handler.zip (7.7 KB ) - added by boris@… 13 years ago.
Signal handler based on Boost.Asio design guidelines
signal_handler.2.zip (7.8 KB ) - added by bschaeling 13 years ago.
Updated signal handler (based on Boost.Asio design patterns)

Download all attachments as: .zip

Change History (13)

by dgoncharov@…, 14 years ago

Attachment: sighandler.cpp added

an example

by dgoncharov@…, 14 years ago

Attachment: signalfd.hpp added

implementation

by dgoncharov@…, 14 years ago

Attachment: signal_handler.hpp added

implementation

by dgoncharov@…, 14 years ago

Attachment: sigselect.cpp added

an example

comment:1 by samjmill@…, 13 years ago

Cc: samjmill@… 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:2 by kyle.tarplee@…, 13 years ago

I would like this as well.

comment:3 by anonymous, 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.

comment:4 by anonymous, 13 years ago

Forgot to subscribe the previous comment. dgoncharov at unison.com

by boris@…, 13 years ago

Attachment: signal_handler.zip added

Signal handler based on Boost.Asio design guidelines

comment:5 by anonymous, 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 bschaeling, 13 years ago

Attachment: signal_handler.2.zip added

Updated signal handler (based on Boost.Asio design patterns)

comment:6 by bschaeling, 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 chris_kohlhoff, 11 years ago

Resolution: fixed
Status: newclosed

As of [72428], the release branch contains the new signal_set class.

Note: See TracTickets for help on using tickets.