ACE_Select_Reactor_Impl Class Reference

This class simply defines how Select_Reactor's basic interface functions should look like and provides a common base class for Select_Reactor using various locking mechanism. More...

#include <Select_Reactor_Base.h>

Inheritance diagram for ACE_Select_Reactor_Impl:

Inheritance graph
[legend]
Collaboration diagram for ACE_Select_Reactor_Impl:

Collaboration graph
[legend]
List of all members.

Public Types

enum  { DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE }

Public Member Functions

 ACE_Select_Reactor_Impl (bool mask_signals=true)
 Constructor.

virtual int purge_pending_notifications (ACE_Event_Handler *=0, ACE_Reactor_Mask=ACE_Event_Handler::ALL_EVENTS_MASK)
virtual int resumable_handler (void)

Protected Member Functions

virtual int bit_ops (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Select_Reactor_Handle_Set &handle_set, int ops)
 Allow manipulation of the mask and mask.

virtual void renew (void)=0
virtual int is_suspended_i (ACE_HANDLE handle)=0
virtual void clear_dispatch_mask (ACE_HANDLE handle, ACE_Reactor_Mask mask)
int supress_notify_renew (void)
void supress_notify_renew (int sr)

Protected Attributes

ACE_Select_Reactor_Handler_Repository handler_rep_
 Table that maps to <ACE_Event_Handler *>'s.

ACE_Select_Reactor_Handle_Set dispatch_set_
 Tracks handles that are ready for dispatch from .

ACE_Select_Reactor_Handle_Set wait_set_
 Tracks handles that are waited for by .

ACE_Select_Reactor_Handle_Set suspend_set_
 Tracks handles that are currently suspended.

ACE_Select_Reactor_Handle_Set ready_set_
ACE_Timer_Queuetimer_queue_
 Defined as a pointer to allow overriding by derived classes...

ACE_Sig_Handlersignal_handler_
 Handle signals without requiring global/static variables.

ACE_Reactor_Notifynotify_handler_
bool delete_timer_queue_
bool delete_signal_handler_
bool delete_notify_handler_
bool initialized_
 True if we've been initialized yet...

int restart_
int requeue_position_
ACE_thread_t owner_
 The original thread that created this Select_Reactor.

bool state_changed_
bool mask_signals_

Private Member Functions

 ACE_Select_Reactor_Impl (const ACE_Select_Reactor_Impl &)
 Deny access since member-wise won't work...

ACE_Select_Reactor_Imploperator= (const ACE_Select_Reactor_Impl &)

Private Attributes

int supress_renew_

Friends

class ACE_Select_Reactor_Notify
class ACE_Select_Reactor_Handler_Repository

Detailed Description

This class simply defines how Select_Reactor's basic interface functions should look like and provides a common base class for Select_Reactor using various locking mechanism.

Definition at line 459 of file Select_Reactor_Base.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DEFAULT_SIZE  Default size of the Select_Reactor's handle table.

Definition at line 462 of file Select_Reactor_Base.h.

00463   {
00464     /// Default size of the Select_Reactor's handle table.
00465     DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE
00466   };


Constructor & Destructor Documentation

ACE_INLINE ACE_Select_Reactor_Impl::ACE_Select_Reactor_Impl bool  mask_signals = true  ) 
 

Constructor.

Definition at line 120 of file Select_Reactor_Base.inl.

00121   : handler_rep_ (*this)
00122   , timer_queue_ (0)
00123   , signal_handler_ (0)
00124   , notify_handler_ (0)
00125   , delete_timer_queue_ (false)
00126   , delete_signal_handler_ (false)
00127   , delete_notify_handler_ (false)
00128   , initialized_ (false)
00129   , restart_ (0)
00130   , requeue_position_ (-1) // Requeue at end of waiters by default.
00131   , state_changed_ (0)
00132   , mask_signals_ (ms)
00133   , supress_renew_ (0)
00134 {
00135 }

ACE_Select_Reactor_Impl::ACE_Select_Reactor_Impl const ACE_Select_Reactor_Impl  )  [private]
 

Deny access since member-wise won't work...


Member Function Documentation

int ACE_Select_Reactor_Impl::bit_ops ACE_HANDLE  handle,
ACE_Reactor_Mask  mask,
ACE_Select_Reactor_Handle_Set handle_set,
int  ops
[protected, virtual]
 

Allow manipulation of the mask and mask.

Definition at line 957 of file Select_Reactor_Base.cpp.

References ACE_BIT_ENABLED, ACE_FDS_PTMF, ACE_Reactor_Mask, ACE_SET_BITS, ACE_TRACE, clear_dispatch_mask(), ACE_Handle_Set::clr_bit(), ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Select_Reactor_Handler_Repository::handle_in_range(), handler_rep_, ACE_Handle_Set::is_set(), ACE_Select_Reactor_Handle_Set::rd_mask_, and ACE_Select_Reactor_Handle_Set::wr_mask_.

Referenced by ACE_Select_Reactor_Handler_Repository::bind(), and ACE_Select_Reactor_Handler_Repository::unbind().

00961 {
00962   ACE_TRACE ("ACE_Select_Reactor_Impl::bit_ops");
00963   if (this->handler_rep_.handle_in_range (handle) == 0)
00964     return -1;
00965 
00966 #if !defined (ACE_WIN32)
00967   ACE_Sig_Guard sb (0,
00968                     this->mask_signals_); // Block out all signals until method returns.
00969 #endif /* ACE_WIN32 */
00970 
00971   ACE_FDS_PTMF ptmf  = &ACE_Handle_Set::set_bit;
00972   u_long omask = ACE_Event_Handler::NULL_MASK;
00973 
00974   // Find the old reactor masks.  This automatically does the work of
00975   // the GET_MASK operation.
00976   if (handle_set.rd_mask_.is_set (handle))
00977     ACE_SET_BITS (omask, ACE_Event_Handler::READ_MASK);
00978   if (handle_set.wr_mask_.is_set (handle))
00979     ACE_SET_BITS (omask, ACE_Event_Handler::WRITE_MASK);
00980   if (handle_set.ex_mask_.is_set (handle))
00981     ACE_SET_BITS (omask, ACE_Event_Handler::EXCEPT_MASK);
00982 
00983   switch (ops)
00984     {
00985     case ACE_Reactor::GET_MASK:
00986       // The work for this operation is done in all cases at the
00987       // begining of the function.
00988       break;
00989     case ACE_Reactor::CLR_MASK:
00990       ptmf = &ACE_Handle_Set::clr_bit;
00991       // State was changed. we need to reflect that change in the
00992       // dispatch_mask I assume that only ACE_Reactor::CLR_MASK should
00993       // be treated here  which means we need to clear the handle|mask
00994       // from the current dispatch handler
00995       this->clear_dispatch_mask (handle, mask);
00996       /* FALLTHRU */
00997     case ACE_Reactor::SET_MASK:
00998       /* FALLTHRU */
00999     case ACE_Reactor::ADD_MASK:
01000 
01001       // The following code is rather subtle...  Note that if we are
01002       // doing a ACE_Reactor::SET_MASK then if the bit is not enabled
01003       // in the mask we need to clear the bit from the ACE_Handle_Set.
01004       // On the other hand, if we are doing a ACE_Reactor::CLR_MASK or
01005       // a ACE_Reactor::ADD_MASK we just carry out the operations
01006       // specified by the mask.
01007 
01008       // READ, ACCEPT, and CONNECT flag will place the handle in the
01009       // read set.
01010       if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK)
01011           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK)
01012           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
01013         {
01014           (handle_set.rd_mask_.*ptmf) (handle);
01015         }
01016       else if (ops == ACE_Reactor::SET_MASK)
01017         handle_set.rd_mask_.clr_bit (handle);
01018 
01019       // WRITE and CONNECT flag will place the handle in the write set
01020       if (ACE_BIT_ENABLED (mask,
01021                            ACE_Event_Handler::WRITE_MASK)
01022           || ACE_BIT_ENABLED (mask,
01023                               ACE_Event_Handler::CONNECT_MASK))
01024         {
01025           (handle_set.wr_mask_.*ptmf) (handle);
01026         }
01027       else if (ops == ACE_Reactor::SET_MASK)
01028         handle_set.wr_mask_.clr_bit (handle);
01029 
01030       // EXCEPT (and CONNECT on Win32) flag will place the handle in
01031       // the except set.
01032       if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK)
01033 #if defined (ACE_WIN32)
01034           || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK)
01035 #endif /* ACE_WIN32 */
01036           )
01037         {
01038           (handle_set.ex_mask_.*ptmf) (handle);
01039         }
01040       else if (ops == ACE_Reactor::SET_MASK)
01041         handle_set.ex_mask_.clr_bit (handle);
01042       break;
01043     default:
01044       return -1;
01045     }
01046   return omask;
01047 }

void ACE_Select_Reactor_Impl::clear_dispatch_mask ACE_HANDLE  handle,
ACE_Reactor_Mask  mask
[protected, virtual]
 

When register/unregister occur, then we need to re-eval our wait/suspend/dispatch set.

Reimplemented in ACE_TP_Reactor.

Definition at line 1050 of file Select_Reactor_Base.cpp.

References ACE_BIT_ENABLED, ACE_Reactor_Mask, ACE_TRACE, ACE_Handle_Set::clr_bit(), dispatch_set_, ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Select_Reactor_Handle_Set::rd_mask_, state_changed_, and ACE_Select_Reactor_Handle_Set::wr_mask_.

Referenced by bit_ops(), ACE_Priority_Reactor::dispatch_io_set(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::suspend_i().

01052 {
01053   ACE_TRACE ("ACE_Select_Reactor_Impl::clear_dispatch_mask");
01054 
01055   //  Use handle and mask in order to modify the sets
01056   // (wait/suspend/ready/dispatch), that way, the dispatch_io_set loop
01057   // will not be interrupt, and there will no reason to rescan the
01058   // wait_set and re-calling select function, which is *very*
01059   // expensive. It seems that wait/suspend/ready sets are getting
01060   // updated in register/remove bind/unbind etc functions.  The only
01061   // thing need to be updated is the dispatch_set (also can  be found
01062   // in that file code as dispatch_mask).  Because of that, we need
01063   // that dispatch_set to be member of the ACE_Select_Reactor_impl in
01064   // Select_Reactor_Base.h file  That way we will have access to that
01065   // member in that function.
01066 
01067   // We kind of invalidate the iterator in dispatch_io_set because its
01068   // an array and index built from the original dispatch-set. Take a
01069   // look at dispatch_io_set for more details.
01070 
01071   // We only need to clr_bit, because we are interested in clearing the
01072   // handles that was removed, so no dispatching to these handles will
01073   // occur.
01074   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK) ||
01075       ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK))
01076     {
01077       this->dispatch_set_.rd_mask_.clr_bit (handle);
01078     }
01079   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK))
01080     {
01081       this->dispatch_set_.wr_mask_.clr_bit (handle);
01082     }
01083   if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
01084     {
01085       this->dispatch_set_.ex_mask_.clr_bit (handle);
01086     }
01087 
01088   // That will make the dispatch_io_set iterator re-start and rescan
01089   // the dispatch set.
01090   this->state_changed_ = true;
01091 }

virtual int ACE_Select_Reactor_Impl::is_suspended_i ACE_HANDLE  handle  )  [protected, pure virtual]
 

Check to see if the associated with handle is suspended. Returns 0 if not, 1 if so.

Implemented in ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Referenced by ACE_Select_Reactor_Handler_Repository::bind().

ACE_Select_Reactor_Impl& ACE_Select_Reactor_Impl::operator= const ACE_Select_Reactor_Impl  )  [private]
 

int ACE_Select_Reactor_Impl::purge_pending_notifications ACE_Event_Handler = 0,
ACE_Reactor_Mask  = ACE_Event_Handler::ALL_EVENTS_MASK
[virtual]
 

Purge any notifications pending in this reactor for the specified ACE_Event_Handler object. Returns the number of notifications purged. Returns -1 on error.

Implements ACE_Reactor_Impl.

Definition at line 936 of file Select_Reactor_Base.cpp.

References ACE_Reactor_Mask, notify_handler_, and ACE_Reactor_Notify::purge_pending_notifications().

00938 {
00939   if (this->notify_handler_ == 0)
00940     return 0;
00941   else
00942     return this->notify_handler_->purge_pending_notifications (eh, mask);
00943 }

virtual void ACE_Select_Reactor_Impl::renew void   )  [protected, pure virtual]
 

Enqueue ourselves into the list of waiting threads at the appropriate point specified by .

Implemented in ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >, and ACE_Select_Reactor_T< ACE_Select_Reactor_Token >.

Referenced by ACE_Select_Reactor_Notify::handle_input().

int ACE_Select_Reactor_Impl::resumable_handler void   )  [virtual]
 

Does the reactor allow the application to resume the handle on its own ie. can it pass on the control of handle resumption to the application. The select reactor has no handlers that can be resumed by the application. So return 0;

Implements ACE_Reactor_Impl.

Reimplemented in ACE_TP_Reactor.

Definition at line 1095 of file Select_Reactor_Base.cpp.

01096 {
01097   // The select reactor has no handlers that can be resumed by the
01098   // application. So return 0;
01099 
01100   return 0;
01101 }

ACE_INLINE void ACE_Select_Reactor_Impl::supress_notify_renew int  sr  )  [protected]
 

Definition at line 147 of file Select_Reactor_Base.inl.

References supress_renew_.

00148 {
00149   this->supress_renew_ = sr;
00150 }

ACE_INLINE int ACE_Select_Reactor_Impl::supress_notify_renew void   )  [protected]
 

Controls/access whether the notify handler should renew the Select_Reactor's token or not.

Definition at line 141 of file Select_Reactor_Base.inl.

References supress_renew_.

Referenced by ACE_TP_Reactor::ACE_TP_Reactor(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::renew().

00142 {
00143   return this->supress_renew_;
00144 }


Friends And Related Function Documentation

friend class ACE_Select_Reactor_Handler_Repository [friend]
 

Definition at line 472 of file Select_Reactor_Base.h.

friend class ACE_Select_Reactor_Notify [friend]
 

Definition at line 471 of file Select_Reactor_Base.h.


Member Data Documentation

bool ACE_Select_Reactor_Impl::delete_notify_handler_ [protected]
 

Keeps track of whether we need to delete the notify handler (if we didn't create it, then we don't delete it).

Definition at line 551 of file Select_Reactor_Base.h.

bool ACE_Select_Reactor_Impl::delete_signal_handler_ [protected]
 

Keeps track of whether we should delete the signal handler (if we didn't create it, then we don't delete it).

Definition at line 547 of file Select_Reactor_Base.h.

bool ACE_Select_Reactor_Impl::delete_timer_queue_ [protected]
 

Keeps track of whether we should delete the timer queue (if we didn't create it, then we don't delete it).

Definition at line 543 of file Select_Reactor_Base.h.

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::dispatch_set_ [protected]
 

Tracks handles that are ready for dispatch from .

Definition at line 519 of file Select_Reactor_Base.h.

Referenced by clear_dispatch_mask().

ACE_Select_Reactor_Handler_Repository ACE_Select_Reactor_Impl::handler_rep_ [protected]
 

Table that maps to <ACE_Event_Handler *>'s.

Definition at line 516 of file Select_Reactor_Base.h.

Referenced by bit_ops().

bool ACE_Select_Reactor_Impl::initialized_ [protected]
 

True if we've been initialized yet...

Definition at line 554 of file Select_Reactor_Base.h.

bool ACE_Select_Reactor_Impl::mask_signals_ [protected]
 

If 0 then the Reactor will not mask the signals during the event dispatching. This is useful for applications that do not register any signal handlers and want to reduce the overhead introduce by the kernel level locks required to change the mask.

Definition at line 586 of file Select_Reactor_Base.h.

ACE_Reactor_Notify* ACE_Select_Reactor_Impl::notify_handler_ [protected]
 

Callback object that unblocks the ACE_Select_Reactor if it's sleeping.

Definition at line 539 of file Select_Reactor_Base.h.

Referenced by purge_pending_notifications().

ACE_thread_t ACE_Select_Reactor_Impl::owner_ [protected]
 

The original thread that created this Select_Reactor.

Definition at line 570 of file Select_Reactor_Base.h.

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::ready_set_ [protected]
 

Track HANDLES we are interested in for various events that must be dispatched *without* going through .

Definition at line 529 of file Select_Reactor_Base.h.

int ACE_Select_Reactor_Impl::requeue_position_ [protected]
 

Position that the main ACE_Select_Reactor thread is requeued in the list of waiters during a callback. If this value == -1 we are requeued at the end of the list. Else if it's 0 then we are requeued at the front of the list. Else if it's > 1 then that indicates the number of waiters to skip over.

Definition at line 567 of file Select_Reactor_Base.h.

int ACE_Select_Reactor_Impl::restart_ [protected]
 

Restart the event-loop method automatically when is interrupted via .

Definition at line 558 of file Select_Reactor_Base.h.

ACE_Sig_Handler* ACE_Select_Reactor_Impl::signal_handler_ [protected]
 

Handle signals without requiring global/static variables.

Definition at line 535 of file Select_Reactor_Base.h.

bool ACE_Select_Reactor_Impl::state_changed_ [protected]
 

True if state has changed during dispatching of , else false. This is used to determine whether we need to make another trip through the 's loop.

Definition at line 578 of file Select_Reactor_Base.h.

Referenced by clear_dispatch_mask().

int ACE_Select_Reactor_Impl::supress_renew_ [private]
 

Determine whether we should renew Select_Reactor's token after handling the notification message.

Definition at line 598 of file Select_Reactor_Base.h.

Referenced by supress_notify_renew().

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::suspend_set_ [protected]
 

Tracks handles that are currently suspended.

Definition at line 525 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_Handler_Repository::unbind().

ACE_Timer_Queue* ACE_Select_Reactor_Impl::timer_queue_ [protected]
 

Defined as a pointer to allow overriding by derived classes...

Definition at line 532 of file Select_Reactor_Base.h.

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::wait_set_ [protected]
 

Tracks handles that are waited for by .

Definition at line 522 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_Handler_Repository::unbind().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 12:57:09 2008 for ACE by doxygen 1.3.6