summaryrefslogtreecommitdiff
path: root/ace/Handle_Set.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ace/Handle_Set.cpp')
-rw-r--r--ace/Handle_Set.cpp111
1 files changed, 22 insertions, 89 deletions
diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp
index 0648a515032..b09333d144e 100644
--- a/ace/Handle_Set.cpp
+++ b/ace/Handle_Set.cpp
@@ -17,9 +17,9 @@ ACE_Handle_Set::dump (void) const
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, "[ "));
- ACE_DEBUG ((LM_DEBUG, "size_ = %d", this->size_));
+ ACE_DEBUG ((LM_DEBUG, "\nsize_ = %d", this->size_));
ACE_DEBUG ((LM_DEBUG, "\nmax_handle_ = %d", this->max_handle_));
+ ACE_DEBUG ((LM_DEBUG, "\n[ "));
#if defined (ACE_WIN32)
for (size_t i = 0; i < this->mask_.fd_count + 1; i++)
@@ -30,17 +30,10 @@ ACE_Handle_Set::dump (void) const
ACE_DEBUG ((LM_DEBUG, " %d ", i));
#endif /* ACE_WIN32 */
- ACE_DEBUG ((LM_DEBUG, " ]"));
+ ACE_DEBUG ((LM_DEBUG, " ]\n"));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-#if defined (ACE_HAS_BROKEN_BITSHIFT)
-static const ACE_UINT32 MSB_MASK = ~(ACE_UINT32 (1) << ACE_UINT32 (NFDBITS - 1));
-#else
-// This needs to go here to avoid overflow problems on some compilers.
-static const ACE_UINT32 MSB_MASK = ~(1 << (NFDBITS - 1));
-#endif /* ACE_HAS_BROKEN_BITSHIFT */
-
// Table that maps bytes to counts of the enabled bits.
const char ACE_Handle_Set::nbits_[256] =
@@ -86,11 +79,13 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask)
// speed up the count.
int
-ACE_Handle_Set::count_bits (unsigned long n) const
+ACE_Handle_Set::count_bits (u_long n) const
{
ACE_TRACE ("ACE_Handle_Set::count_bits");
- return (ACE_Handle_Set::nbits_[n & 0xff] + ACE_Handle_Set::nbits_[(n >> 8) & 0xff] +
- ACE_Handle_Set::nbits_[(n >> 16) & 0xff] + ACE_Handle_Set::nbits_[n >> 24]);
+ return (ACE_Handle_Set::nbits_[n & 0xff]
+ + ACE_Handle_Set::nbits_[(n >> 8) & 0xff]
+ + ACE_Handle_Set::nbits_[(n >> 16) & 0xff]
+ + ACE_Handle_Set::nbits_[n >> 24]);
}
// Synchronize the underlying FD_SET with the MAX_FD and the SIZE.
@@ -100,16 +95,16 @@ ACE_Handle_Set::sync (ACE_HANDLE max)
{
ACE_TRACE ("ACE_Handle_Set::sync");
#if !defined(ACE_WIN32)
- this->size_ = 0;
+ this->size_ = 0;
- for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
- i >= 0;
- i--)
- this->size_ += count_bits (this->mask_.fds_bits[i]);
+ for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE;
+ i >= 0;
+ i--)
+ this->size_ += count_bits (this->mask_.fds_bits[i]);
- this->set_max (max);
+ this->set_max (max);
#else
- ACE_UNUSED_ARG (max);
+ ACE_UNUSED_ARG (max);
#endif /* !ACE_WIN32 */
}
@@ -120,9 +115,8 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
{
ACE_TRACE ("ACE_Handle_Set::set_max");
#if !defined(ACE_WIN32)
-
if (this->size_ == 0)
- this->max_handle_ = -1;
+ this->max_handle_ = ACE_INVALID_HANDLE;
else
{
int i;
@@ -133,9 +127,10 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
continue;
this->max_handle_ = i * ACE_Handle_Set::WORDSIZE;
+
for (fd_mask val = this->mask_.fds_bits[i];
- (val & ~1) != 0;
- val = (val >> 1) & MSB_MASK)
+ (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1...
+ val = (val >> 1) & ACE_MSB_MASK)
this->max_handle_++;
}
@@ -143,7 +138,7 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max)
if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE)
this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1;
#else
- ACE_UNUSED_ARG(current_max);
+ ACE_UNUSED_ARG (current_max);
#endif /* !ACE_WIN32 */
}
@@ -155,69 +150,7 @@ ACE_Handle_Set_Iterator::dump (void) const
ACE_TRACE ("ACE_Handle_Set_Iterator::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
- ACE_DEBUG ((LM_DEBUG, "num_ = %d", this->num_));
- ACE_DEBUG ((LM_DEBUG, "\nindex_ = %d", this->index_));
+ ACE_DEBUG ((LM_DEBUG, "\nhandle_index_ = %d", this->handle_index_));
+ ACE_DEBUG ((LM_DEBUG, "\nword_num_ = %d", this->word_num_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
-
-void
-ACE_Handle_Set_Iterator::operator++ (void)
-{
- ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
-
-#if defined(ACE_WIN32)
- this->index_++;
-#else /* !ACE_WIN32 */
- this->val_ = (this->val_ >> 1) & MSB_MASK;
- this->num_++;
-
-
- if (this->val_ == 0)
- {
- for (this->index_++;
- this->index_ < ACE_Handle_Set::NUM_WORDS
- && this->handles_.mask_.fds_bits[this->index_] == 0;
- this->index_++)
- continue;
-
- if (this->index_ >= ACE_Handle_Set::NUM_WORDS)
- {
- this->num_ = this->handles_.max_handle_ + 1;
- return;
- }
- else
- {
- this->val_ = this->handles_.mask_.fds_bits[this->index_];
- this->num_ = this->index_ * ACE_Handle_Set::WORDSIZE;
- }
- }
-
- for (; ACE_BIT_DISABLED (this->val_, 1); this->num_++)
- this->val_ = (this->val_ >> 1) & MSB_MASK;
-#endif /* !ACE_WIN32 */
-}
-
-ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &f)
- : handles_ (f),
- num_ (0),
- index_ (0)
-{
- ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
-#if !defined(ACE_WIN32)
- // Loop until we've found the first non-zero bit or we run off the
- // end of the bitset.
- for (;
- this->num_ < ACE_Handle_Set::MAXSIZE
- && this->handles_.mask_.fds_bits[this->index_] == 0;
- this->index_++)
- this->num_ += ACE_Handle_Set::WORDSIZE;
-
- if (this->num_ >= ACE_Handle_Set::MAXSIZE)
- this->num_ = this->handles_.max_handle_ + 1;
- else
- for (this->val_ = this->handles_.mask_.fds_bits[this->index_];
- (ACE_BIT_DISABLED (this->val_, 1)) && this->num_ < ACE_Handle_Set::MAXSIZE;
- this->num_++)
- this->val_ = (this->val_ >> 1) & MSB_MASK;
-#endif /* !ACE_WIN32 */
-}