Ice 3.7 C++11 API Reference
Public Member Functions | List of all members
IceUtil::CtrlCHandler Class Reference

Provides a portable way to handle Ctrl-C and Ctrl-C like signals. More...

#include <Ice/Ice.h>

Public Member Functions

 CtrlCHandler (CtrlCHandlerCallback cb=nullptr)
 Registers a callback function that handles Ctrl-C like signals. More...
 
CtrlCHandlerCallback getCallback () const
 Obtains the signal callback. More...
 
CtrlCHandlerCallback setCallback (CtrlCHandlerCallback cb)
 Replaces the signal callback. More...
 
 ~CtrlCHandler ()
 Unregisters the callback function. More...
 

Detailed Description

Provides a portable way to handle Ctrl-C and Ctrl-C like signals.

On Linux and macOS, the CtrlCHandler handles SIGHUP, SIGINT and SIGTERM. On Windows, it is essentially a wrapper for SetConsoleCtrlHandler().

Constructor & Destructor Documentation

◆ CtrlCHandler()

IceUtil::CtrlCHandler::CtrlCHandler ( CtrlCHandlerCallback  cb = nullptr)
explicit

Registers a callback function that handles Ctrl-C like signals.

On Linux and macOS, this constructor masks the SIGHUP, SIGINT and SIGTERM signals and then creates a thread that waits for these signals using sigwait. On Windows, this constructor calls SetConsoleCtrlCHandler to register a handler routine that calls the supplied callback function. Only a single CtrlCHandler object can exist in a process at a give time.

Parameters
cbThe callback function to invoke when a signal is received.

◆ ~CtrlCHandler()

IceUtil::CtrlCHandler::~CtrlCHandler ( )

Unregisters the callback function.

On Linux and macOS, this destructor joins and terminates the thread created by the constructor but does not "unmask" SIGHUP, SIGINT and SIGTERM. As a result, these signals are ignored after this destructor completes. On Windows, this destructor unregisters the SetConsoleCtrlHandler handler routine, and as a result a Ctrl-C or similar signal will terminate the application after this destructor completes.

Member Function Documentation

◆ getCallback()

CtrlCHandlerCallback IceUtil::CtrlCHandler::getCallback ( ) const

Obtains the signal callback.

Returns
The callback.

◆ setCallback()

CtrlCHandlerCallback IceUtil::CtrlCHandler::setCallback ( CtrlCHandlerCallback  cb)

Replaces the signal callback.

Parameters
cbThe new callback.
Returns
The old callback, or nil if no callback is currently set.

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