#include <Sig_Handler.h>
Inheritance diagram for ACE_Sig_Handler:
Public Member Functions | |
ACE_Sig_Handler (void) | |
Default ctor/dtor. | |
virtual | ~ACE_Sig_Handler (void) |
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 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 | |
int | sig_pending (void) |
True if there is a pending signal. | |
void | sig_pending (int) |
Reset the value of so that no signal is pending. | |
void | dispatch (int, siginfo_t *, ucontext_t *) |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Static Protected Member Functions | |
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. | |
Static Protected Attributes | |
sig_atomic_t | sig_pending_ = 0 |
Keeps track of whether a signal is pending. | |
Static Private Attributes | |
ACE_Event_Handler * | signal_handlers_ [ACE_NSIG] |
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.
|
Default ctor/dtor.
Definition at line 6 of file Sig_Handler.inl.
00007 { 00008 } |
|
Definition at line 59 of file Sig_Handler.cpp.
00060 { 00061 } |
|
Callback routine registered with sigaction(2) that dispatches the method of the appropriate pre-registered ACE_Event_Handler. Reimplemented in ACE_Sig_Handlers. Definition at line 236 of file Sig_Handler.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_, and ucontext_t.
00239 { 00240 ACE_TRACE ("ACE_Sig_Handler::dispatch"); 00241 00242 // Save/restore errno. 00243 ACE_Errno_Guard error (errno); 00244 00245 // We can't use the <sig_pending> call here because that acquires 00246 // the lock, which is non-portable... 00247 ACE_Sig_Handler::sig_pending_ = 1; 00248 00249 // Darn well better be in range since the OS dispatched this... 00250 ACE_ASSERT (ACE_Sig_Handler::in_range (signum)); 00251 00252 ACE_Event_Handler *eh = ACE_Sig_Handler::signal_handlers_[signum]; 00253 00254 if (eh != 0) 00255 { 00256 if (eh->handle_signal (signum, siginfo, ucontext) == -1) 00257 { 00258 // Define the default disposition. 00259 ACE_Sig_Action sa ((ACE_SignalHandler) SIG_DFL, (sigset_t *) 0); 00260 00261 ACE_Sig_Handler::signal_handlers_[signum] = 0; 00262 00263 // Remove the current disposition by registering the default 00264 // disposition. 00265 sa.register_action (signum); 00266 00267 // Allow the event handler to close down if necessary. 00268 eh->handle_close (ACE_INVALID_HANDLE, 00269 ACE_Event_Handler::SIGNAL_MASK); 00270 } 00271 #if defined (ACE_WIN32) 00272 else 00273 // Win32 is weird in the sense that it resets the signal 00274 // disposition to SIG_DFL after a signal handler is 00275 // dispatched. Therefore, to workaround this "feature" we 00276 // must re-register the <ACE_Event_Handler> with <signum> 00277 // explicitly. 00278 ACE_Sig_Handler::register_handler_i (signum, 00279 eh); 00280 #endif /* ACE_WIN32*/ 00281 } 00282 } |
|
Dump the state of an object.
Reimplemented in ACE_Sig_Handlers. Definition at line 64 of file Sig_Handler.cpp. References ACE_TRACE. Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump().
00065 { 00066 #if defined (ACE_HAS_DUMP) 00067 ACE_TRACE ("ACE_Sig_Handler::dump"); 00068 #endif /* ACE_HAS_DUMP */ 00069 } |
|
Set a new ACE_Event_Handler that is associated with signum. Return the existing handler. Reimplemented in ACE_Sig_Handlers. Definition at line 127 of file Sig_Handler.cpp. References ACE_TRACE, and handler_i().
00129 { 00130 ACE_TRACE ("ACE_Sig_Handler::handler"); 00131 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00132 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00133 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00134 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00135 00136 return ACE_Sig_Handler::handler_i (signum, new_sh); 00137 } |
|
Return the associated with signum.
Reimplemented in ACE_Sig_Handlers. Definition at line 95 of file Sig_Handler.cpp. References ACE_TRACE, in_range(), and signal_handlers_. Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::handler_i().
00096 { 00097 ACE_TRACE ("ACE_Sig_Handler::handler"); 00098 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00099 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00100 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00101 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00102 00103 if (ACE_Sig_Handler::in_range (signum)) 00104 return ACE_Sig_Handler::signal_handlers_[signum]; 00105 else 00106 return 0; 00107 } |
|
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 . Definition at line 110 of file Sig_Handler.cpp. References ACE_TRACE, in_range(), and signal_handlers_. Referenced by handler(), and register_handler_i().
00112 { 00113 ACE_TRACE ("ACE_Sig_Handler::handler_i"); 00114 00115 if (ACE_Sig_Handler::in_range (signum)) 00116 { 00117 ACE_Event_Handler *sh = ACE_Sig_Handler::signal_handlers_[signum]; 00118 00119 ACE_Sig_Handler::signal_handlers_[signum] = new_sh; 00120 return sh; 00121 } 00122 else 00123 return 0; 00124 } |
|
Check whether the SIGNUM is within the legal range of signals.
Definition at line 11 of file Sig_Handler.inl. References ACE_NSIG, and ACE_TRACE. Referenced by 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 183 of file Sig_Handler.cpp. References ACE_TRACE, and register_handler_i(). Referenced by ACE_Async_Timer_Queue_Adapter< TQ >::ACE_Async_Timer_Queue_Adapter(), ACE_MMAP_Memory_Pool::ACE_MMAP_Memory_Pool(), ACE_Shared_Memory_Pool::ACE_Shared_Memory_Pool(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::register_handler().
00188 { 00189 ACE_TRACE ("ACE_Sig_Handler::register_handler"); 00190 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00191 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00192 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00193 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00194 00195 return ACE_Sig_Handler::register_handler_i (signum, 00196 new_sh, 00197 new_disp, 00198 old_sh, 00199 old_disp); 00200 } |
|
This implementation method is called by and Definition at line 144 of file Sig_Handler.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().
00149 { 00150 ACE_TRACE ("ACE_Sig_Handler::register_handler_i"); 00151 00152 if (ACE_Sig_Handler::in_range (signum)) 00153 { 00154 ACE_Sig_Action sa; // Define a "null" action. 00155 ACE_Event_Handler *sh = ACE_Sig_Handler::handler_i (signum, 00156 new_sh); 00157 00158 // Return a pointer to the old <ACE_Sig_Handler> if the user 00159 // asks for this. 00160 if (old_sh != 0) 00161 *old_sh = sh; 00162 00163 // Make sure that <new_disp> points to a valid location if the 00164 // user doesn't care... 00165 if (new_disp == 0) 00166 new_disp = &sa; 00167 00168 new_disp->handler (ace_signal_handler_dispatcher); 00169 #if !defined (ACE_HAS_LYNXOS_SIGNALS) 00170 new_disp->flags (new_disp->flags () | SA_SIGINFO); 00171 #endif /* ACE_HAS_LYNXOS_SIGNALS */ 00172 return new_disp->register_action (signum, old_disp); 00173 } 00174 else 00175 return -1; 00176 } |
|
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 205 of file Sig_Handler.cpp. References ACE_TRACE, in_range(), ACE_Sig_Action::register_action(), SIG_DFL, and signal_handlers_. Referenced by ACE_MMAP_Memory_Pool::handle_signal(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::remove_handler().
00209 { 00210 ACE_TRACE ("ACE_Sig_Handler::remove_handler"); 00211 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00212 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00213 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00214 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00215 00216 if (ACE_Sig_Handler::in_range (signum)) 00217 { 00218 ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); // Define the default disposition. 00219 00220 if (new_disp == 0) 00221 new_disp = &sa; 00222 00223 ACE_Sig_Handler::signal_handlers_[signum] = 0; 00224 00225 // Register either the new disposition or restore the default. 00226 return new_disp->register_action (signum, old_disp); 00227 } 00228 00229 return -1; 00230 } |
|
Reset the value of so that no signal is pending.
Definition at line 83 of file Sig_Handler.cpp. References ACE_TRACE, and sig_pending_.
00084 { 00085 ACE_TRACE ("ACE_Sig_Handler::sig_pending"); 00086 00087 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00088 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00089 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00090 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00091 ACE_Sig_Handler::sig_pending_ = pending; 00092 } |
|
True if there is a pending signal.
Definition at line 72 of file Sig_Handler.cpp. References ACE_TRACE, and sig_pending_. Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dispatch().
00073 { 00074 ACE_TRACE ("ACE_Sig_Handler::sig_pending"); 00075 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00076 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00077 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00078 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00079 return ACE_Sig_Handler::sig_pending_ != 0; 00080 } |
|
Declare the dynamic allocation hooks.
Reimplemented in ACE_Sig_Handlers. Definition at line 105 of file Sig_Handler.h. |
|
Keeps track of whether a signal is pending.
Definition at line 54 of file Sig_Handler.cpp. Referenced by dispatch(), and sig_pending(). |
|
Array used to store one user-defined Event_Handler for every signal. Definition at line 51 of file Sig_Handler.cpp. Referenced by dispatch(), handler(), handler_i(), and remove_handler(). |