Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

signal_set

Typedef for the typical usage of a signal set.

typedef basic_signal_set signal_set;
Types

Name

Description

implementation_type

The underlying implementation type of I/O object.

service_type

The type of the service that will be used to provide I/O operations.

Member Functions

Name

Description

add

Add a signal to a signal_set.

async_wait

Start an asynchronous operation to wait for a signal to be delivered.

basic_signal_set

Construct a signal set without adding any signals.

Construct a signal set and add one signal.

Construct a signal set and add two signals.

Construct a signal set and add three signals.

cancel

Cancel all operations associated with the signal set.

clear

Remove all signals from a signal_set.

get_io_service

Get the io_service associated with the object.

remove

Remove a signal from a signal_set.

Protected Member Functions

Name

Description

get_implementation

Get the underlying implementation of the I/O object.

get_service

Get the service associated with the I/O object.

Protected Data Members

Name

Description

implementation

(Deprecated: Use get_implementation().) The underlying implementation of the I/O object.

service

(Deprecated: Use get_service().) The service associated with the I/O object.

The basic_signal_set class template provides the ability to perform an asynchronous wait for one or more signals to occur.

Most applications will use the signal_set typedef.

Thread Safety

Distinct objects: Safe.

Shared objects: Unsafe.

Example

Performing an asynchronous wait:

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_service, SIGINT, SIGTERM);

// Start an asynchronous wait for one of the signals to occur.
signals.async_wait(handler);
Queueing of signal notifications

If a signal is registered with a signal_set, and the signal occurs when there are no waiting handlers, then the signal notification is queued. The next async_wait operation on that signal_set will dequeue the notification. If multiple notifications are queued, subsequent async_wait operations dequeue them one at a time. Signal notifications are dequeued in order of ascending signal number.

If a signal number is removed from a signal_set (using the remove or erase member functions) then any queued notifications for that signal are discarded.

Multiple registration of signals

The same signal number may be registered with different signal_set objects. When the signal occurs, one handler is called for each signal_set object.

Note that multiple registration only works for signals that are registered using Asio. The application must not also register a signal handler using functions such as signal() or sigaction().

Signal masking on POSIX platforms

POSIX allows signals to be blocked using functions such as sigprocmask() and pthread_sigmask(). For signals to be delivered, programs must ensure that any signals registered using signal_set objects are unblocked in at least one thread.

Requirements

Header: boost/asio/signal_set.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext