#include <Signal.h>
Inheritance diagram for ACE_Sig_Handler:


Public Methods | |
| 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>. More... | |
| virtual ACE_Event_Handler * | handler (int signum, ACE_Event_Handler *) |
| Set a new <ACE_Event_Handler> that is associated with <signum>. Return the existing handler. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Static Public Methods | |
| int | sig_pending (void) |
| True if there is a pending signal. More... | |
| void | sig_pending (int) |
| Reset the value of <sig_pending_> so that no signal is pending. More... | |
| void | dispatch (int, siginfo_t *, ucontext_t *) |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Static Protected Methods | |
| ACE_Event_Handler * | handler_i (int signum, ACE_Event_Handler *) |
| 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) |
| int | in_range (int signum) |
| Check whether the SIGNUM is within the legal range of signals. More... | |
Static Protected Attributes | |
| sig_atomic_t | sig_pending_ = 0 |
| Keeps track of whether a signal is pending. More... | |
Static Private Attributes | |
| ACE_Event_Handler * | signal_handlers_ [ACE_NSIG] |
| Array used to store one user-defined Event_Handler for every signal. More... | |
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 265 of file Signal.h.
|
||||||||||||||||
|
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 395 of file Signal.cpp. References ACE_ASSERT, ACE_SignalHandler, ACE_TRACE, ACE_Event_Handler::handle_close, ACE_Event_Handler::handle_signal, in_range, ACE_Sig_Action::register_action, register_handler_i, SIG_DFL, sig_pending_, signal_handlers_, ACE_Event_Handler::SIGNAL_MASK, and ucontext_t.
00398 {
00399 ACE_TRACE ("ACE_Sig_Handler::dispatch");
00400
00401 // Save/restore errno.
00402 ACE_Errno_Guard error (errno);
00403
00404 // We can't use the <sig_pending> call here because that acquires
00405 // the lock, which is non-portable...
00406 ACE_Sig_Handler::sig_pending_ = 1;
00407
00408 // Darn well better be in range since the OS dispatched this...
00409 ACE_ASSERT (ACE_Sig_Handler::in_range (signum));
00410
00411 ACE_Event_Handler *eh = ACE_Sig_Handler::signal_handlers_[signum];
00412
00413 if (eh != 0)
00414 {
00415 if (eh->handle_signal (signum, siginfo, ucontext) == -1)
00416 {
00417 // Define the default disposition.
00418 ACE_Sig_Action sa ((ACE_SignalHandler) SIG_DFL, (sigset_t *) 0);
00419
00420 ACE_Sig_Handler::signal_handlers_[signum] = 0;
00421
00422 // Remove the current disposition by registering the default
00423 // disposition.
00424 sa.register_action (signum);
00425
00426 // Allow the event handler to close down if necessary.
00427 eh->handle_close (ACE_INVALID_HANDLE,
00428 ACE_Event_Handler::SIGNAL_MASK);
00429 }
00430 #if defined (ACE_WIN32)
00431 else
00432 // Win32 is weird in the sense that it resets the signal
00433 // disposition to SIG_DFL after a signal handler is
00434 // dispatched. Therefore, to workaround this "feature" we
00435 // must re-register the <ACE_Event_Handler> with <signum>
00436 // explicitly.
00437 ACE_Sig_Handler::register_handler_i (signum,
00438 eh);
00439 #endif /* ACE_WIN32*/
00440 }
00441 }
|
|
|
Dump the state of an object.
Reimplemented in ACE_Sig_Handlers. Definition at line 225 of file Signal.cpp. References ACE_TRACE. Referenced by ACE_WFMO_Reactor::dump, and ACE_Select_Reactor_T::dump.
00226 {
00227 ACE_TRACE ("ACE_Sig_Handler::dump");
00228 }
|
|
||||||||||||
|
Set a new <ACE_Event_Handler> that is associated with <signum>. Return the existing handler.
Reimplemented in ACE_Sig_Handlers. Definition at line 286 of file Signal.cpp. References ACE_MT, ACE_TRACE, and handler_i.
00288 {
00289 ACE_TRACE ("ACE_Sig_Handler::handler");
00290 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00291 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00292 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00293 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00294
00295 return ACE_Sig_Handler::handler_i (signum, new_sh);
00296 }
|
|
|
Return the <ACE_Sig_Handler> associated with <signum>.
Reimplemented in ACE_Sig_Handlers. Definition at line 254 of file Signal.cpp. References ACE_MT, ACE_TRACE, in_range, and signal_handlers_. Referenced by ACE_WFMO_Reactor::handler, ACE_Dev_Poll_Reactor::handler, and ACE_Select_Reactor_T::handler_i.
00255 {
00256 ACE_TRACE ("ACE_Sig_Handler::handler");
00257 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00258 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00259 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00260 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00261
00262 if (ACE_Sig_Handler::in_range (signum))
00263 return ACE_Sig_Handler::signal_handlers_[signum];
00264 else
00265 return 0;
00266 }
|
|
||||||||||||
|
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 269 of file Signal.cpp. References ACE_TRACE, in_range, and signal_handlers_. Referenced by handler, and register_handler_i.
00271 {
00272 ACE_TRACE ("ACE_Sig_Handler::handler_i");
00273
00274 if (ACE_Sig_Handler::in_range (signum))
00275 {
00276 ACE_Event_Handler *sh = ACE_Sig_Handler::signal_handlers_[signum];
00277
00278 ACE_Sig_Handler::signal_handlers_[signum] = new_sh;
00279 return sh;
00280 }
00281 else
00282 return 0;
00283 }
|
|
|
Check whether the SIGNUM is within the legal range of signals.
Definition at line 297 of file Signal.i. References ACE_NSIG, and ACE_TRACE. Referenced by ACE_Sig_Handlers::dispatch, dispatch, handler, handler_i, ACE_Sig_Handlers::register_handler, register_handler_i, ACE_Sig_Handlers::remove_handler, and remove_handler.
|
|
||||||||||||||||||||||||
|
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 342 of file Signal.cpp. References ACE_MT, ACE_TRACE, and register_handler_i. Referenced by ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool, ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool, ACE_WFMO_Reactor::register_handler, ACE_Select_Reactor_T::register_handler, and ACE_Dev_Poll_Reactor::register_handler.
00347 {
00348 ACE_TRACE ("ACE_Sig_Handler::register_handler");
00349 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00350 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00351 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00352 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00353
00354 return ACE_Sig_Handler::register_handler_i (signum,
00355 new_sh,
00356 new_disp,
00357 old_sh,
00358 old_disp);
00359 }
|
|
||||||||||||||||||||||||
|
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 303 of file Signal.cpp. References ace_signal_handler_dispatcher, ACE_TRACE, ACE_Sig_Action::flags, ACE_Sig_Action::handler, handler_i, in_range, ACE_Sig_Action::register_action, and SA_SIGINFO. Referenced by dispatch, and register_handler.
00308 {
00309 ACE_TRACE ("ACE_Sig_Handler::register_handler_i");
00310
00311 if (ACE_Sig_Handler::in_range (signum))
00312 {
00313 ACE_Sig_Action sa; // Define a "null" action.
00314 ACE_Event_Handler *sh = ACE_Sig_Handler::handler_i (signum,
00315 new_sh);
00316
00317 // Return a pointer to the old <ACE_Sig_Handler> if the user
00318 // asks for this.
00319 if (old_sh != 0)
00320 *old_sh = sh;
00321
00322 // Make sure that <new_disp> points to a valid location if the
00323 // user doesn't care...
00324 if (new_disp == 0)
00325 new_disp = &sa;
00326
00327 new_disp->handler (ace_signal_handler_dispatcher);
00328 #if !defined (ACE_HAS_LYNXOS_SIGNALS)
00329 new_disp->flags (new_disp->flags () | SA_SIGINFO);
00330 #endif /* ACE_HAS_LYNXOS_SIGNALS */
00331 return new_disp->register_action (signum, old_disp);
00332 }
00333 else
00334 return -1;
00335 }
|
|
||||||||||||||||||||
|
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 364 of file Signal.cpp. References ACE_MT, ACE_TRACE, in_range, ACE_Sig_Action::register_action, SIG_DFL, and signal_handlers_. Referenced by ACE_MMAP_Memory_Pool::handle_signal, ACE_WFMO_Reactor::remove_handler, ACE_Select_Reactor_T::remove_handler, and ACE_Dev_Poll_Reactor::remove_handler.
00368 {
00369 ACE_TRACE ("ACE_Sig_Handler::remove_handler");
00370 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00371 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00372 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00373 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00374
00375 if (ACE_Sig_Handler::in_range (signum))
00376 {
00377 ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); // Define the default disposition.
00378
00379 if (new_disp == 0)
00380 new_disp = &sa;
00381
00382 ACE_Sig_Handler::signal_handlers_[signum] = 0;
00383
00384 // Register either the new disposition or restore the default.
00385 return new_disp->register_action (signum, old_disp);
00386 }
00387 else
00388 return -1;
00389 }
|
|
|
Reset the value of <sig_pending_> so that no signal is pending.
Definition at line 242 of file Signal.cpp. References ACE_MT, ACE_TRACE, and sig_pending_.
00243 {
00244 ACE_TRACE ("ACE_Sig_Handler::sig_pending");
00245
00246 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00247 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00248 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00249 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00250 ACE_Sig_Handler::sig_pending_ = pending;
00251 }
|
|
|
True if there is a pending signal.
Definition at line 231 of file Signal.cpp. References ACE_MT, ACE_TRACE, and sig_pending_. Referenced by ACE_Select_Reactor_T::dispatch, ACE_Dev_Poll_Reactor::dispatch, and ACE_TP_Reactor::handle_signals.
00232 {
00233 ACE_TRACE ("ACE_Sig_Handler::sig_pending");
00234 ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00235 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00236 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00237 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00238 return ACE_Sig_Handler::sig_pending_ != 0;
00239 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented in ACE_Sig_Handlers. |
|
|
Keeps track of whether a signal is pending.
Definition at line 52 of file Signal.cpp. Referenced by ACE_Sig_Handlers::dispatch, dispatch, and sig_pending. |
|
|
Array used to store one user-defined Event_Handler for every signal.
Definition at line 49 of file Signal.cpp. Referenced by dispatch, handler, handler_i, and remove_handler. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002