#include <Handle_Set.h>
Collaboration diagram for ACE_Handle_Set_Iterator:

Public Member Functions | |
| ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs) | |
| Constructor. | |
| ~ACE_Handle_Set_Iterator (void) | |
| Default dtor. | |
| void | reset_state (void) |
| ACE_HANDLE | operator() (void) |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Attributes | |
| const ACE_Handle_Set & | handles_ |
| The we are iterating through. | |
| u_int | handle_index_ |
| Index of the bit we're examining in the current word. | |
| int | word_num_ |
| Number of the word we're iterating over (typically between 0..7). | |
Definition at line 174 of file Handle_Set.h.
|
|
Constructor.
Definition at line 437 of file Handle_Set.cpp. References ACE_BIT_DISABLED, ACE_DIV_BY_WORDSIZE, ACE_MSB_MASK, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, and word_num_.
00438 : handles_ (hs), 00439 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32) 00440 handle_index_ (0), 00441 word_num_ (-1) 00442 #elif defined (ACE_HAS_BIG_FD_SET) 00443 oldlsb_ (0), 00444 word_max_ (hs.max_handle_ == ACE_INVALID_HANDLE 00445 ? 0 00446 : ((ACE_DIV_BY_WORDSIZE (hs.max_handle_)) + 1)) 00447 #endif /* ACE_HAS_BIG_FD_SET */ 00448 { 00449 ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator"); 00450 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET) 00451 // No sense searching further than the max_handle_ + 1; 00452 ACE_HANDLE maxhandlep1 = 00453 this->handles_.max_handle_ + 1; 00454 00455 fd_mask *maskp = 00456 (fd_mask *)(this->handles_.mask_.fds_bits); 00457 00458 // Loop until we've found the first non-zero bit or we run past the 00459 // <maxhandlep1> of the bitset. 00460 while (this->handle_index_ < maxhandlep1 00461 && maskp[++this->word_num_] == 0) 00462 this->handle_index_ += ACE_Handle_Set::WORDSIZE; 00463 00464 // If the bit index becomes >= the maxhandlep1 that means there 00465 // weren't any bits set. Therefore, we'll just store the 00466 // maxhandlep1, which will cause <operator()> to return 00467 // <ACE_INVALID_HANDLE> immediately. 00468 if (this->handle_index_ >= maxhandlep1) 00469 this->handle_index_ = maxhandlep1; 00470 else 00471 // Loop until we get <word_val_> to have its least significant bit 00472 // enabled, keeping track of which <handle_index> this represents 00473 // (this information is used by <operator()>). 00474 #if defined (ACE_TANDEM_NSK_BIT_ORDER) 00475 // bits are in reverse order, MSB (sign bit) = bit 0. 00476 for (this->word_val_ = maskp[this->word_num_]; 00477 this->word_val_ > 0; 00478 this->word_val_ = (this->word_val_ << 1)) 00479 this->handle_index_++; 00480 # else 00481 for (this->word_val_ = maskp[this->word_num_]; 00482 ACE_BIT_DISABLED (this->word_val_, 1) 00483 && this->handle_index_ < maxhandlep1; 00484 this->handle_index_++) 00485 this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK; 00486 # endif /* ACE_TANDEM_NSK_BIT_ORDER */ 00487 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET) 00488 if (this->word_max_==0) 00489 { 00490 this->word_num_ = -1; 00491 this->word_val_ = 0; 00492 } 00493 else 00494 { 00495 this->word_num_ = 00496 ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1; 00497 this->word_val_ = 0; 00498 } 00499 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */ 00500 } |
|
|
Default dtor.
Definition at line 189 of file Handle_Set.inl.
00190 {
00191 }
|
|
|
Dump the state of an object.
Definition at line 265 of file Handle_Set.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, and LM_DEBUG.
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_TEXT ("\nhandle_index_ = %d"), this->handle_index_));
00273 #elif defined(ACE_HAS_BIG_FD_SET)
00274 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nword_max_ = %d"), this->word_max_));
00275 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nword_val_ = %d"), this->word_val_));
00276 #endif
00277 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nword_num_ = %d"), this->word_num_));
00278 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00279 #endif /* ACE_HAS_DUMP */
00280 }
|
|
|
"Next" operator. Returns the next unseen ACE_HANDLE in the up to <handle_set_.max_handle_>). When all the handles have been seen returns . Advances the iterator automatically, so you need not call <operator++> (which is now obsolete). Definition at line 283 of file Handle_Set.cpp. References ACE_BIT_DISABLED, ACE_MSB_MASK, ACE_MULT_BY_WORDSIZE, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, and word_num_.
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 }
|
|
|
Reset the state of the iterator by reinitializing the state that we maintain. Definition at line 504 of file Handle_Set.cpp. References ACE_BIT_DISABLED, ACE_DIV_BY_WORDSIZE, ACE_MSB_MASK, ACE_TRACE, handle_index_, handles_, ACE_Handle_Set::mask_, ACE_Handle_Set::max_handle_, and word_num_.
00505 {
00506 ACE_TRACE ("ACE_Handle_Set_Iterator::reset_state");
00507
00508 #if !defined (ACE_HAS_BIG_FD_SET) || defined (ACE_WIN32)
00509 this->handle_index_ = 0;
00510 this->word_num_ = -1;
00511 #elif defined (ACE_HAS_BIG_FD_SET)
00512 this->oldlsb_ = 0;
00513 this->word_max_ =
00514 this->handles_.max_handle_ == ACE_INVALID_HANDLE ? 0
00515 : ((ACE_DIV_BY_WORDSIZE (this->handles_.max_handle_)) + 1);
00516 #endif /* ACE_HAS_BIG_FD_SET */
00517
00518 #if !defined (ACE_WIN32) && !defined (ACE_HAS_BIG_FD_SET)
00519 // No sense searching further than the max_handle_ + 1;
00520 ACE_HANDLE maxhandlep1 =
00521 this->handles_.max_handle_ + 1;
00522
00523 fd_mask *maskp =
00524 (fd_mask *)(this->handles_.mask_.fds_bits);
00525
00526 // Loop until we've found the first non-zero bit or we run past the
00527 // <maxhandlep1> of the bitset.
00528 while (this->handle_index_ < maxhandlep1
00529 && maskp[++this->word_num_] == 0)
00530 this->handle_index_ += ACE_Handle_Set::WORDSIZE;
00531
00532 // If the bit index becomes >= the maxhandlep1 that means there
00533 // weren't any bits set. Therefore, we'll just store the
00534 // maxhandlep1, which will cause <operator()> to return
00535 // <ACE_INVALID_HANDLE> immediately.
00536 if (this->handle_index_ >= maxhandlep1)
00537 this->handle_index_ = maxhandlep1;
00538 else
00539 // Loop until we get <word_val_> to have its least significant bit
00540 // enabled, keeping track of which <handle_index> this represents
00541 // (this information is used by <operator()>).
00542 #if defined (ACE_TANDEM_NSK_BIT_ORDER)
00543 // bits are in reverse order, MSB (sign bit) = bit 0.
00544 for (this->word_val_ = maskp[this->word_num_];
00545 this->word_val_ > 0;
00546 this->word_val_ = (this->word_val_ << 1))
00547 this->handle_index_++;
00548 # else
00549 for (this->word_val_ = maskp[this->word_num_];
00550 ACE_BIT_DISABLED (this->word_val_, 1)
00551 && this->handle_index_ < maxhandlep1;
00552 this->handle_index_++)
00553 this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK;
00554 # endif /* ACE_TANDEM_NSK_BIT_ORDER */
00555 #elif !defined (ACE_WIN32) && defined (ACE_HAS_BIG_FD_SET)
00556 if (this->word_max_==0)
00557 {
00558 this->word_num_ = -1;
00559 this->word_val_ = 0;
00560 }
00561 else
00562 {
00563 this->word_num_ =
00564 ACE_DIV_BY_WORDSIZE (this->handles_.min_handle_) - 1;
00565 this->word_val_ = 0;
00566 }
00567 #endif /* !ACE_WIN32 && !ACE_HAS_BIG_FD_SET */
00568 }
|
|
|
Declare the dynamic allocation hooks.
Definition at line 200 of file Handle_Set.h. |
|
|
Index of the bit we're examining in the current word.
Definition at line 208 of file Handle_Set.h. Referenced by ACE_Handle_Set_Iterator(), operator()(), and reset_state(). |
|
|
The we are iterating through.
Definition at line 204 of file Handle_Set.h. Referenced by ACE_Handle_Set_Iterator(), operator()(), and reset_state(). |
|
|
Number of the word we're iterating over (typically between 0..7).
Definition at line 217 of file Handle_Set.h. Referenced by ACE_Handle_Set_Iterator(), operator()(), and reset_state(). |
1.3.6