Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Handle_Set Class Reference

C++ wrapper facade for the socket <fd_set> abstraction. More...

#include <Handle_Set.h>

List of all members.

Public Types

enum  { MAXSIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE }

Public Methods

 ACE_Handle_Set (void)
 Constructor, initializes the bitmask to all 0s. More...

 ACE_Handle_Set (const ACE_FD_SET_TYPE &mask)
void reset (void)
 Initialize the bitmask to all 0s and reset the associated fields. More...

int is_set (ACE_HANDLE handle) const
void set_bit (ACE_HANDLE handle)
 Enables the <handle>. No range checking is performed so <handle> must be less than <ACE_DEFAULT_SELECT_REACTOR_SIZE>. More...

void clr_bit (ACE_HANDLE handle)
 Disables the <handle>. No range checking is performed so <handle> must be less than <ACE_DEFAULT_SELECT_REACTOR_SIZE>. More...

int num_set (void) const
 Returns a count of the number of enabled bits. More...

ACE_HANDLE max_set (void) const
 Returns the number of the large bit. More...

void sync (ACE_HANDLE max)
 operator fd_set * ()
 Returns a pointer to the underlying <fd_set>. Returns 0 if there are no handle bits set (<size_> == 0). More...

fd_set * fdset (void)
 Returns a pointer to the underlying <fd_set>. Returns 0 if there are no handle bits set (<size_> == 0). More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Types

enum  { WORDSIZE = NFDBITS, NBITS = 256 }

Private Methods

void set_max (ACE_HANDLE max)
 Resets the <max_handle_> after a clear of the original <max_handle_>. More...


Static Private Methods

int count_bits (u_long n)
 Counts the number of bits enabled in N. Uses a table lookup to speed up the count. More...


Private Attributes

int size_
 Size of the set, i.e., a count of the number of enabled bits. More...

ACE_HANDLE max_handle_
 Current max handle. More...

fd_set mask_
 Bitmask. More...


Static Private Attributes

const char nbits_ [NBITS]
 Table that maps bytes to counts of the enabled bits in each value from 0 to 255. More...


Friends

class ACE_Handle_Set_Iterator


Detailed Description

C++ wrapper facade for the socket <fd_set> abstraction.

This abstraction is a very efficient wrapper facade over <fd_set>. In particular, no range checking is performed, so it's important not to set or clear bits that are outside the <ACE_DEFAULT_SELECT_REACTOR_SIZE>.

Definition at line 33 of file Handle_Set.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
MAXSIZE 

Definition at line 40 of file Handle_Set.h.

00041   {
00042     MAXSIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE
00043   };

anonymous enum [private]
 

Enumeration values:
WORDSIZE 
NBITS 

Definition at line 124 of file Handle_Set.h.

00125   {
00126     WORDSIZE = NFDBITS,
00127 #if !defined (ACE_WIN32)
00128     NUM_WORDS = howmany (MAXSIZE, NFDBITS),
00129 #endif /* ACE_WIN32 */
00130     NBITS = 256
00131   };


Constructor & Destructor Documentation

ACE_Handle_Set::ACE_Handle_Set void   
 

Constructor, initializes the bitmask to all 0s.

Definition at line 85 of file Handle_Set.cpp.

References ACE_TRACE, and reset.

00086 {
00087   ACE_TRACE ("ACE_Handle_Set::ACE_Handle_Set");
00088   this->reset ();
00089 }

ACE_Handle_Set::ACE_Handle_Set const ACE_FD_SET_TYPE   mask
 

Constructor, initializes the handle set from a given mask. <ACE_FD_SET_TYPE> is a <typedef> based on the platform's native type used for masks passed to <select>.

Definition at line 91 of file Handle_Set.cpp.

References ACE_FD_SET_TYPE, ACE_TRACE, MAXSIZE, ACE_OS_String::memcpy, reset, and sync.

00092 {
00093   ACE_TRACE ("ACE_Handle_Set::ACE_Handle_Set");
00094   this->reset ();
00095   ACE_OS::memcpy ((void *) &this->mask_,
00096                   (void *) &fd_mask,
00097                   sizeof this->mask_);
00098 #if !defined (ACE_WIN32)
00099   this->sync (ACE_Handle_Set::MAXSIZE);
00100 #if defined (ACE_HAS_BIG_FD_SET)
00101   this->min_handle_ = 0;
00102 #endif /* ACE_HAS_BIG_FD_SET */
00103 #endif /* !ACE_WIN32 */
00104 }


Member Function Documentation

ACE_INLINE void ACE_Handle_Set::clr_bit ACE_HANDLE    handle
 

Disables the <handle>. No range checking is performed so <handle> must be less than <ACE_DEFAULT_SELECT_REACTOR_SIZE>.

Definition at line 108 of file Handle_Set.i.

References ACE_TRACE, is_set, max_handle_, set_max, and size_.

Referenced by ACE_Select_Reactor_Impl::bit_ops, ACE_Select_Reactor_T::check_handles, ACE_TP_Reactor::clear_handle_read_set, ACE_Select_Reactor_Notify::dispatch_notifications, ACE_TP_Reactor::handle_notify_events, ACE_Select_Reactor_T::resume_i, and ACE_Select_Reactor_T::suspend_i.

00109 {
00110   ACE_TRACE ("ACE_Handle_Set::clr_bit");
00111 
00112   if ((handle != ACE_INVALID_HANDLE) &&
00113       (this->is_set (handle)))
00114     {
00115       FD_CLR ((ACE_SOCKET) handle,
00116               &this->mask_);
00117       this->size_--;
00118 
00119 #if !defined (ACE_WIN32)
00120       if (handle == this->max_handle_)
00121         this->set_max (this->max_handle_);
00122 #endif /* !ACE_WIN32 */
00123     }
00124 }

int ACE_Handle_Set::count_bits u_long    n [static, private]
 

Counts the number of bits enabled in N. Uses a table lookup to speed up the count.

Definition at line 110 of file Handle_Set.cpp.

References ACE_TRACE, and nbits_.

Referenced by sync.

00111 {
00112 
00113  ACE_TRACE ("ACE_Handle_Set::count_bits");
00114 #if defined (ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT)
00115   register int rval = 0;
00116 
00117   // Count the number of enabled bits in <n>.  This algorithm is very
00118   // fast, i.e., O(enabled bits in n).
00119 
00120   for (register u_long m = n;
00121        m != 0;
00122        m &= m - 1)
00123     rval++;
00124 
00125   return rval;
00126 #else
00127    return (ACE_Handle_Set::nbits_[n & 0xff]
00128           + ACE_Handle_Set::nbits_[(n >> 8) & 0xff]
00129           + ACE_Handle_Set::nbits_[(n >> 16) & 0xff]
00130           + ACE_Handle_Set::nbits_[(n >> 24) & 0xff]);
00131 #endif /* ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT */
00132 }

void ACE_Handle_Set::dump void    const
 

Dump the state of an object.

Definition at line 29 of file Handle_Set.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, is_set, LM_DEBUG, mask_, and max_handle_.

00030 {
00031   ACE_TRACE ("ACE_Handle_Set::dump");
00032 
00033   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00034 
00035   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nsize_ = %d"), this->size_));
00036   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nmax_handle_ = %d"), this->max_handle_));
00037   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n[ ")));
00038 
00039 #if defined (ACE_WIN32)
00040   for (size_t i = 0; i < (size_t) this->mask_.fd_count + 1; i++)
00041     ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" %x "), this->mask_.fd_array[i]));
00042 #else /* !ACE_WIN32 */
00043   for (ACE_HANDLE i = 0; i < this->max_handle_ + 1; i++)
00044     if (this->is_set (i))
00045       ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" %d "), i));
00046 #endif /* ACE_WIN32 */
00047 
00048   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" ]\n")));
00049   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00050 }

ACE_INLINE fd_set * ACE_Handle_Set::fdset void   
 

Returns a pointer to the underlying <fd_set>. Returns 0 if there are no handle bits set (<size_> == 0).

Definition at line 155 of file Handle_Set.i.

References ACE_TRACE, mask_, and size_.

Referenced by ACE::handle_ready, and ACE::select.

00156 {
00157   ACE_TRACE ("ACE_Handle_Set::fdset");
00158 
00159   if (this->size_ > 0)
00160     return (fd_set *) &this->mask_;
00161   else
00162     return (fd_set *) 0;
00163 }

ACE_INLINE int ACE_Handle_Set::is_set ACE_HANDLE    handle const
 

Checks whether <handle> is enabled. No range checking is performed so <handle> must be less than <ACE_DEFAULT_SELECT_REACTOR_SIZE>.

Definition at line 60 of file Handle_Set.i.

References ACE_TRACE, and size_.

Referenced by ACE_Select_Reactor_Impl::bit_ops, clr_bit, ACE_Select_Reactor_Notify::dispatch_notifications, dump, ACE_FlReactor::fl_io_proc, ACE_TP_Reactor::get_notify_handle, ACE::handle_timed_complete, ACE_XtReactor::InputCallbackProc, ACE_TkReactor::InputCallbackProc, ACE_Select_Reactor_T::is_suspended_i, ACE_TP_Reactor::mask_ops, ACE_Select_Reactor_T::resume_i, set_bit, ACE_Select_Reactor_T::suspend_i, and ACE_Select_Reactor_Handler_Repository::unbind.

00061 {
00062   ACE_TRACE ("ACE_Handle_Set::is_set");
00063 #if defined (ACE_HAS_BIG_FD_SET)
00064   return FD_ISSET (handle,
00065                    &this->mask_)
00066     && this->size_ > 0;
00067 #else
00068   return FD_ISSET (handle,
00069                    &this->mask_);
00070 #endif /* ACE_HAS_BIG_FD_SET */
00071 }

ACE_INLINE ACE_HANDLE ACE_Handle_Set::max_set void    const
 

Returns the number of the large bit.

Definition at line 51 of file Handle_Set.i.

References ACE_TRACE, and max_handle_.

Referenced by ACE_Select_Reactor_Handler_Repository::unbind.

00052 {
00053   ACE_TRACE ("ACE_Handle_Set::max_set");
00054   return this->max_handle_;
00055 }

ACE_INLINE int ACE_Handle_Set::num_set void    const
 

Returns a count of the number of enabled bits.

Definition at line 129 of file Handle_Set.i.

References ACE_TRACE, mask_, and size_.

Referenced by ACE_Process::close_dup_handles, ACE_Process::close_passed_handles, ACE_Process_Options::dup_handles, ACE_Process_Options::passed_handles, and ACE_TP_Reactor::remove_handler.

00130 {
00131   ACE_TRACE ("ACE_Handle_Set::num_set");
00132 #if defined (ACE_WIN32)
00133   return this->mask_.fd_count;
00134 #else /* !ACE_WIN32 */
00135   return this->size_;
00136 #endif /* ACE_WIN32 */
00137 }

ACE_INLINE ACE_Handle_Set::operator fd_set *  
 

Returns a pointer to the underlying <fd_set>. Returns 0 if there are no handle bits set (<size_> == 0).

Definition at line 142 of file Handle_Set.i.

References ACE_TRACE, mask_, and size_.

00143 {
00144   ACE_TRACE ("ACE_Handle_Set::operator fd_set *");
00145 
00146   if (this->size_ > 0)
00147     return (fd_set *) &this->mask_;
00148   else
00149     return (fd_set *) 0;
00150 }

ACE_INLINE void ACE_Handle_Set::reset void   
 

Initialize the bitmask to all 0s and reset the associated fields.

Definition at line 9 of file Handle_Set.i.

References ACE_TRACE, max_handle_, size_, and WORDSIZE.

Referenced by ACE_Handle_Set, ACE_QtReactor::ACE_QtReactor, ACE_WIN32_Asynch_Connect::cancel_uncompleted, ACE_POSIX_Asynch_Connect::cancel_uncompleted, ACE_Process::close_dup_handles, ACE_Process::close_passed_handles, ACE_Process_Options::dup_handles, ACE_TP_Reactor::get_event_for_dispatching, ACE_Process_Options::passed_handles, ACE_SOCK_Dgram::recv, ACE_SOCK_IO::recvv, and ACE_SOCK_Dgram::send.

00010 {
00011   ACE_TRACE ("ACE_Handle_Set::reset");
00012   this->max_handle_ =
00013     ACE_INVALID_HANDLE;
00014 #if defined (ACE_HAS_BIG_FD_SET)
00015   this->min_handle_ =
00016     NUM_WORDS * WORDSIZE;
00017 #endif /* ACE_HAS_BIG_FD_SET */
00018   this->size_ = 0;
00019   // #if !defined (ACE_HAS_BIG_FD_SET)      Why is this here?  -Steve Huston
00020   FD_ZERO (&this->mask_);
00021   // #endif /* ACE_HAS_BIG_FD_SET */
00022 }

ACE_INLINE void ACE_Handle_Set::set_bit ACE_HANDLE    handle
 

Enables the <handle>. No range checking is performed so <handle> must be less than <ACE_DEFAULT_SELECT_REACTOR_SIZE>.

Definition at line 76 of file Handle_Set.i.

References ACE_TRACE, is_set, max_handle_, and size_.

Referenced by ACE_Select_Reactor_Impl::bit_ops, ACE_WIN32_Asynch_Connect::cancel_uncompleted, ACE_POSIX_Asynch_Connect::cancel_uncompleted, ACE_Select_Reactor_T::check_handles, ACE_FlReactor::fl_io_proc, ACE_Acceptor< SVC_HANDLER, ACE_PEER_ACCEPTOR_2 >::handle_input, ACE::handle_ready, ACE::handle_timed_accept, ACE::handle_timed_complete, ACE_XtReactor::InputCallbackProc, ACE_TkReactor::InputCallbackProc, ACE_Process_Options::pass_handle, ACE_SOCK_Dgram::recv, ACE_SOCK_Dgram_SC::recv, ACE_SOCK_IO::recvv, ACE_Select_Reactor_T::resume_i, ACE_SOCK_Dgram::send, and ACE_Select_Reactor_T::suspend_i.

00077 {
00078   ACE_TRACE ("ACE_Handle_Set::set_bit");
00079   if ((handle != ACE_INVALID_HANDLE)
00080       && (!this->is_set (handle)))
00081     {
00082 #if defined (ACE_WIN32)
00083       FD_SET ((SOCKET) handle,
00084               &this->mask_);
00085       this->size_++;
00086 #else /* ACE_WIN32 */
00087 #if defined (ACE_HAS_BIG_FD_SET)
00088       if (this->size_ == 0)
00089         FD_ZERO (&this->mask_);
00090 
00091       if (handle < this->min_handle_)
00092         this->min_handle_ = handle;
00093 #endif /* ACE_HAS_BIG_FD_SET */
00094 
00095       FD_SET (handle,
00096               &this->mask_);
00097       this->size_++;
00098 
00099       if (handle > this->max_handle_)
00100         this->max_handle_ = handle;
00101 #endif /* ACE_WIN32 */
00102     }
00103 }

void ACE_Handle_Set::set_max ACE_HANDLE    max [private]
 

Resets the <max_handle_> after a clear of the original <max_handle_>.

Definition at line 205 of file Handle_Set.cpp.

References ACE_DIV_BY_WORDSIZE, ACE_MSB_MASK, ACE_MULT_BY_WORDSIZE, ACE_TRACE, mask_, max_handle_, MAXSIZE, and size_.

Referenced by clr_bit, and sync.

00206 {
00207   ACE_TRACE ("ACE_Handle_Set::set_max");
00208 #if !defined(ACE_WIN32)
00209   fd_mask * maskp = (fd_mask *)(this->mask_.fds_bits);
00210 
00211   if (this->size_ == 0)
00212     this->max_handle_ = ACE_INVALID_HANDLE;
00213   else
00214     {
00215       int i;
00216 
00217       for (i = ACE_DIV_BY_WORDSIZE (current_max - 1);
00218            maskp[i] == 0;
00219            i--)
00220         continue;
00221 
00222 #if defined (ACE_PSOS)
00223       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i);
00224       for (fd_mask val = maskp[i];
00225            (val & ACE_MSB_MASK) != 0;
00226            val = (val << 1))
00227         this->max_handle_++;
00228 #elif 1 /* !defined(ACE_HAS_BIG_FD_SET) */
00229       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i);
00230       for (fd_mask val = maskp[i];
00231            (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1...
00232            val = (val >> 1) & ACE_MSB_MASK)
00233         this->max_handle_++;
00234 #else
00235       register u_long val = this->mask_.fds_bits[i];
00236       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i)
00237         + ACE_Handle_Set::bitpos(val & ~(val - 1));
00238 #endif /* 1 */
00239     }
00240 
00241   // Do some sanity checking...
00242   if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE)
00243     this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1;
00244 #else
00245   ACE_UNUSED_ARG (current_max);
00246 #endif /* !ACE_WIN32 */
00247 }

void ACE_Handle_Set::sync ACE_HANDLE    max
 

Rescan the underlying <fd_set> up to handle <max> to find the new <max_handle> (highest bit set) and <size> (how many bits set) values. This is useful for evaluating the changes after the handle set has been manipulated in some way other than member functions; for example, after <select> modifies the <fd_set>.

Definition at line 184 of file Handle_Set.cpp.

References ACE_DIV_BY_WORDSIZE, ACE_TRACE, count_bits, mask_, set_max, and size_.

Referenced by ACE_Handle_Set, ACE_TP_Reactor::get_event_for_dispatching, ACE::select, ACE_XtReactor::wait_for_multiple_events, ACE_TkReactor::wait_for_multiple_events, ACE_QtReactor::wait_for_multiple_events, and ACE_FlReactor::wait_for_multiple_events.

00185 {
00186   ACE_TRACE ("ACE_Handle_Set::sync");
00187 #if !defined (ACE_WIN32)
00188   fd_mask *maskp = (fd_mask *)(this->mask_.fds_bits);
00189   this->size_ = 0;
00190 
00191   for (int i = ACE_DIV_BY_WORDSIZE (max - 1);
00192        i >= 0;
00193        i--)
00194     this->size_ += ACE_Handle_Set::count_bits (maskp[i]);
00195 
00196   this->set_max (max);
00197 #else
00198   ACE_UNUSED_ARG (max);
00199 #endif /* !ACE_WIN32 */
00200 }


Friends And Related Function Documentation

friend class ACE_Handle_Set_Iterator [friend]
 

Definition at line 36 of file Handle_Set.h.


Member Data Documentation

ACE_Handle_Set::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 107 of file Handle_Set.h.

fd_set ACE_Handle_Set::mask_ [private]
 

Bitmask.

Definition at line 122 of file Handle_Set.h.

Referenced by ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator, dump, fdset, num_set, operator fd_set *, ACE_Handle_Set_Iterator::operator(), ACE_Handle_Set_Iterator::reset_state, set_max, and sync.

ACE_HANDLE ACE_Handle_Set::max_handle_ [private]
 

Current max handle.

Definition at line 114 of file Handle_Set.h.

Referenced by ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator, clr_bit, dump, max_set, ACE_Handle_Set_Iterator::operator(), reset, ACE_Handle_Set_Iterator::reset_state, set_bit, and set_max.

const char ACE_Handle_Set::nbits_ [static, private]
 

Initial value:

{
  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
  4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8}
Table that maps bytes to counts of the enabled bits in each value from 0 to 255.

Definition at line 64 of file Handle_Set.cpp.

Referenced by count_bits.

int ACE_Handle_Set::size_ [private]
 

Size of the set, i.e., a count of the number of enabled bits.

Definition at line 111 of file Handle_Set.h.

Referenced by clr_bit, fdset, is_set, num_set, operator fd_set *, reset, set_bit, set_max, and sync.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:48:19 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002