Modify

Ticket #2879 (closed Feature Requests: fixed)

Opened 5 years ago

Last modified 3 years ago

[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

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

Change History

Changed 5 years ago by dgoncharov@…

an example

Changed 5 years ago by dgoncharov@…

implementation

Changed 5 years ago by dgoncharov@…

implementation

Changed 5 years ago by dgoncharov@…

an example

comment:1 Changed 5 years ago by samjmill@…

  • 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 Changed 5 years ago by kyle.tarplee@…

I would like this as well.

comment:3 Changed 5 years ago by anonymous

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 Changed 5 years ago by anonymous

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

Changed 5 years ago by boris@…

Signal handler based on Boost.Asio design guidelines

comment:5 Changed 4 years ago by anonymous

The implementation proposed in the last comment is incorrect. It uses async-signal-unsafe syscalls like locking a mutex inside a signal handler.

Changed 4 years ago by bschaeling

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

comment:6 Changed 4 years ago by bschaeling

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 Changed 3 years ago by chris_kohlhoff

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.