Sig_Handler.cpp

Go to the documentation of this file.
00001 // $Id: Sig_Handler.cpp 81388 2008-04-23 14:02:05Z johnnyw $
00002 
00003 #include "ace/Sig_Handler.h"
00004 #include "ace/Sig_Adapter.h"
00005 #include "ace/Signal.h"
00006 #include "ace/Recursive_Thread_Mutex.h"
00007 #include "ace/Managed_Object.h"
00008 #include "ace/Containers.h"
00009 #include "ace/Guard_T.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 #include "ace/Sig_Handler.inl"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 ACE_RCSID(ace, Sig_Handler, "$Id: Sig_Handler.cpp 81388 2008-04-23 14:02:05Z johnnyw $")
00016 
00017 #if defined (ACE_HAS_SIG_C_FUNC)
00018 
00019 extern "C" void
00020 ace_sig_handler_dispatch (int signum, siginfo_t *info, ucontext_t *context)
00021 {
00022   ACE_TRACE ("ace_sig_handler_dispatch");
00023   ACE_Sig_Handler::dispatch (signum, info, context);
00024 }
00025 
00026 #define ace_signal_handler_dispatcher ACE_SignalHandler(ace_sig_handler_dispatch)
00027 
00028 extern "C" void
00029 ace_sig_handlers_dispatch (int signum, siginfo_t *info, ucontext_t *context)
00030 {
00031   ACE_TRACE ("ace_sig_handlers_dispatch");
00032   ACE_Sig_Handlers::dispatch (signum, info, context);
00033 }
00034 
00035 #define ace_signal_handlers_dispatcher ACE_SignalHandler(ace_sig_handlers_dispatch)
00036 
00037 #else
00038 #define ace_signal_handler_dispatcher ACE_SignalHandler(ACE_Sig_Handler::dispatch)
00039 
00040 #define ace_signal_handlers_dispatcher ACE_SignalHandler(ACE_Sig_Handlers::dispatch)
00041 #endif /* ACE_HAS_SIG_C_FUNC */
00042 
00043 
00044 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00045 
00046 // Array of Event_Handlers that will handle the signals.
00047 ACE_Event_Handler *ACE_Sig_Handler::signal_handlers_[ACE_NSIG];
00048 
00049 // Remembers if a signal has occurred.
00050 sig_atomic_t ACE_Sig_Handler::sig_pending_ = 0;
00051 
00052 
00053 ACE_ALLOC_HOOK_DEFINE(ACE_Sig_Handler)
00054 
00055 ACE_Sig_Handler::~ACE_Sig_Handler (void)
00056 {
00057 }
00058 
00059 void
00060 ACE_Sig_Handler::dump (void) const
00061 {
00062 #if defined (ACE_HAS_DUMP)
00063   ACE_TRACE ("ACE_Sig_Handler::dump");
00064 #endif /* ACE_HAS_DUMP */
00065 }
00066 
00067 int
00068 ACE_Sig_Handler::sig_pending (void)
00069 {
00070   ACE_TRACE ("ACE_Sig_Handler::sig_pending");
00071   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00072           ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00073           (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00074           ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00075   return ACE_Sig_Handler::sig_pending_ != 0;
00076 }
00077 
00078 void
00079 ACE_Sig_Handler::sig_pending (int pending)
00080 {
00081   ACE_TRACE ("ACE_Sig_Handler::sig_pending");
00082 
00083   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00084           ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00085           (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00086           ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00087   ACE_Sig_Handler::sig_pending_ = pending;
00088 }
00089 
00090 ACE_Event_Handler *
00091 ACE_Sig_Handler::handler (int signum)
00092 {
00093   ACE_TRACE ("ACE_Sig_Handler::handler");
00094   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00095     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00096       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00097     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00098 
00099   if (ACE_Sig_Handler::in_range (signum))
00100     return ACE_Sig_Handler::signal_handlers_[signum];
00101   else
00102     return 0;
00103 }
00104 
00105 ACE_Event_Handler *
00106 ACE_Sig_Handler::handler_i (int signum,
00107                             ACE_Event_Handler *new_sh)
00108 {
00109   ACE_TRACE ("ACE_Sig_Handler::handler_i");
00110 
00111   if (ACE_Sig_Handler::in_range (signum))
00112     {
00113       ACE_Event_Handler *sh = ACE_Sig_Handler::signal_handlers_[signum];
00114 
00115       ACE_Sig_Handler::signal_handlers_[signum] = new_sh;
00116       return sh;
00117     }
00118   else
00119     return 0;
00120 }
00121 
00122 ACE_Event_Handler *
00123 ACE_Sig_Handler::handler (int signum,
00124                           ACE_Event_Handler *new_sh)
00125 {
00126   ACE_TRACE ("ACE_Sig_Handler::handler");
00127   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00128     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00129       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00130     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00131 
00132   return ACE_Sig_Handler::handler_i (signum, new_sh);
00133 }
00134 
00135 // Register an ACE_Event_Handler along with the corresponding SIGNUM.
00136 // This method does NOT acquire any locks, so it can be called from a
00137 // signal handler.
00138 
00139 int
00140 ACE_Sig_Handler::register_handler_i (int signum,
00141                                      ACE_Event_Handler *new_sh,
00142                                      ACE_Sig_Action *new_disp,
00143                                      ACE_Event_Handler **old_sh,
00144                                      ACE_Sig_Action *old_disp)
00145 {
00146   ACE_TRACE ("ACE_Sig_Handler::register_handler_i");
00147 
00148   if (ACE_Sig_Handler::in_range (signum))
00149     {
00150       ACE_Sig_Action sa; // Define a "null" action.
00151       ACE_Event_Handler *sh = ACE_Sig_Handler::handler_i (signum,
00152                                                           new_sh);
00153 
00154       // Return a pointer to the old <ACE_Sig_Handler> if the user
00155       // asks for this.
00156       if (old_sh != 0)
00157         *old_sh = sh;
00158 
00159       // Make sure that <new_disp> points to a valid location if the
00160       // user doesn't care...
00161       if (new_disp == 0)
00162         new_disp = &sa;
00163 
00164       new_disp->handler (ace_signal_handler_dispatcher);
00165 #if !defined (ACE_HAS_LYNXOS_SIGNALS)
00166       new_disp->flags (new_disp->flags () | SA_SIGINFO);
00167 #endif /* ACE_HAS_LYNXOS_SIGNALS */
00168       return new_disp->register_action (signum, old_disp);
00169     }
00170   else
00171     return -1;
00172 }
00173 
00174 // Register an ACE_Event_Handler along with the corresponding SIGNUM.
00175 // This method acquires a lock, so it can't be called from a signal
00176 // handler, e.g., <dispatch>.
00177 
00178 int
00179 ACE_Sig_Handler::register_handler (int signum,
00180                                    ACE_Event_Handler *new_sh,
00181                                    ACE_Sig_Action *new_disp,
00182                                    ACE_Event_Handler **old_sh,
00183                                    ACE_Sig_Action *old_disp)
00184 {
00185   ACE_TRACE ("ACE_Sig_Handler::register_handler");
00186   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00187     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00188       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00189     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00190 
00191   return ACE_Sig_Handler::register_handler_i (signum,
00192                                               new_sh,
00193                                               new_disp,
00194                                               old_sh,
00195                                               old_disp);
00196 }
00197 
00198 // Remove an ACE_Event_Handler.
00199 
00200 int
00201 ACE_Sig_Handler::remove_handler (int signum,
00202                                  ACE_Sig_Action *new_disp,
00203                                  ACE_Sig_Action *old_disp,
00204                                  int)
00205 {
00206   ACE_TRACE ("ACE_Sig_Handler::remove_handler");
00207   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00208     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00209       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00210     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00211 
00212   if (ACE_Sig_Handler::in_range (signum))
00213     {
00214       ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); // Define the default disposition.
00215 
00216       if (new_disp == 0)
00217         new_disp = &sa;
00218 
00219       ACE_Sig_Handler::signal_handlers_[signum] = 0;
00220 
00221       // Register either the new disposition or restore the default.
00222       return new_disp->register_action (signum, old_disp);
00223     }
00224 
00225     return -1;
00226 }
00227 
00228 // Master dispatcher function that gets called by a signal handler and
00229 // dispatches one handler...
00230 
00231 void
00232 ACE_Sig_Handler::dispatch (int signum,
00233                            siginfo_t *siginfo,
00234                            ucontext_t *ucontext)
00235 {
00236   ACE_TRACE ("ACE_Sig_Handler::dispatch");
00237 
00238   // Save/restore errno.
00239   ACE_Errno_Guard error (errno);
00240 
00241   // We can't use the <sig_pending> call here because that acquires
00242   // the lock, which is non-portable...
00243   ACE_Sig_Handler::sig_pending_ = 1;
00244 
00245   // Darn well better be in range since the OS dispatched this...
00246   ACE_ASSERT (ACE_Sig_Handler::in_range (signum));
00247 
00248   ACE_Event_Handler *eh = ACE_Sig_Handler::signal_handlers_[signum];
00249 
00250   if (eh != 0)
00251     {
00252       if (eh->handle_signal (signum, siginfo, ucontext) == -1)
00253         {
00254           // Define the default disposition.
00255           ACE_Sig_Action sa ((ACE_SignalHandler) SIG_DFL, (sigset_t *) 0);
00256 
00257           ACE_Sig_Handler::signal_handlers_[signum] = 0;
00258 
00259           // Remove the current disposition by registering the default
00260           // disposition.
00261           sa.register_action (signum);
00262 
00263           // Allow the event handler to close down if necessary.
00264           eh->handle_close (ACE_INVALID_HANDLE,
00265                             ACE_Event_Handler::SIGNAL_MASK);
00266         }
00267 #if defined (ACE_WIN32)
00268       else
00269         // Win32 is weird in the sense that it resets the signal
00270         // disposition to SIG_DFL after a signal handler is
00271         // dispatched.  Therefore, to workaround this "feature" we
00272         // must re-register the <ACE_Event_Handler> with <signum>
00273         // explicitly.
00274         ACE_Sig_Handler::register_handler_i (signum,
00275                                              eh);
00276 #endif /* ACE_WIN32*/
00277     }
00278 }
00279 
00280 // ----------------------------------------
00281 // The following classes are local to this file.
00282 
00283 // There are bugs with HP/UX's C++ compiler that prevents this stuff
00284 // from compiling...
00285 #define ACE_MAX_SIGNAL_HANDLERS ((size_t) 20)
00286 
00287 // Keeps track of the id that uniquely identifies each registered
00288 // signal handler.  This id can be used to cancel a timer via the
00289 // <remove_handler> method.
00290 int ACE_Sig_Handlers::sigkey_ = 0;
00291 
00292 // If this is true then a 3rd party library has registered a
00293 // handler...
00294 bool ACE_Sig_Handlers::third_party_sig_handler_ = false;
00295 
00296 // Make life easier by defining typedefs...
00297 typedef ACE_Fixed_Set <ACE_Event_Handler *, ACE_MAX_SIGNAL_HANDLERS> ACE_SIG_HANDLERS_SET;
00298 typedef ACE_Fixed_Set_Iterator <ACE_Event_Handler *, ACE_MAX_SIGNAL_HANDLERS> ACE_SIG_HANDLERS_ITERATOR;
00299 
00300 class ACE_Sig_Handlers_Set
00301 {
00302 public:
00303   static ACE_SIG_HANDLERS_SET *instance (int signum);
00304 
00305 private:
00306   static ACE_SIG_HANDLERS_SET *sig_handlers_[ACE_NSIG];
00307 };
00308 
00309 /* static */
00310 ACE_SIG_HANDLERS_SET *ACE_Sig_Handlers_Set::sig_handlers_[ACE_NSIG];
00311 
00312 /* static */
00313 ACE_SIG_HANDLERS_SET *
00314 ACE_Sig_Handlers_Set::instance (int signum)
00315 {
00316   if (signum <= 0 || signum >= ACE_NSIG)
00317     return 0; // This will cause problems...
00318   else if (ACE_Sig_Handlers_Set::sig_handlers_[signum] == 0)
00319     ACE_NEW_RETURN (ACE_Sig_Handlers_Set::sig_handlers_[signum],
00320                     ACE_SIG_HANDLERS_SET,
00321                     0);
00322   return ACE_Sig_Handlers_Set::sig_handlers_[signum];
00323 }
00324 
00325 ACE_ALLOC_HOOK_DEFINE(ACE_Sig_Handlers)
00326 
00327 void
00328 ACE_Sig_Handlers::dump (void) const
00329 {
00330 #if defined (ACE_HAS_DUMP)
00331   ACE_TRACE ("ACE_Sig_Handlers::dump");
00332 #endif /* ACE_HAS_DUMP */
00333 }
00334 
00335 // This is the method that does all the dirty work...  The basic
00336 // structure of this method was devised by Detlef Becker.
00337 
00338 int
00339 ACE_Sig_Handlers::register_handler (int signum,
00340                                     ACE_Event_Handler *new_sh,
00341                                     ACE_Sig_Action *new_disp,
00342                                     ACE_Event_Handler **,
00343                                     ACE_Sig_Action *old_disp)
00344 {
00345   ACE_TRACE ("ACE_Sig_Handlers::register_handler");
00346   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00347     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00348       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00349     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00350 
00351   if (ACE_Sig_Handler::in_range (signum))
00352     {
00353       ACE_Sig_Adapter *ace_sig_adapter = 0; // Our signal handler.
00354       ACE_Sig_Adapter *extern_sh = 0; // An external signal handler.
00355       ACE_Sig_Action sa;
00356 
00357       // Get current signal disposition.
00358       sa.retrieve_action (signum);
00359 
00360       // Check whether we are already in control of the signal
00361       // handling disposition...
00362 
00363       if (!(sa.handler () == ace_signal_handlers_dispatcher
00364           || sa.handler () == ACE_SignalHandler (SIG_IGN)
00365           || sa.handler () == ACE_SignalHandler (SIG_DFL)))
00366         {
00367           // Drat, a 3rd party library has already installed a signal ;-(
00368 
00369           // Upto here we never disabled RESTART_MODE.  Thus,
00370           // RESTART_MODE can only be changed by 3rd party libraries.
00371 
00372           if (ACE_BIT_DISABLED (sa.flags (), SA_RESTART)
00373               && ACE_Sig_Handlers::third_party_sig_handler_)
00374             // Toggling is disallowed since we might break 3rd party
00375             // code.
00376             return -1;
00377 
00378           // Note that we've seen a 3rd party handler...
00379           ACE_Sig_Handlers::third_party_sig_handler_ = true;
00380 
00381           // Create a new 3rd party disposition, remembering its
00382           // preferred signal blocking etc...;
00383           ACE_NEW_RETURN (extern_sh,
00384                           ACE_Sig_Adapter (sa,
00385                                            ++ACE_Sig_Handlers::sigkey_),
00386                           -1);
00387           // Add the external signal handler to the set of handlers
00388           // for this signal.
00389           if (ACE_Sig_Handlers_Set::instance (signum)->insert (extern_sh) == -1)
00390             {
00391               delete extern_sh;
00392               return -1;
00393             }
00394         }
00395       // Add our new handler at this point.
00396       ACE_NEW_RETURN (ace_sig_adapter,
00397                       ACE_Sig_Adapter (new_sh,
00398                                        ++ACE_Sig_Handlers::sigkey_),
00399                       -1);
00400       // Add the ACE signal handler to the set of handlers for this
00401       // signal (make sure it goes before the external one if there is
00402       // one of these).
00403       if (ACE_Sig_Handlers_Set::instance (signum)->insert (ace_sig_adapter) == -1)
00404         {
00405           // We couldn't reinstall our handler, so let's pretend like
00406           // none of this happened...
00407           if (extern_sh)
00408             {
00409               ACE_Sig_Handlers_Set::instance (signum)->remove (extern_sh);
00410               delete extern_sh;
00411             }
00412           delete ace_sig_adapter;
00413           return -1;
00414         }
00415       // If ACE_Sig_Handlers::dispatch() was set we're done.
00416       else if (sa.handler () == ace_signal_handlers_dispatcher)
00417         return ace_sig_adapter->sigkey ();
00418 
00419       // Otherwise, we need to register our handler function so that
00420       // all signals will be dispatched through ACE.
00421       else
00422         {
00423           // Make sure that new_disp points to a valid location if the
00424           // user doesn't care...
00425           if (new_disp == 0)
00426             new_disp = &sa;
00427 
00428           new_disp->handler (ace_signal_handlers_dispatcher);
00429 
00430           // Default is to restart signal handlers.
00431           new_disp->flags (new_disp->flags () | SA_RESTART);
00432           new_disp->flags (new_disp->flags () | SA_SIGINFO);
00433 
00434           // Finally install (possibly reinstall) the ACE signal
00435           // handler disposition with the SA_RESTART mode enabled.
00436           if (new_disp->register_action (signum, old_disp) == -1)
00437             {
00438               // Yikes, lots of roll back at this point...
00439               ACE_Sig_Handlers_Set::instance (signum)->remove (ace_sig_adapter);
00440               delete ace_sig_adapter;
00441 
00442               if (extern_sh)
00443                 {
00444                   ACE_Sig_Handlers_Set::instance (signum)->remove (extern_sh);
00445                   delete extern_sh;
00446                 }
00447               return -1;
00448             }
00449           else // Return the signal key so that programs can cancel this
00450             // handler if they want!
00451             return ace_sig_adapter->sigkey ();
00452         }
00453     }
00454 
00455   return -1;
00456 }
00457 
00458 // Remove the ACE_Event_Handler currently associated with <signum>.
00459 // Install the new disposition (if given) and return the previous
00460 // disposition (if desired by the caller).  Returns 0 on success and
00461 // -1 if <signum> is invalid.
00462 
00463 int
00464 ACE_Sig_Handlers::remove_handler (int signum,
00465                                   ACE_Sig_Action *new_disp,
00466                                   ACE_Sig_Action *old_disp,
00467                                   int sigkey)
00468 {
00469   ACE_TRACE ("ACE_Sig_Handlers::remove_handler");
00470   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00471     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00472       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00473     ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00474 
00475   if (ACE_Sig_Handler::in_range (signum))
00476     {
00477       ACE_SIG_HANDLERS_SET *handler_set =
00478         ACE_Sig_Handlers_Set::instance (signum);
00479 
00480       ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set);
00481 
00482       // Iterate through the set of handlers for this signal.
00483 
00484       for (ACE_Event_Handler **eh;
00485            handler_iterator.next (eh) != 0;
00486            handler_iterator.advance ())
00487         {
00488           // Type-safe downcast would be nice here...
00489           ACE_Sig_Adapter *sh = (ACE_Sig_Adapter *) *eh;
00490 
00491           // Remove the handler if (1) its key matches the key we've
00492           // been told to remove or (2) if we've been told to remove
00493           // *all* handlers (i.e., <sigkey> == -1).
00494 
00495           if (sh->sigkey () == sigkey || sigkey == -1)
00496             {
00497               handler_set->remove (*eh);
00498               delete *eh;
00499             }
00500         }
00501 
00502       if (handler_set->size () == 0)
00503         {
00504           // If there are no more handlers left for a signal then
00505           // register the new disposition or restore the default
00506           // disposition.
00507 
00508           ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0);
00509 
00510           if (new_disp == 0)
00511             new_disp = &sa;
00512 
00513           return new_disp->register_action (signum, old_disp);
00514         }
00515       return 0;
00516     }
00517   else
00518     return -1;
00519 }
00520 
00521 // Master dispatcher function that gets called by a signal handler and
00522 // dispatches *all* the handlers...
00523 
00524 void
00525 ACE_Sig_Handlers::dispatch (int signum,
00526                             siginfo_t *siginfo,
00527                             ucontext_t *ucontext)
00528 {
00529   ACE_TRACE ("ACE_Sig_Handlers::dispatch");
00530   // The following is #ifdef'd out because it's entirely non-portable
00531   // to acquire a mutex in a signal handler...
00532 #if 0
00533   ACE_MT (ACE_Recursive_Thread_Mutex *lock =
00534     ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object
00535       (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK);
00536     ACE_TSS_Guard<ACE_Recursive_Thread_Mutex> m (*lock));
00537 #endif /* 0 */
00538 
00539   // Save/restore errno.
00540   ACE_Errno_Guard error (errno);
00541 
00542   ACE_Sig_Handler::sig_pending_ = 1;
00543 
00544   // Darn well better be in range since the OS dispatched this...
00545   ACE_ASSERT (ACE_Sig_Handler::in_range (signum));
00546 
00547   ACE_SIG_HANDLERS_SET *handler_set =
00548     ACE_Sig_Handlers_Set::instance (signum);
00549 
00550   ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set);
00551 
00552   for (ACE_Event_Handler **eh = 0;
00553        handler_iterator.next (eh) != 0;
00554        handler_iterator.advance ())
00555     {
00556       if ((*eh)->handle_signal (signum, siginfo, ucontext) == -1)
00557         {
00558           handler_set->remove (*eh);
00559           delete *eh;
00560         }
00561     }
00562 }
00563 
00564 // Return the first item in the list of handlers.  Note that this will
00565 // trivially provide the same behavior as the ACE_Sig_Handler
00566 // version if there is only 1 handler registered!
00567 
00568 ACE_Event_Handler *
00569 ACE_Sig_Handlers::handler (int signum)
00570 {
00571   ACE_TRACE ("ACE_Sig_Handlers::handler");
00572   ACE_SIG_HANDLERS_SET *handler_set =
00573     ACE_Sig_Handlers_Set::instance (signum);
00574   ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set);
00575   ACE_Event_Handler **eh = 0;
00576   handler_iterator.next (eh);
00577   return *eh;
00578 }
00579 
00580 // The following is a strange bit of logic that tries to give the same
00581 // semantics as what happens in ACE_Sig_Handler when we replace the
00582 // current signal handler with a new one.  Note that if there is only
00583 // one signal handler the behavior will be identical.  If there is
00584 // more than one handler then things get weird...
00585 
00586 ACE_Event_Handler *
00587 ACE_Sig_Handlers::handler (int signum, ACE_Event_Handler *new_sh)
00588 {
00589   ACE_TRACE ("ACE_Sig_Handlers::handler");
00590   ACE_SIG_HANDLERS_SET *handler_set =
00591     ACE_Sig_Handlers_Set::instance (signum);
00592   ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set);
00593   ACE_Event_Handler **eh = 0;
00594 
00595   // Find the first handler...
00596   handler_iterator.next (eh);
00597 
00598   // ... then remove it from the set ...
00599   handler_set->remove (*eh);
00600 
00601   // ... and then insert the new signal handler into the beginning of
00602   // the set (note, this is a bit too tied up in the implementation of
00603   // ACE_Unbounded_Set...).
00604   ACE_Sig_Adapter *temp = 0;
00605 
00606   ACE_NEW_RETURN (temp,
00607                   ACE_Sig_Adapter (new_sh,
00608                                    ++ACE_Sig_Handlers::sigkey_),
00609                   0);
00610   handler_set->insert (temp);
00611   return *eh;
00612 }
00613 
00614 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7