This is the main dispatcher of signals for ACE. It improves the existing UNIX signal handling mechanism by allowing C++ objects to handle signals in a way that avoids the use of global/static variables and functions. More...
#include <Sig_Handler.h>


Public Member Functions | |
| ACE_Sig_Handler (void) | |
| Default constructor. | |
| virtual | ~ACE_Sig_Handler (void) |
| Destructor. | |
| virtual int | register_handler (int signum, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp=0, ACE_Event_Handler **old_sh=0, ACE_Sig_Action *old_disp=0) |
| virtual int | remove_handler (int signum, ACE_Sig_Action *new_disp=0, ACE_Sig_Action *old_disp=0, int sigkey=-1) |
| virtual ACE_Event_Handler * | handler (int signum) |
| Return the ACE_Sig_Handler associated with signum. | |
| virtual ACE_Event_Handler * | handler (int signum, ACE_Event_Handler *) |
| void | dump (void) const |
| Dump the state of an object. | |
Static Public Member Functions | |
| static int | sig_pending (void) |
| True if there is a pending signal. | |
| static void | sig_pending (int) |
| Reset the value of <sig_pending_> so that no signal is pending. | |
| static void | dispatch (int, siginfo_t *, ucontext_t *) |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Static Protected Member Functions | |
| static ACE_Event_Handler * | handler_i (int signum, ACE_Event_Handler *) |
| static int | register_handler_i (int signum, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp=0, ACE_Event_Handler **old_sh=0, ACE_Sig_Action *old_disp=0) |
| static int | in_range (int signum) |
| Check whether the SIGNUM is within the legal range of signals. | |
Static Protected Attributes | |
| static sig_atomic_t | sig_pending_ = 0 |
| Keeps track of whether a signal is pending. | |
Static Private Attributes | |
| static ACE_Event_Handler * | signal_handlers_ [ACE_NSIG] |
This is the main dispatcher of signals for ACE. It improves the existing UNIX signal handling mechanism by allowing C++ objects to handle signals in a way that avoids the use of global/static variables and functions.
Using this class a program can register an ACE_Event_Handler with the ACE_Sig_Handler in order to handle a designated signum. When a signal occurs that corresponds to this signum, the handle_signal method of the registered ACE_Event_Handler is invoked automatically.
Definition at line 43 of file Sig_Handler.h.
| ACE_Sig_Handler::ACE_Sig_Handler | ( | void | ) |
| ACE_Sig_Handler::~ACE_Sig_Handler | ( | void | ) | [virtual] |
| void ACE_Sig_Handler::dispatch | ( | int | signum, | |
| siginfo_t * | siginfo, | |||
| ucontext_t * | ucontext | |||
| ) | [static] |
Callback routine registered with sigaction(2) that dispatches the <handle_signal> method of the appropriate pre-registered ACE_Event_Handler.
Reimplemented in ACE_Sig_Handlers.
Definition at line 231 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::dispatch");
// Save/restore errno.
ACE_Errno_Guard error (errno);
// We can't use the <sig_pending> call here because that acquires
// the lock, which is non-portable...
ACE_Sig_Handler::sig_pending_ = 1;
// Darn well better be in range since the OS dispatched this...
ACE_ASSERT (ACE_Sig_Handler::in_range (signum));
ACE_Event_Handler *eh = ACE_Sig_Handler::signal_handlers_[signum];
if (eh != 0)
{
if (eh->handle_signal (signum, siginfo, ucontext) == -1)
{
// Define the default disposition.
ACE_Sig_Action sa ((ACE_SignalHandler) SIG_DFL, (sigset_t *) 0);
ACE_Sig_Handler::signal_handlers_[signum] = 0;
// Remove the current disposition by registering the default
// disposition.
sa.register_action (signum);
// Allow the event handler to close down if necessary.
eh->handle_close (ACE_INVALID_HANDLE,
ACE_Event_Handler::SIGNAL_MASK);
}
#if defined (ACE_WIN32)
else
// Win32 is weird in the sense that it resets the signal
// disposition to SIG_DFL after a signal handler is
// dispatched. Therefore, to workaround this "feature" we
// must re-register the <ACE_Event_Handler> with <signum>
// explicitly.
ACE_Sig_Handler::register_handler_i (signum,
eh);
#endif /* ACE_WIN32*/
}
}
| void ACE_Sig_Handler::dump | ( | void | ) | const |
Dump the state of an object.
Reimplemented in ACE_Sig_Handlers.
Definition at line 60 of file Sig_Handler.cpp.
{
#if defined (ACE_HAS_DUMP)
ACE_TRACE ("ACE_Sig_Handler::dump");
#endif /* ACE_HAS_DUMP */
}
| ACE_Event_Handler * ACE_Sig_Handler::handler | ( | int | signum | ) | [virtual] |
Return the ACE_Sig_Handler associated with signum.
Reimplemented in ACE_Sig_Handlers.
Definition at line 91 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::handler");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
if (ACE_Sig_Handler::in_range (signum))
return ACE_Sig_Handler::signal_handlers_[signum];
else
return 0;
}
| ACE_Event_Handler * ACE_Sig_Handler::handler | ( | int | signum, | |
| ACE_Event_Handler * | new_sh | |||
| ) | [virtual] |
Set a new ACE_Event_Handler that is associated with signum. Return the existing handler.
Reimplemented in ACE_Sig_Handlers.
Definition at line 123 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::handler");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
return ACE_Sig_Handler::handler_i (signum, new_sh);
}
| ACE_Event_Handler * ACE_Sig_Handler::handler_i | ( | int | signum, | |
| ACE_Event_Handler * | new_sh | |||
| ) | [static, protected] |
Set a new ACE_Event_Handler that is associated with signum. Return the existing handler. Does not acquire any locks so that it can be called from a signal handler, such as <dispatch>.
Definition at line 106 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::handler_i");
if (ACE_Sig_Handler::in_range (signum))
{
ACE_Event_Handler *sh = ACE_Sig_Handler::signal_handlers_[signum];
ACE_Sig_Handler::signal_handlers_[signum] = new_sh;
return sh;
}
else
return 0;
}
| int ACE_Sig_Handler::in_range | ( | int | signum | ) | [static, protected] |
Check whether the SIGNUM is within the legal range of signals.
Definition at line 11 of file Sig_Handler.inl.
{
ACE_TRACE ("ACE_Sig_Handler::in_range");
return signum > 0 && signum < ACE_NSIG;
}
| int ACE_Sig_Handler::register_handler | ( | int | signum, | |
| ACE_Event_Handler * | new_sh, | |||
| ACE_Sig_Action * | new_disp = 0, |
|||
| ACE_Event_Handler ** | old_sh = 0, |
|||
| ACE_Sig_Action * | old_disp = 0 | |||
| ) | [virtual] |
Add a new ACE_Event_Handler and a new sigaction associated with signum. Passes back the existing ACE_Event_Handler and its sigaction if pointers are non-zero. Returns -1 on failure and >= 0 on success.
Reimplemented in ACE_Sig_Handlers.
Definition at line 178 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::register_handler");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
return ACE_Sig_Handler::register_handler_i (signum,
new_sh,
new_disp,
old_sh,
old_disp);
}
| int ACE_Sig_Handler::register_handler_i | ( | int | signum, | |
| ACE_Event_Handler * | new_sh, | |||
| ACE_Sig_Action * | new_disp = 0, |
|||
| ACE_Event_Handler ** | old_sh = 0, |
|||
| ACE_Sig_Action * | old_disp = 0 | |||
| ) | [static, protected] |
This implementation method is called by <register_handler> and dispatch. It doesn't do any locking so that it can be called within a signal handler, such as dispatch. It adds a new ACE_Event_Handler and a new sigaction associated with signum. Passes back the existing ACE_Event_Handler and its sigaction if pointers are non-zero. Returns -1 on failure and >= 0 on success.
Definition at line 140 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::register_handler_i");
if (ACE_Sig_Handler::in_range (signum))
{
ACE_Sig_Action sa; // Define a "null" action.
ACE_Event_Handler *sh = ACE_Sig_Handler::handler_i (signum, new_sh);
// Return a pointer to the old <ACE_Sig_Handler> if the user
// asks for this.
if (old_sh != 0)
*old_sh = sh;
// Make sure that <new_disp> points to a valid location if the
// user doesn't care...
if (new_disp == 0)
new_disp = &sa;
new_disp->handler (ace_signal_handler_dispatcher);
#if !defined (ACE_HAS_LYNXOS4_SIGNALS)
new_disp->flags (new_disp->flags () | SA_SIGINFO);
#endif /* ACE_HAS_LYNXOS4_SIGNALS */
return new_disp->register_action (signum, old_disp);
}
else
return -1;
}
| int ACE_Sig_Handler::remove_handler | ( | int | signum, | |
| ACE_Sig_Action * | new_disp = 0, |
|||
| ACE_Sig_Action * | old_disp = 0, |
|||
| int | sigkey = -1 | |||
| ) | [virtual] |
Remove the ACE_Event_Handler currently associated with signum. sigkey is ignored in this implementation since there is only one instance of a signal handler. Install the new disposition (if given) and return the previous disposition (if desired by the caller). Returns 0 on success and -1 if signum is invalid.
Reimplemented in ACE_Sig_Handlers.
Definition at line 200 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::remove_handler");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
if (ACE_Sig_Handler::in_range (signum))
{
ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); // Define the default disposition.
if (new_disp == 0)
new_disp = &sa;
ACE_Sig_Handler::signal_handlers_[signum] = 0;
// Register either the new disposition or restore the default.
return new_disp->register_action (signum, old_disp);
}
return -1;
}
| void ACE_Sig_Handler::sig_pending | ( | int | pending | ) | [static] |
Reset the value of <sig_pending_> so that no signal is pending.
Definition at line 79 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::sig_pending");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
ACE_Sig_Handler::sig_pending_ = pending;
}
| int ACE_Sig_Handler::sig_pending | ( | void | ) | [static] |
True if there is a pending signal.
Definition at line 68 of file Sig_Handler.cpp.
{
ACE_TRACE ("ACE_Sig_Handler::sig_pending");
ACE_MT (ACE_Recursive_Thread_Mutex *lock =
ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
(ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
return ACE_Sig_Handler::sig_pending_ != 0;
}
Declare the dynamic allocation hooks.
Reimplemented in ACE_Sig_Handlers.
Definition at line 106 of file Sig_Handler.h.
sig_atomic_t ACE_Sig_Handler::sig_pending_ = 0 [static, protected] |
Keeps track of whether a signal is pending.
Definition at line 138 of file Sig_Handler.h.
ACE_Event_Handler * ACE_Sig_Handler::signal_handlers_ [static, private] |
Array used to store one user-defined Event_Handler for every signal.
Definition at line 143 of file Sig_Handler.h.
1.7.0