00001 // -*- C++ -*- 00002 // 00003 // $Id: Handle_Set.inl 80826 2008-03-04 14:51:23Z wotte $ 00004 00005 #include "ace/Log_Msg.h" 00006 00007 // todo: This should be cleaned up a bit. 00008 // memset for FD_ZERO on OpenBSD and Solaris w/ gcc 2.95.3 00009 #include "ace/os_include/os_string.h" 00010 00011 // FreeBSD 4.8-RC? for bzero() used by FD_ZERO 00012 #include "ace/os_include/os_strings.h" 00013 00014 // IRIX5 defines bzero() in this odd file... used by FD_ZERO 00015 #if defined (ACE_HAS_BSTRING) 00016 # include /**/ <bstring.h> 00017 #endif /* ACE_HAS_BSTRING */ 00018 00019 // AIX defines bzero() in this odd file... used by FD_ZERO 00020 #if defined (ACE_HAS_STRINGS) 00021 # include "ace/os_include/os_strings.h" 00022 #endif /* ACE_HAS_STRINGS */ 00023 00024 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 // Initialize the bitmask to all 0s and reset the associated fields. 00027 00028 ACE_INLINE void 00029 ACE_Handle_Set::reset (void) 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 } 00043 00044 #if defined (ACE_HAS_BIG_FD_SET) 00045 ACE_INLINE ACE_Handle_Set & 00046 ACE_Handle_Set::operator = (const ACE_Handle_Set &rhs) 00047 { 00048 ACE_TRACE ("ACE_Handle_Set::operator ="); 00049 00050 if (rhs.size_ > 0) 00051 { 00052 this->size_ = 00053 rhs.size_; 00054 this->max_handle_ = 00055 rhs.max_handle_; 00056 this->min_handle_ = 00057 rhs.min_handle_; 00058 this->mask_ = 00059 rhs.mask_; 00060 } 00061 else 00062 this->reset (); 00063 00064 return *this; 00065 } 00066 #endif /* ACE_HAS_BIG_FD_SET */ 00067 00068 // Returns the number of the large bit. 00069 00070 ACE_INLINE ACE_HANDLE 00071 ACE_Handle_Set::max_set (void) const 00072 { 00073 ACE_TRACE ("ACE_Handle_Set::max_set"); 00074 return this->max_handle_; 00075 } 00076 00077 // Checks whether handle is enabled. 00078 00079 ACE_INLINE int 00080 ACE_Handle_Set::is_set (ACE_HANDLE handle) const 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 } 00095 00096 // Enables the handle. 00097 00098 ACE_INLINE void 00099 ACE_Handle_Set::set_bit (ACE_HANDLE handle) 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 } 00127 00128 // Disables the handle. 00129 00130 ACE_INLINE void 00131 ACE_Handle_Set::clr_bit (ACE_HANDLE handle) 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 } 00148 00149 // Returns a count of the number of enabled bits. 00150 00151 ACE_INLINE int 00152 ACE_Handle_Set::num_set (void) const 00153 { 00154 ACE_TRACE ("ACE_Handle_Set::num_set"); 00155 #if defined (ACE_WIN32) 00156 return this->mask_.fd_count; 00157 #else /* !ACE_WIN32 */ 00158 return this->size_; 00159 #endif /* ACE_WIN32 */ 00160 } 00161 00162 // Returns a pointer to the underlying fd_set. 00163 00164 ACE_INLINE 00165 ACE_Handle_Set::operator fd_set *() 00166 { 00167 ACE_TRACE ("ACE_Handle_Set::operator fd_set *"); 00168 00169 if (this->size_ > 0) 00170 return (fd_set *) &this->mask_; 00171 else 00172 return (fd_set *) 0; 00173 } 00174 00175 // Returns a pointer to the underlying fd_set. 00176 00177 ACE_INLINE fd_set * 00178 ACE_Handle_Set::fdset (void) 00179 { 00180 ACE_TRACE ("ACE_Handle_Set::fdset"); 00181 00182 if (this->size_ > 0) 00183 return (fd_set *) &this->mask_; 00184 else 00185 return (fd_set *) 0; 00186 } 00187 00188 ACE_INLINE 00189 ACE_Handle_Set_Iterator::~ACE_Handle_Set_Iterator (void) 00190 { 00191 } 00192 00193 ACE_END_VERSIONED_NAMESPACE_DECL