Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::asio::basic_signal_set< SignalSetService > Class Template Reference

Provides signal functionality. More...

#include <basic_signal_set.hpp>

Inheritance diagram for boost::asio::basic_signal_set< SignalSetService >:
Collaboration diagram for boost::asio::basic_signal_set< SignalSetService >:

Public Types

typedef SignalSetService service_type
 The type of the service that will be used to provide I/O operations. More...
 
typedef
service_type::implementation_type 
implementation_type
 The underlying implementation type of I/O object. More...
 

Public Member Functions

 basic_signal_set (boost::asio::io_service &io_service)
 Construct a signal set without adding any signals. More...
 
 basic_signal_set (boost::asio::io_service &io_service, int signal_number_1)
 Construct a signal set and add one signal. More...
 
 basic_signal_set (boost::asio::io_service &io_service, int signal_number_1, int signal_number_2)
 Construct a signal set and add two signals. More...
 
 basic_signal_set (boost::asio::io_service &io_service, int signal_number_1, int signal_number_2, int signal_number_3)
 Construct a signal set and add three signals. More...
 
void add (int signal_number)
 Add a signal to a signal_set. More...
 
boost::system::error_code add (int signal_number, boost::system::error_code &ec)
 Add a signal to a signal_set. More...
 
void remove (int signal_number)
 Remove a signal from a signal_set. More...
 
boost::system::error_code remove (int signal_number, boost::system::error_code &ec)
 Remove a signal from a signal_set. More...
 
void clear ()
 Remove all signals from a signal_set. More...
 
boost::system::error_code clear (boost::system::error_code &ec)
 Remove all signals from a signal_set. More...
 
void cancel ()
 Cancel all operations associated with the signal set. More...
 
boost::system::error_code cancel (boost::system::error_code &ec)
 Cancel all operations associated with the signal set. More...
 
template<typename SignalHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (SignalHandler, void(boost::system::error_code, int)) async_wait(BOOST_ASIO_MOVE_ARG(SignalHandler) handler)
 Start an asynchronous operation to wait for a signal to be delivered. More...
 
boost::asio::io_serviceget_io_service ()
 Get the io_service associated with the object. More...
 

Protected Member Functions

service_typeget_service ()
 Get the service associated with the I/O object. More...
 
const service_typeget_service () const
 Get the service associated with the I/O object. More...
 
implementation_typeget_implementation ()
 Get the underlying implementation of the I/O object. More...
 
const implementation_typeget_implementation () const
 Get the underlying implementation of the I/O object. More...
 

Protected Attributes

service_typeservice
 (Deprecated: Use get_service().) The service associated with the I/O object. More...
 
implementation_type implementation
 (Deprecated: Use get_implementation().) The underlying implementation of the I/O object. More...
 

Detailed Description

template<typename SignalSetService = signal_set_service>
class boost::asio::basic_signal_set< SignalSetService >

Provides signal functionality.

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 boost::asio::signal_set typedef.

Thread Safety
Distinct objects: Safe.
Shared objects: Unsafe.
Example
Performing an asynchronous wait:
void handler(
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.

Member Typedef Documentation

typedef service_type::implementation_type boost::asio::basic_io_object< SignalSetService >::implementation_type
inherited

The underlying implementation type of I/O object.

typedef SignalSetService boost::asio::basic_io_object< SignalSetService >::service_type
inherited

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

Constructor & Destructor Documentation

template<typename SignalSetService = signal_set_service>
boost::asio::basic_signal_set< SignalSetService >::basic_signal_set ( boost::asio::io_service io_service)
inlineexplicit

Construct a signal set without adding any signals.

This constructor creates a signal set without registering for any signals.

Parameters
io_serviceThe io_service object that the signal set will use to dispatch handlers for any asynchronous operations performed on the set.
template<typename SignalSetService = signal_set_service>
boost::asio::basic_signal_set< SignalSetService >::basic_signal_set ( boost::asio::io_service io_service,
int  signal_number_1 
)
inline

Construct a signal set and add one signal.

This constructor creates a signal set and registers for one signal.

Parameters
io_serviceThe io_service object that the signal set will use to dispatch handlers for any asynchronous operations performed on the set.
signal_number_1The signal number to be added.
Note
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service);
signals.add(signal_number_1);

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::asio::basic_signal_set< SignalSetService >::basic_signal_set ( boost::asio::io_service io_service,
int  signal_number_1,
int  signal_number_2 
)
inline

Construct a signal set and add two signals.

This constructor creates a signal set and registers for two signals.

Parameters
io_serviceThe io_service object that the signal set will use to dispatch handlers for any asynchronous operations performed on the set.
signal_number_1The first signal number to be added.
signal_number_2The second signal number to be added.
Note
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service);
signals.add(signal_number_1);
signals.add(signal_number_2);

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::asio::basic_signal_set< SignalSetService >::basic_signal_set ( boost::asio::io_service io_service,
int  signal_number_1,
int  signal_number_2,
int  signal_number_3 
)
inline

Construct a signal set and add three signals.

This constructor creates a signal set and registers for three signals.

Parameters
io_serviceThe io_service object that the signal set will use to dispatch handlers for any asynchronous operations performed on the set.
signal_number_1The first signal number to be added.
signal_number_2The second signal number to be added.
signal_number_3The third signal number to be added.
Note
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service);
signals.add(signal_number_1);
signals.add(signal_number_2);
signals.add(signal_number_3);

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

Member Function Documentation

template<typename SignalSetService = signal_set_service>
void boost::asio::basic_signal_set< SignalSetService >::add ( int  signal_number)
inline

Add a signal to a signal_set.

This function adds the specified signal to the set. It has no effect if the signal is already in the set.

Parameters
signal_numberThe signal to be added to the set.
Exceptions
boost::system::system_errorThrown on failure.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::system::error_code boost::asio::basic_signal_set< SignalSetService >::add ( int  signal_number,
boost::system::error_code ec 
)
inline

Add a signal to a signal_set.

This function adds the specified signal to the set. It has no effect if the signal is already in the set.

Parameters
signal_numberThe signal to be added to the set.
ecSet to indicate what error occurred, if any.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
template<typename SignalHandler >
boost::asio::basic_signal_set< SignalSetService >::BOOST_ASIO_INITFN_RESULT_TYPE ( SignalHandler  ,
void(boost::system::error_code, int)   
)
inline

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

This function may be used to initiate an asynchronous wait against the signal set. It always returns immediately.

For each call to async_wait(), the supplied handler will be called exactly once. The handler will be called when:

  • One of the registered signals in the signal set occurs; or
Parameters
handlerThe handler to be called when the signal occurs. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const boost::system::error_code& error, // Result of operation.
int signal_number // Indicates which signal occurred.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using boost::asio::io_service::post().

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
void boost::asio::basic_signal_set< SignalSetService >::cancel ( )
inline

Cancel all operations associated with the signal set.

This function forces the completion of any pending asynchronous wait operations against the signal set. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.

Cancellation does not alter the set of registered signals.

Exceptions
boost::system::system_errorThrown on failure.
Note
If a registered signal occurred before cancel() is called, then the handlers for asynchronous wait operations will:
  • have already been invoked; or
  • have been queued for invocation in the near future.

These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::system::error_code boost::asio::basic_signal_set< SignalSetService >::cancel ( boost::system::error_code ec)
inline

Cancel all operations associated with the signal set.

This function forces the completion of any pending asynchronous wait operations against the signal set. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.

Cancellation does not alter the set of registered signals.

Parameters
ecSet to indicate what error occurred, if any.
Note
If a registered signal occurred before cancel() is called, then the handlers for asynchronous wait operations will:
  • have already been invoked; or
  • have been queued for invocation in the near future.

These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
void boost::asio::basic_signal_set< SignalSetService >::clear ( )
inline

Remove all signals from a signal_set.

This function removes all signals from the set. It has no effect if the set is already empty.

Exceptions
boost::system::system_errorThrown on failure.
Note
Removes all queued notifications.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::system::error_code boost::asio::basic_signal_set< SignalSetService >::clear ( boost::system::error_code ec)
inline

Remove all signals from a signal_set.

This function removes all signals from the set. It has no effect if the set is already empty.

Parameters
ecSet to indicate what error occurred, if any.
Note
Removes all queued notifications.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

implementation_type& boost::asio::basic_io_object< SignalSetService >::get_implementation ( )
inlineprotectedinherited

Get the underlying implementation of the I/O object.

const implementation_type& boost::asio::basic_io_object< SignalSetService >::get_implementation ( ) const
inlineprotectedinherited

Get the underlying implementation of the I/O object.

boost::asio::io_service& boost::asio::basic_io_object< SignalSetService >::get_io_service ( )
inlineinherited

Get the io_service associated with the object.

This function may be used to obtain the io_service object that the I/O object uses to dispatch handlers for asynchronous operations.

Returns
A reference to the io_service object that the I/O object will use to dispatch handlers. Ownership is not transferred to the caller.
service_type& boost::asio::basic_io_object< SignalSetService >::get_service ( )
inlineprotectedinherited

Get the service associated with the I/O object.

const service_type& boost::asio::basic_io_object< SignalSetService >::get_service ( ) const
inlineprotectedinherited

Get the service associated with the I/O object.

template<typename SignalSetService = signal_set_service>
void boost::asio::basic_signal_set< SignalSetService >::remove ( int  signal_number)
inline

Remove a signal from a signal_set.

This function removes the specified signal from the set. It has no effect if the signal is not in the set.

Parameters
signal_numberThe signal to be removed from the set.
Exceptions
boost::system::system_errorThrown on failure.
Note
Removes any notifications that have been queued for the specified signal number.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

template<typename SignalSetService = signal_set_service>
boost::system::error_code boost::asio::basic_signal_set< SignalSetService >::remove ( int  signal_number,
boost::system::error_code ec 
)
inline

Remove a signal from a signal_set.

This function removes the specified signal from the set. It has no effect if the signal is not in the set.

Parameters
signal_numberThe signal to be removed from the set.
ecSet to indicate what error occurred, if any.
Note
Removes any notifications that have been queued for the specified signal number.

References boost::asio::basic_io_object< SignalSetService >::implementation, and boost::asio::basic_io_object< SignalSetService >::service.

Member Data Documentation


The documentation for this class was generated from the following file: