summaryrefslogtreecommitdiff
path: root/ace/Handle_Set.i
diff options
context:
space:
mode:
Diffstat (limited to 'ace/Handle_Set.i')
-rw-r--r--ace/Handle_Set.i111
1 files changed, 104 insertions, 7 deletions
diff --git a/ace/Handle_Set.i b/ace/Handle_Set.i
index d7577404ea3..db3d7ccb446 100644
--- a/ace/Handle_Set.i
+++ b/ace/Handle_Set.i
@@ -41,7 +41,7 @@ ACE_Handle_Set::set_bit (ACE_HANDLE handle)
if (!this->is_set (handle))
{
#if defined(ACE_WIN32)
- FD_SET ((SOCKET)handle, &this->mask_);
+ FD_SET ((SOCKET) handle, &this->mask_);
#else /* !ACE_WIN32 */
FD_SET (handle, &this->mask_);
this->size_++;
@@ -77,7 +77,7 @@ ACE_INLINE int
ACE_Handle_Set::num_set (void) const
{
ACE_TRACE ("ACE_Handle_Set::num_set");
-#if defined(ACE_WIN32)
+#if defined (ACE_WIN32)
return this->mask_.fd_count;
#else /* !ACE_WIN32 */
return this->size_;
@@ -97,11 +97,108 @@ ACE_INLINE ACE_HANDLE
ACE_Handle_Set_Iterator::operator () (void)
{
ACE_TRACE ("ACE_Handle_Set_Iterator::operator");
-#if defined(ACE_WIN32)
- return this->index_ < this->handles_.mask_.fd_count
- ? (ACE_HANDLE)this->handles_.mask_.fd_array[this->index_]
- : ACE_INVALID_HANDLE;
+#if defined (ACE_WIN32)
+ if (this->handle_index_ < this->handles_.mask_.fd_count)
+ // Return the handle and advance the iterator.
+ return (ACE_HANDLE) this->handles_.mask_.fd_array[this->handle_index_++];
+ else
+ return ACE_INVALID_HANDLE;
+
#else /* !ACE_WIN32 */
- return this->num_ <= this->handles_.max_handle_ ? this->num_ : -1;
+ // No sense searching further than the max_handle_ + 1;
+ ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
+
+ if (this->handle_index_ >= maxhandlep1)
+ // We've seen all the handles we're interested in seeing for this
+ // iterator.
+ return ACE_INVALID_HANDLE;
+ else
+ {
+ ACE_HANDLE result = this->handle_index_;
+
+ // Increment the iterator.
+ this->handle_index_++;
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+
+ // If've examined all the bits in this word, we'll go onto the
+ // next word.
+
+ if (this->word_val_ == 0)
+ {
+ // Loop until we've found the first non-zero bit or we run
+ // past the <maxhandlep1> of the bitset.
+ while (this->handle_index_ < maxhandlep1
+ && this->handles_.mask_.fds_bits[++this->word_num_] == 0)
+ this->handle_index_ += ACE_Handle_Set::WORDSIZE;
+
+ // If the bit index becomes >= the maxhandlep1 that means
+ // there weren't any more bits set that we want to consider.
+ // Therefore, we'll just store the maxhandlep1, which will
+ // cause <operator()> to return <ACE_INVALID_HANDLE>
+ // immediately next time it's called.
+ if (this->handle_index_ >= maxhandlep1)
+ {
+ this->handle_index_ = maxhandlep1;
+ return result;
+ }
+ else
+ // Load the bits of the next word.
+ this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_];
+ }
+
+ // Loop until we get <word_val_> to have its least significant
+ // bit enabled, keeping track of which <handle_index> this
+ // represents (this information is used by subsequent calls to
+ // <operator()>).
+
+ for (;
+ ACE_BIT_DISABLED (this->word_val_, 1);
+ this->handle_index_++)
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+
+ return result;
#endif /* ACE_WIN32 */
+ }
+}
+
+ACE_INLINE void
+ACE_Handle_Set_Iterator::operator++ (void)
+{
+ ACE_TRACE ("ACE_Handle_Set_Iterator::operator++");
+
+ // This is now a no-op.
+}
+
+ACE_INLINE
+ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs)
+ : handles_ (hs),
+ handle_index_ (0),
+ word_num_ (-1)
+{
+ ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator");
+#if !defined(ACE_WIN32)
+ // No sense searching further than the max_handle_ + 1;
+ ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1;
+
+ // Loop until we've found the first non-zero bit or we run past the
+ // <maxhandlep1> of the bitset.
+ while (this->handle_index_ < maxhandlep1
+ && this->handles_.mask_.fds_bits[++this->word_num_] == 0)
+ this->handle_index_ += ACE_Handle_Set::WORDSIZE;
+
+ // If the bit index becomes >= the maxhandlep1 that means there weren't
+ // any bits set. Therefore, we'll just store the maxhandlep1, which will
+ // cause <operator()> to return <ACE_INVALID_HANDLE> immediately.
+ if (this->handle_index_ >= maxhandlep1)
+ this->handle_index_ = maxhandlep1;
+ else
+ // Loop until we get <word_val_> to have its least significant bit
+ // enabled, keeping track of which <handle_index> this represents
+ // (this information is used by <operator()>).
+ for (this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_];
+ ACE_BIT_DISABLED (this->word_val_, 1)
+ && this->handle_index_ < maxhandlep1;
+ this->handle_index_++)
+ this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
+#endif /* !ACE_WIN32 */
}