C++ wrapper facade for the socket fd_set abstraction.
More...
#include <Handle_Set.h>
Public Types | |
| enum | { MAXSIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE } |
Public Member Functions | |
| ACE_Handle_Set (void) | |
| Constructor, initializes the bitmask to all 0s. | |
| ACE_Handle_Set (const fd_set &mask) | |
| void | reset (void) |
| Initialize the bitmask to all 0s and reset the associated fields. | |
| int | is_set (ACE_HANDLE handle) const |
| void | set_bit (ACE_HANDLE handle) |
| void | clr_bit (ACE_HANDLE handle) |
| int | num_set (void) const |
| Returns a count of the number of enabled bits. | |
| ACE_HANDLE | max_set (void) const |
| Returns the number of the large bit. | |
| void | sync (ACE_HANDLE max) |
| operator fd_set * () | |
| fd_set * | fdset (void) |
| ACE_Handle_Set & | operator= (const ACE_Handle_Set &) |
| Assignment operator optimizes for cases where <size_> == 0. | |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Types | |
| enum | { WORDSIZE = NFDBITS, NUM_WORDS = howmany (MAXSIZE, NFDBITS), NBITS = 256 } |
Private Member Functions | |
| void | set_max (ACE_HANDLE max) |
Static Private Member Functions | |
| static int | count_bits (u_long n) |
| static int | bitpos (u_long bit) |
| Find the position of the bit counting from right to left. | |
Private Attributes | |
| int | size_ |
| Size of the set, i.e., a count of the number of enabled bits. | |
| ACE_HANDLE | max_handle_ |
| Current max handle. | |
| ACE_HANDLE | min_handle_ |
| Current min handle. | |
| fd_set | mask_ |
| Bitmask. | |
Static Private Attributes | |
| static const char | nbits_ [NBITS] |
Friends | |
| class | ACE_Handle_Set_Iterator |
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 49 of file Handle_Set.h.
| anonymous enum |
Definition at line 56 of file Handle_Set.h.
00057 { 00058 MAXSIZE = ACE_DEFAULT_SELECT_REACTOR_SIZE 00059 };
anonymous enum [private] |
| ACE_Handle_Set::ACE_Handle_Set | ( | void | ) |
Constructor, initializes the bitmask to all 0s.
Definition at line 93 of file Handle_Set.cpp.
| ACE_Handle_Set::ACE_Handle_Set | ( | const fd_set & | mask | ) |
Constructor, initializes the handle set from a given mask.
Definition at line 99 of file Handle_Set.cpp.
00100 { 00101 ACE_TRACE ("ACE_Handle_Set::ACE_Handle_Set"); 00102 this->reset (); 00103 ACE_OS::memcpy ((void *) &this->mask_, 00104 (void *) &fd_mask, 00105 sizeof this->mask_); 00106 #if !defined (ACE_WIN32) 00107 this->sync (ACE_Handle_Set::MAXSIZE); 00108 #if defined (ACE_HAS_BIG_FD_SET) 00109 this->min_handle_ = 0; 00110 #endif /* ACE_HAS_BIG_FD_SET */ 00111 #endif /* !ACE_WIN32 */ 00112 }
| static int ACE_Handle_Set::bitpos | ( | u_long | bit | ) | [static, private] |
Find the position of the bit counting from right to left.
| 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 131 of file Handle_Set.inl.
00132 { 00133 ACE_TRACE ("ACE_Handle_Set::clr_bit"); 00134 00135 if ((handle != ACE_INVALID_HANDLE) && 00136 (this->is_set (handle))) 00137 { 00138 FD_CLR ((ACE_SOCKET) handle, 00139 &this->mask_); 00140 --this->size_; 00141 00142 #if !defined (ACE_WIN32) 00143 if (handle == this->max_handle_) 00144 this->set_max (this->max_handle_); 00145 #endif /* !ACE_WIN32 */ 00146 } 00147 }
| 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 118 of file Handle_Set.cpp.
00119 { 00120 00121 ACE_TRACE ("ACE_Handle_Set::count_bits"); 00122 #if defined (ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT) 00123 register int rval = 0; 00124 00125 // Count the number of enabled bits in <n>. This algorithm is very 00126 // fast, i.e., O(enabled bits in n). 00127 00128 for (register u_long m = n; 00129 m != 0; 00130 m &= m - 1) 00131 rval++; 00132 00133 return rval; 00134 #else 00135 return (ACE_Handle_Set::nbits_[n & 0xff] 00136 + ACE_Handle_Set::nbits_[(n >> 8) & 0xff] 00137 + ACE_Handle_Set::nbits_[(n >> 16) & 0xff] 00138 + ACE_Handle_Set::nbits_[(n >> 24) & 0xff]); 00139 #endif /* ACE_HAS_HANDLE_SET_OPTIMIZED_FOR_SELECT */ 00140 }
| void ACE_Handle_Set::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 35 of file Handle_Set.cpp.
00036 { 00037 #if defined (ACE_HAS_DUMP) 00038 ACE_TRACE ("ACE_Handle_Set::dump"); 00039 00040 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00041 00042 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nsize_ = %d"), this->size_)); 00043 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmax_handle_ = %d"), this->max_handle_)); 00044 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n[ "))); 00045 00046 #if defined (ACE_WIN32) 00047 for (size_t i = 0; i < (size_t) this->mask_.fd_count + 1; i++) 00048 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" %x "), this->mask_.fd_array[i])); 00049 #else /* !ACE_WIN32 */ 00050 for (ACE_HANDLE i = 0; i < this->max_handle_ + 1; i++) 00051 if (this->is_set (i)) 00052 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" %d "), i)); 00053 #endif /* ACE_WIN32 */ 00054 00055 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" ]\n"))); 00056 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00057 #endif /* ACE_HAS_DUMP */ 00058 }
| 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 178 of file Handle_Set.inl.
| 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 80 of file Handle_Set.inl.
00081 { 00082 ACE_TRACE ("ACE_Handle_Set::is_set"); 00083 #if defined (ACE_HAS_BIG_FD_SET) 00084 return FD_ISSET (handle, 00085 &this->mask_) 00086 && this->size_ > 0; 00087 #elif defined (ACE_HAS_NONCONST_FD_ISSET) 00088 return FD_ISSET (handle, 00089 const_cast<fd_set*> (&this->mask_)); 00090 #else 00091 return FD_ISSET (handle, 00092 &this->mask_); 00093 #endif /* ACE_HAS_BIG_FD_SET */ 00094 }
| ACE_HANDLE ACE_Handle_Set::max_set | ( | void | ) | const |
Returns the number of the large bit.
Definition at line 71 of file Handle_Set.inl.
00072 { 00073 ACE_TRACE ("ACE_Handle_Set::max_set"); 00074 return this->max_handle_; 00075 }
| int ACE_Handle_Set::num_set | ( | void | ) | const |
Returns a count of the number of enabled bits.
Definition at line 152 of file Handle_Set.inl.
| 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 165 of file Handle_Set.inl.
| ACE_Handle_Set& ACE_Handle_Set::operator= | ( | const ACE_Handle_Set & | ) |
Assignment operator optimizes for cases where <size_> == 0.
| void ACE_Handle_Set::reset | ( | void | ) |
Initialize the bitmask to all 0s and reset the associated fields.
Definition at line 29 of file Handle_Set.inl.
00030 { 00031 ACE_TRACE ("ACE_Handle_Set::reset"); 00032 this->max_handle_ = 00033 ACE_INVALID_HANDLE; 00034 #if defined (ACE_HAS_BIG_FD_SET) 00035 this->min_handle_ = 00036 NUM_WORDS * WORDSIZE; 00037 #endif /* ACE_HAS_BIG_FD_SET */ 00038 this->size_ = 0; 00039 // #if !defined (ACE_HAS_BIG_FD_SET) Why is this here? -Steve Huston 00040 FD_ZERO (&this->mask_); 00041 // #endif /* ACE_HAS_BIG_FD_SET */ 00042 }
| 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 99 of file Handle_Set.inl.
00100 { 00101 ACE_TRACE ("ACE_Handle_Set::set_bit"); 00102 if ((handle != ACE_INVALID_HANDLE) 00103 && (!this->is_set (handle))) 00104 { 00105 #if defined (ACE_WIN32) 00106 FD_SET ((SOCKET) handle, 00107 &this->mask_); 00108 ++this->size_; 00109 #else /* ACE_WIN32 */ 00110 #if defined (ACE_HAS_BIG_FD_SET) 00111 if (this->size_ == 0) 00112 FD_ZERO (&this->mask_); 00113 00114 if (handle < this->min_handle_) 00115 this->min_handle_ = handle; 00116 #endif /* ACE_HAS_BIG_FD_SET */ 00117 00118 FD_SET (handle, 00119 &this->mask_); 00120 ++this->size_; 00121 00122 if (handle > this->max_handle_) 00123 this->max_handle_ = handle; 00124 #endif /* ACE_WIN32 */ 00125 } 00126 }
| 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 213 of file Handle_Set.cpp.
00214 { 00215 ACE_TRACE ("ACE_Handle_Set::set_max"); 00216 #if !defined(ACE_WIN32) 00217 fd_mask * maskp = (fd_mask *)(this->mask_.fds_bits); 00218 00219 if (this->size_ == 0) 00220 this->max_handle_ = ACE_INVALID_HANDLE; 00221 else 00222 { 00223 int i; 00224 00225 for (i = ACE_DIV_BY_WORDSIZE (current_max - 1); 00226 maskp[i] == 0; 00227 i--) 00228 continue; 00229 #if defined (ACE_TANDEM_NSK_BIT_ORDER) 00230 // bits are in reverse order, MSB (sign bit) = bit 0. 00231 this->max_handle_ = ACE_MULT_BY_WORDSIZE (i); 00232 for (fd_mask val = maskp[i]; 00233 (val & ACE_MSB_MASK) != 0; 00234 val = (val << 1)) 00235 ++this->max_handle_; 00236 #elif 1 /* !defined(ACE_HAS_BIG_FD_SET) */ 00237 this->max_handle_ = ACE_MULT_BY_WORDSIZE (i); 00238 for (fd_mask val = maskp[i]; 00239 (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1... 00240 val = (val >> 1) & ACE_MSB_MASK) 00241 ++this->max_handle_; 00242 #else 00243 register u_long val = this->mask_.fds_bits[i]; 00244 this->max_handle_ = ACE_MULT_BY_WORDSIZE (i) 00245 + ACE_Handle_Set::bitpos(val & ~(val - 1)); 00246 #endif /* 1 */ 00247 } 00248 00249 // Do some sanity checking... 00250 if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE) 00251 this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1; 00252 #else 00253 ACE_UNUSED_ARG (current_max); 00254 #endif /* !ACE_WIN32 */ 00255 }
| 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 192 of file Handle_Set.cpp.
00193 { 00194 ACE_TRACE ("ACE_Handle_Set::sync"); 00195 #if !defined (ACE_WIN32) 00196 fd_mask *maskp = (fd_mask *)(this->mask_.fds_bits); 00197 this->size_ = 0; 00198 00199 for (int i = ACE_DIV_BY_WORDSIZE (max - 1); 00200 i >= 0; 00201 i--) 00202 this->size_ += ACE_Handle_Set::count_bits (maskp[i]); 00203 00204 this->set_max (max); 00205 #else 00206 ACE_UNUSED_ARG (max); 00207 #endif /* !ACE_WIN32 */ 00208 }
friend class ACE_Handle_Set_Iterator [friend] |
Definition at line 52 of file Handle_Set.h.
Declare the dynamic allocation hooks.
Definition at line 121 of file Handle_Set.h.
fd_set ACE_Handle_Set::mask_ [private] |
Bitmask.
Definition at line 136 of file Handle_Set.h.
ACE_HANDLE ACE_Handle_Set::max_handle_ [private] |
Current max handle.
Definition at line 128 of file Handle_Set.h.
ACE_HANDLE ACE_Handle_Set::min_handle_ [private] |
Current min handle.
Definition at line 132 of file Handle_Set.h.
const char ACE_Handle_Set::nbits_ [static, private] |
{
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 162 of file Handle_Set.h.
int ACE_Handle_Set::size_ [private] |
Size of the set, i.e., a count of the number of enabled bits.
Definition at line 125 of file Handle_Set.h.
1.6.1