Handle_Set.cpp

Go to the documentation of this file.
00001 // Handle_Set.cpp
00002 // Handle_Set.cpp,v 4.52 2006/05/05 07:42:26 jwillemsen Exp
00003 
00004 #include "ace/Handle_Set.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 #include "ace/Handle_Set.inl"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 #include "ace/OS_NS_string.h"
00011 
00012 ACE_RCSID(ace, Handle_Set, "Handle_Set.cpp,v 4.52 2006/05/05 07:42:26 jwillemsen Exp")
00013 
00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00015 
00016 ACE_ALLOC_HOOK_DEFINE(ACE_Handle_Set)
00017 
00018   // ACE_MSB_MASK is only used here.
00019   // This needs to go here to avoid overflow problems on some compilers.
00020 #if defined (ACE_WIN32)
00021    //  Does ACE_WIN32 have an fd_mask?
00022 #  define ACE_MSB_MASK (~(1 << (NFDBITS - 1)))
00023 #else  /* ! ACE_WIN32 */
00024 #  define ACE_MSB_MASK (~((fd_mask) 1 << (NFDBITS - 1)))
00025 #endif /* ! ACE_WIN32 */
00026 
00027 #if defined (__BORLANDC__) && !defined (ACE_WIN32)
00028 // The Borland C++ compiler on Linux also doesn't have fds_bits, but has __fds_bits.
00029 #define fds_bits __fds_bits
00030 #endif
00031 
00032 #if defined (linux) && __GLIBC__ > 1 && __GLIBC_MINOR__ >= 1 && !defined (_XOPEN_SOURCE)
00033   // XPG4.2 requires the fds_bits member name, so it is not enabled by
00034   // default on Linux/glibc-2.1.x systems.  Instead use "__fds_bits."
00035   // Ugly, but "what are you going to do?" 8-)
00036 #define fds_bits __fds_bits
00037 #endif  /* linux && __GLIBC__ > 1 && __GLIBC_MINOR__ >= 1 && !_XOPEN_SOURCE */
00038 
00039 void
00040 ACE_Handle_Set::dump (void) const
00041 {
00042 #if defined (ACE_HAS_DUMP)
00043   ACE_TRACE ("ACE_Handle_Set::dump");
00044 
00045   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00046 
00047   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nsize_ = %d"), this->size_));
00048   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nmax_handle_ = %d"), this->max_handle_));
00049   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n[ ")));
00050 
00051 #if defined (ACE_WIN32)
00052   for (size_t i = 0; i < (size_t) this->mask_.fd_count + 1; i++)
00053     ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" %x "), this->mask_.fd_array[i]));
00054 #else /* !ACE_WIN32 */
00055   for (ACE_HANDLE i = 0; i < this->max_handle_ + 1; i++)
00056     if (this->is_set (i))
00057       ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" %d "), i));
00058 #endif /* ACE_WIN32 */
00059 
00060   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" ]\n")));
00061   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00062 #endif /* ACE_HAS_DUMP */
00063 }
00064 
00065 // Table that maps bytes to counts of the enabled bits in each value
00066 // from 0 to 255,
00067 //
00068 // nbits_[0] == 0
00069 //
00070 // because there are no bits enabled for the value 0.
00071 //
00072 // nbits_[5] == 2
00073 //
00074 // because there are 2 bits enabled in the value 5, i.e., it's
00075 // 101 in binary.
00076 
00077 const char ACE_Handle_Set::nbits_[256] =
00078 {
00079   0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
00080   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
00081   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
00082   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00083   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
00084   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00085   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00086   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
00087   1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
00088   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00089   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00090   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
00091   2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
00092   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
00093   3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
00094   4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
00095 
00096 // Constructor, initializes the bitmask to all 0s.
00097 
00098 ACE_Handle_Set::ACE_Handle_Set (void)
00099 {
00100   ACE_TRACE ("ACE_Handle_Set::ACE_Handle_Set");
00101   this->reset ();
00102 }
00103 
00104 ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
00105 {
00106   ACE_TRACE ("ACE_Handle_Set::ACE_Handle_Set");
00107   this->reset ();
00108   ACE_OS::memcpy ((void *) &this->mask_,
00109                   (void *) &fd_mask,
00110                   sizeof this->mask_);
00111 #if !defined (ACE_WIN32)
00112   this->sync (ACE_Handle_Set::MAXSIZE);
00113 #if defined (ACE_HAS_BIG_FD_SET)
00114   this->min_handle_ = 0;
00115 #endif /* ACE_HAS_BIG_FD_SET */
00116 #endif /* !ACE_WIN32 */
00117 }
00118 
00119 // Counts the number of bits enabled in N.  Uses a table lookup to
00120 // speed up the count.
00121 
00122 int
00123 ACE_Handle_Set::count_bits (u_long n)
00124 {
00125 
00126  ACE_TRACE ("ACE_Handle_Set::count_bits");
00127 #if defined (ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT)
00128   register int rval = 0;
00129 
00130   // Count the number of enabled bits in <n>.  This algorithm is very
00131   // fast, i.e., O(enabled bits in n).
00132 
00133   for (register u_long m = n;
00134        m != 0;
00135        m &= m - 1)
00136     rval++;
00137 
00138   return rval;
00139 #else
00140    return (ACE_Handle_Set::nbits_[n & 0xff]
00141           + ACE_Handle_Set::nbits_[(n >> 8) & 0xff]
00142           + ACE_Handle_Set::nbits_[(n >> 16) & 0xff]
00143           + ACE_Handle_Set::nbits_[(n >> 24) & 0xff]);
00144 #endif /* ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT */
00145 }
00146 
00147 #if defined (ACE_HAS_BIG_FD_SET)
00148 // Find the bit position counting from right to left worst case
00149 // (1<<31) is 8.
00150 
00151 int
00152 ACE_Handle_Set::bitpos (u_long bit)
00153 {
00154   register int l = 0;
00155   register u_long n = bit - 1;
00156 
00157   // This is a fast count method when have the most significative bit.
00158 
00159   while (n >> 8)
00160     {
00161       n >>= 8;
00162       l += 8;
00163     }
00164 
00165   // Is greater than 15?
00166   if (n & 16)
00167     {
00168       n >>= 4;
00169       l += 4;
00170     }
00171 
00172   // Count number remaining bits.
00173   while (n != 0)
00174     {
00175       n &= n - 1;
00176       l++;
00177     }
00178   return l;
00179 }
00180 #endif /* ACE_HAS_BIG_FD_SET */
00181 
00182 // Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
00183 
00184 #if defined (ACE_USE_SHIFT_FOR_EFFICIENCY)
00185 // These don't work because shifting right 3 bits is not the same as
00186 // dividing by 3, e.g., dividing by 8 requires shifting right 3 bits.
00187 // In order to do the shift, we need to calculate the number of bits
00188 // at some point.
00189 #define ACE_DIV_BY_WORDSIZE(x) ((x) >> ((int) ACE_Handle_Set::WORDSIZE))
00190 #define ACE_MULT_BY_WORDSIZE(x) ((x) << ((int) ACE_Handle_Set::WORDSIZE))
00191 #else
00192 #define ACE_DIV_BY_WORDSIZE(x) ((x) / ((int) ACE_Handle_Set::WORDSIZE))
00193 #define ACE_MULT_BY_WORDSIZE(x) ((x) * ((int) ACE_Handle_Set::WORDSIZE))
00194 #endif /* ACE_USE_SHIFT_FOR_EFFICIENCY */
00195 
00196 void
00197 ACE_Handle_Set::sync (ACE_HANDLE max)
00198 {
00199   ACE_TRACE ("ACE_Handle_Set::sync");
00200 #if !defined (ACE_WIN32)
00201   fd_mask *maskp = (fd_mask *)(this->mask_.fds_bits);
00202   this->size_ = 0;
00203 
00204   for (int i = ACE_DIV_BY_WORDSIZE (max - 1);
00205        i >= 0;
00206        i--)
00207     this->size_ += ACE_Handle_Set::count_bits (maskp[i]);
00208 
00209   this->set_max (max);
00210 #else
00211   ACE_UNUSED_ARG (max);
00212 #endif /* !ACE_WIN32 */
00213 }
00214 
00215 // Resets the MAX_FD after a clear of the original MAX_FD.
00216 
00217 void
00218 ACE_Handle_Set::set_max (ACE_HANDLE current_max)
00219 {
00220   ACE_TRACE ("ACE_Handle_Set::set_max");
00221 #if !defined(ACE_WIN32)
00222   fd_mask * maskp = (fd_mask *)(this->mask_.fds_bits);
00223 
00224   if (this->size_ == 0)
00225     this->max_handle_ = ACE_INVALID_HANDLE;
00226   else
00227     {
00228       int i;
00229 
00230       for (i = ACE_DIV_BY_WORDSIZE (current_max - 1);
00231            maskp[i] == 0;
00232            i--)
00233         continue;
00234 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00235       // bits are in reverse order, MSB (sign bit) = bit 0.
00236       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i);
00237       for (fd_mask val = maskp[i];
00238            (val & ACE_MSB_MASK) != 0;
00239            val = (val << 1))
00240         ++this->max_handle_;
00241 #elif 1 /* !defined(ACE_HAS_BIG_FD_SET) */
00242       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i);
00243       for (fd_mask val = maskp[i];
00244            (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1...
00245            val = (val >> 1) & ACE_MSB_MASK)
00246         ++this->max_handle_;
00247 #else
00248       register u_long val = this->mask_.fds_bits[i];
00249       this->max_handle_ = ACE_MULT_BY_WORDSIZE (i)
00250         + ACE_Handle_Set::bitpos(val & ~(val - 1));
00251 #endif /* 1 */
00252     }
00253 
00254   // Do some sanity checking...
00255   if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE)
00256     this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1;
00257 #else
00258   ACE_UNUSED_ARG (current_max);
00259 #endif /* !ACE_WIN32 */
00260 }
00261 
00262 ACE_ALLOC_HOOK_DEFINE(ACE_Handle_Set_Iterator)
00263 
00264 void
00265 ACE_Handle_Set_Iterator::dump (void) const
00266 {
00267 #if defined (ACE_HAS_DUMP)
00268   ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
00269 
00270   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00271 #if defined(ACE_WIN32) || !defined(ACE_HAS_BIG_FD_SET)
00272   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nhandle_index_ = %d"), this->handle_index_));
00273 #elif defined(ACE_HAS_BIG_FD_SET)
00274   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_max_ = %d"), this->word_max_));
00275   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_val_ = %d"), this->word_val_));
00276 #endif
00277   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nword_num_ = %d"), this->word_num_));
00278   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00279 #endif /* ACE_HAS_DUMP */
00280 }
00281 
00282 ACE_HANDLE
00283 ACE_Handle_Set_Iterator::operator () (void)
00284 {
00285   ACE_TRACE ("ACE_Handle_Set_Iterator::operator");
00286 #if defined (ACE_WIN32)
00287   if (this->handle_index_ < this->handles_.mask_.fd_count)
00288     // Return the handle and advance the iterator.
00289     return (ACE_HANDLE) this->handles_.mask_.fd_array[this->handle_index_++];
00290   else
00291     return ACE_INVALID_HANDLE;
00292 
00293 #elif !defined (ACE_HAS_BIG_FD_SET) /* !ACE_WIN32 */
00294   // No sense searching further than the max_handle_ + 1;
00295   ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
00296 
00297   // HP-UX 11 plays some games with the fd_mask type - fd_mask is
00298   // defined as an int_32t, but the fds_bits is an array of longs.
00299   // This makes plainly indexing through the array by hand tricky,
00300   // since the FD_* macros treat the array as int32_t.  So the bits
00301   // are in the right place for int32_t, even though the array is
00302   // long.  This, they say, is to preserve the same in-memory layout
00303   // for 32-bit and 64-bit processes.  So, we play the same game as
00304   // the FD_* macros to get the bits right.  On all other systems,
00305   // this amounts to practically a NOP, since this is what would have
00306   // been done anyway, without all this type jazz.
00307   fd_mask * maskp = (fd_mask *)(this->handles_.mask_.fds_bits);
00308 
00309   if (this->handle_index_ >= maxhandlep1)
00310     // We've seen all the handles we're interested in seeing for this
00311     // iterator.
00312     return ACE_INVALID_HANDLE;
00313   else
00314     {
00315       ACE_HANDLE result = this->handle_index_;
00316 
00317       // Increment the iterator and advance to the next bit in this
00318       // word.
00319       this->handle_index_++;
00320 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00321       // bits are in reverse order, MSB (sign bit) = bit 0.
00322       this->word_val_ = (this->word_val_ << 1);
00323 #  else
00324       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00325 #  endif /* ACE_TANDEM_NSK_BIT_ORDER */
00326 
00327       // If we've examined all the bits in this word, we'll go onto
00328       // the next word.
00329 
00330       if (this->word_val_ == 0)
00331         {
00332           // Start the handle_index_ at the beginning of the next word
00333           // and then loop until we've found the first non-zero bit or
00334           // we run past the <maxhandlep1> of the bitset.
00335 
00336           for (this->handle_index_ = ACE_MULT_BY_WORDSIZE(++this->word_num_);
00337                this->handle_index_ < maxhandlep1
00338                  && maskp[this->word_num_] == 0;
00339                this->word_num_++)
00340             this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00341 
00342           // If the bit index becomes >= the maxhandlep1 that means
00343           // there weren't any more bits set that we want to consider.
00344           // Therefore, we'll just store the maxhandlep1, which will
00345           // cause <operator()> to return <ACE_INVALID_HANDLE>
00346           // immediately next time it's called.
00347           if (this->handle_index_ >= maxhandlep1)
00348             {
00349               this->handle_index_ = maxhandlep1;
00350               return result;
00351             }
00352           else
00353             // Load the bits of the next word.
00354             this->word_val_ = maskp[this->word_num_];
00355         }
00356 
00357       // Loop until we get <word_val_> to have its least significant
00358       // bit enabled, keeping track of which <handle_index> this
00359       // represents (this information is used by subsequent calls to
00360       // <operator()>).
00361 
00362 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00363       // bits are in reverse order, MSB (sign bit) = bit 0.
00364       for (;
00365            this->word_val_ > 0;
00366            this->word_val_ = (this->word_val_ << 1))
00367         this->handle_index_++;
00368 #  else
00369       for (;
00370            ACE_BIT_DISABLED (this->word_val_, 1);
00371            this->handle_index_++)
00372         this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00373 #  endif /* ACE_TANDEM_NSK_BIT_ORDER */
00374 
00375       return result;
00376     }
00377 #else /* !ACE_HAS_BIG_FD_SET */
00378    // Find the first word in fds_bits with bit on
00379    register u_long lsb = this->word_val_;
00380 
00381    if (lsb == 0)
00382      {
00383        do
00384          {
00385            // We have exceeded the word count in Handle_Set?
00386            if (++this->word_num_ >= this->word_max_)
00387              return ACE_INVALID_HANDLE;
00388 
00389            lsb = this->handles_.mask_.fds_bits[this->word_num_];
00390          }
00391        while (lsb == 0);
00392 
00393        // Set index to word boundary.
00394        this->handle_index_ = ACE_MULT_BY_WORDSIZE (this->word_num_);
00395 
00396        // Put new word_val.
00397        this->word_val_ = lsb;
00398 
00399        // Find the least significative bit.
00400        lsb &= ~(lsb - 1);
00401 
00402        // Remove least significative bit.
00403        this->word_val_ ^= lsb;
00404 
00405        // Save to calculate bit distance.
00406        this->oldlsb_ = lsb;
00407 
00408        // Move index to least significative bit.
00409        while (lsb >>= 1)
00410          this->handle_index_++;
00411      }
00412    else
00413      {
00414         // Find the least significative bit.
00415         lsb &= ~(lsb - 1);
00416 
00417         // Remove least significative bit.
00418         this->word_val_ ^= lsb;
00419 
00420         register u_long n = lsb - this->oldlsb_;
00421 
00422         // Move index to bit distance between new lsb and old lsb.
00423         do
00424           {
00425             this->handle_index_++;
00426             n &= n >> 1;
00427           }
00428         while (n != 0);
00429 
00430         this->oldlsb_ = lsb;
00431       }
00432 
00433    return this->handle_index_;
00434 #endif /* ACE_WIN32 */
00435 }
00436 
00437 void
00438 ACE_Handle_Set_Iterator::operator++ (void)
00439 {
00440   ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
00441 
00442   // This is now a no-op.
00443 }
00444 
00445 ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
00446   : handles_ (hs),
00447 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
00448     handle_index_ (0),
00449     word_num_ (-1)
00450 #elif defined (ACE_HAS_BIG_FD_SET)
00451     oldlsb_ (0),
00452     word_max_ (hs.max_handle_ == ACE_INVALID_HANDLE
00453                ? 0
00454                : ((ACE_DIV_BY_WORDSIZE (hs.max_handle_)) + 1))
00455 #endif /* ACE_HAS_BIG_FD_SET */
00456 {
00457   ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
00458 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET)
00459   // No sense searching further than the max_handle_ + 1;
00460   ACE_HANDLE maxhandlep1 =
00461     this->handles_.max_handle_ + 1;
00462 
00463   fd_mask *maskp =
00464     (fd_mask *)(this->handles_.mask_.fds_bits);
00465 
00466   // Loop until we've found the first non-zero bit or we run past the
00467   // <maxhandlep1> of the bitset.
00468   while (this->handle_index_ < maxhandlep1
00469          && maskp[++this->word_num_] == 0)
00470     this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00471 
00472   // If the bit index becomes >= the maxhandlep1 that means there
00473   // weren't any bits set.  Therefore, we'll just store the
00474   // maxhandlep1, which will cause <operator()> to return
00475   // <ACE_INVALID_HANDLE> immediately.
00476   if (this->handle_index_ >= maxhandlep1)
00477     this->handle_index_ = maxhandlep1;
00478   else
00479     // Loop until we get <word_val_> to have its least significant bit
00480     // enabled, keeping track of which <handle_index> this represents
00481     // (this information is used by <operator()>).
00482 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00483     // bits are in reverse order, MSB (sign bit) = bit 0.
00484     for (this->word_val_ = maskp[this->word_num_];
00485          this->word_val_ > 0;
00486          this->word_val_ = (this->word_val_ << 1))
00487       this->handle_index_++;
00488 #  else
00489     for (this->word_val_ = maskp[this->word_num_];
00490          ACE_BIT_DISABLED (this->word_val_, 1)
00491            && this->handle_index_ < maxhandlep1;
00492          this->handle_index_++)
00493       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00494 #  endif /* ACE_TANDEM_NSK_BIT_ORDER */
00495 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET)
00496     if (this->word_max_==0)
00497       {
00498         this->word_num_ = -1;
00499         this->word_val_ = 0;
00500       }
00501     else
00502       {
00503         this->word_num_ =
00504           ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1;
00505         this->word_val_ = 0;
00506       }
00507 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
00508 }
00509 
00510 
00511 void
00512 ACE_Handle_Set_Iterator::reset_state (void)
00513 {
00514   ACE_TRACE ("ACE_Handle_Set_Iterator::reset_state");
00515 
00516 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
00517   this->handle_index_  = 0;
00518   this->word_num_ = -1;
00519 #elif defined (ACE_HAS_BIG_FD_SET)
00520   this->oldlsb_ = 0;
00521   this->word_max_  =
00522     this->handles_.max_handle_ == ACE_INVALID_HANDLE  ? 0
00523     : ((ACE_DIV_BY_WORDSIZE (this->handles_.max_handle_)) + 1);
00524 #endif /* ACE_HAS_BIG_FD_SET */
00525 
00526 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET)
00527   // No sense searching further than the max_handle_ + 1;
00528   ACE_HANDLE maxhandlep1 =
00529     this->handles_.max_handle_ + 1;
00530 
00531   fd_mask *maskp =
00532     (fd_mask *)(this->handles_.mask_.fds_bits);
00533 
00534   // Loop until we've found the first non-zero bit or we run past the
00535   // <maxhandlep1> of the bitset.
00536   while (this->handle_index_ < maxhandlep1
00537          && maskp[++this->word_num_] == 0)
00538     this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00539 
00540   // If the bit index becomes >= the maxhandlep1 that means there
00541   // weren't any bits set.  Therefore, we'll just store the
00542   // maxhandlep1, which will cause <operator()> to return
00543   // <ACE_INVALID_HANDLE> immediately.
00544   if (this->handle_index_ >= maxhandlep1)
00545     this->handle_index_ = maxhandlep1;
00546   else
00547     // Loop until we get <word_val_> to have its least significant bit
00548     // enabled, keeping track of which <handle_index> this represents
00549     // (this information is used by <operator()>).
00550 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00551     // bits are in reverse order, MSB (sign bit) = bit 0.
00552     for (this->word_val_ = maskp[this->word_num_];
00553          this->word_val_ > 0;
00554          this->word_val_ = (this->word_val_ << 1))
00555       this->handle_index_++;
00556 #  else
00557     for (this->word_val_ = maskp[this->word_num_];
00558          ACE_BIT_DISABLED (this->word_val_, 1)
00559            && this->handle_index_ < maxhandlep1;
00560          this->handle_index_++)
00561       this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00562 #  endif /* ACE_TANDEM_NSK_BIT_ORDER */
00563 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET)
00564     if (this->word_max_==0)
00565       {
00566         this->word_num_ = -1;
00567         this->word_val_ = 0;
00568       }
00569     else
00570       {
00571         this->word_num_ =
00572           ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1;
00573         this->word_val_ = 0;
00574       }
00575 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
00576 }
00577 
00578 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:51 2006 for ACE by doxygen 1.3.6