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

 DEFAULT_SIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE
 Default size of the Select_Reactor's handle table.
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 <wait_set_> mask and <ready_set_> 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 <ACE_HANDLEs> to <ACE_Event_Handler *>'s.
ACE_Select_Reactor_Handle_Set dispatch_set_
 Tracks handles that are ready for dispatch from <select>.
ACE_Select_Reactor_Handle_Set wait_set_
 Tracks handles that are waited for by <select>.
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 458 of file Select_Reactor_Base.h.


Member Enumeration Documentation

anonymous enum

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

Definition at line 461 of file Select_Reactor_Base.h.

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


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 <wait_set_> mask and <ready_set_> mask.

Definition at line 970 of file Select_Reactor_Base.cpp.

References ACE_Event_Handler::ACCEPT_MASK, ACE_BIT_ENABLED, ACE_FDS_PTMF, ACE_SET_BITS, ACE_TRACE, ACE_Reactor::ADD_MASK, clear_dispatch_mask(), ACE_Handle_Set::clr_bit(), ACE_Reactor::CLR_MASK, ACE_Event_Handler::CONNECT_MASK, ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Event_Handler::EXCEPT_MASK, ACE_Reactor::GET_MASK, ACE_Handle_Set::is_set(), ACE_Event_Handler::NULL_MASK, ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_Event_Handler::READ_MASK, ACE_Handle_Set::set_bit(), ACE_Reactor::SET_MASK, ACE_Select_Reactor_Handle_Set::wr_mask_, and ACE_Event_Handler::WRITE_MASK.

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

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

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 1063 of file Select_Reactor_Base.cpp.

References ACE_Event_Handler::ACCEPT_MASK, ACE_BIT_ENABLED, ACE_TRACE, ACE_Handle_Set::clr_bit(), dispatch_set_, ACE_Select_Reactor_Handle_Set::ex_mask_, ACE_Event_Handler::EXCEPT_MASK, ACE_Select_Reactor_Handle_Set::rd_mask_, ACE_Event_Handler::READ_MASK, state_changed_, ACE_Select_Reactor_Handle_Set::wr_mask_, and ACE_Event_Handler::WRITE_MASK.

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

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

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

Check to see if the <Event_Handler> 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 >.

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 949 of file Select_Reactor_Base.cpp.

References notify_handler_, and ACE_Reactor_Notify::purge_pending_notifications().

00951 {
00952   if (this->notify_handler_ == 0)
00953     return 0;
00954   else
00955     return this->notify_handler_->purge_pending_notifications (eh, mask);
00956 }

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 <requeue_position_>.

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 1108 of file Select_Reactor_Base.cpp.

01109 {
01110   // The select reactor has no handlers that can be resumed by the
01111   // application. So return 0;
01112 
01113   return 0;
01114 }

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().

00142 {
00143   return this->supress_renew_;
00144 }


Friends And Related Function Documentation

friend class ACE_Select_Reactor_Handler_Repository [friend]

Definition at line 471 of file Select_Reactor_Base.h.

friend class ACE_Select_Reactor_Notify [friend]

Definition at line 470 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 550 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close().

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 546 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close().

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 542 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close().

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::dispatch_set_ [protected]

Tracks handles that are ready for dispatch from <select>.

Definition at line 518 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 <ACE_HANDLEs> to <ACE_Event_Handler *>'s.

Definition at line 515 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump(), ACE_TP_Reactor::handle_socket_events(), ACE_TP_Reactor::post_process_socket_event(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::size().

bool ACE_Select_Reactor_Impl::initialized_ [protected]

True if we've been initialized yet...

Definition at line 553 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::initialized().

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 585 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 538 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump(), ACE_TP_Reactor::get_notify_handle(), ACE_TP_Reactor::handle_notify_events(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::max_notify_iterations(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::notify(), and purge_pending_notifications().

ACE_thread_t ACE_Select_Reactor_Impl::owner_ [protected]

The original thread that created this Select_Reactor.

Definition at line 569 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::owner().

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 <select>.

Definition at line 528 of file Select_Reactor_Base.h.

Referenced by ACE_TP_Reactor::clear_dispatch_mask(), ACE_TP_Reactor::clear_handle_read_set(), ACE_TP_Reactor::get_event_for_dispatching(), and ACE_TP_Reactor::handle_notify_events().

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 <notify> 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 566 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::requeue_position().

int ACE_Select_Reactor_Impl::restart_ [protected]

Restart the <handle_events> event-loop method automatically when <select> is interrupted via <EINTR>.

Definition at line 557 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::handle_error(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::restart().

ACE_Sig_Handler* ACE_Select_Reactor_Impl::signal_handler_ [protected]

Handle signals without requiring global/static variables.

Definition at line 534 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::handler_i(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::register_handler(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::remove_handler().

bool ACE_Select_Reactor_Impl::state_changed_ [protected]

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

Definition at line 577 of file Select_Reactor_Base.h.

Referenced by clear_dispatch_mask(), ACE_TP_Reactor::dispatch_i(), ACE_Priority_Reactor::dispatch_io_set(), and ACE_TP_Reactor::get_event_for_dispatching().

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 596 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 524 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::is_suspended_i(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::resume_i(), and 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 531 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::cancel_timer(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump(), ACE_TP_Reactor::handle_timer_events(), and ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::timer_queue().

ACE_Select_Reactor_Handle_Set ACE_Select_Reactor_Impl::wait_set_ [protected]

Tracks handles that are waited for by <select>.

Definition at line 521 of file Select_Reactor_Base.h.

Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::suspend_i(), and ACE_Select_Reactor_Handler_Repository::unbind().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:33 2010 for ACE by  doxygen 1.4.7