#include <Select_Reactor_Base.h>
Collaboration diagram for ACE_Select_Reactor_Handler_Repository:

Public Methods | |
| ACE_Select_Reactor_Handler_Repository (ACE_Select_Reactor_Impl &) | |
| Default "do-nothing" constructor. More... | |
| ~ACE_Select_Reactor_Handler_Repository (void) | |
| Destructor. More... | |
| int | open (size_t size) |
| Initialize a repository of the appropriate <size>. More... | |
| int | close (void) |
| Close down the repository. More... | |
| ACE_Event_Handler * | find (ACE_HANDLE handle, size_t *index_p=0) |
| int | bind (ACE_HANDLE, ACE_Event_Handler *, ACE_Reactor_Mask) |
| Bind the <ACE_Event_Handler *> to the <ACE_HANDLE> with the appropriate <ACE_Reactor_Mask> settings. More... | |
| int | unbind (ACE_HANDLE, ACE_Reactor_Mask mask) |
| Remove the binding of <ACE_HANDLE> in accordance with the <mask>. More... | |
| int | unbind_all (void) |
| Remove all the <ACE_HANDLE, ACE_Event_Handler> tuples. More... | |
| int | invalid_handle (ACE_HANDLE handle) |
| int | handle_in_range (ACE_HANDLE handle) |
| size_t | size (void) const |
| Returns the current table size. More... | |
| size_t | max_handlep1 (void) |
| Maximum ACE_HANDLE value, plus 1. More... | |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Attributes | |
| ACE_Select_Reactor_Impl & | select_reactor_ |
| Reference to our <Select_Reactor>. More... | |
| ssize_t | max_size_ |
| Maximum number of handles. More... | |
| int | max_handlep1_ |
| The highest currently active handle, plus 1 (ranges between 0 and <max_size_>. More... | |
| ACE_Event_Tuple * | event_handlers_ |
Friends | |
| class | ACE_Select_Reactor_Handler_Repository_Iterator |
This class is necessary to shield differences between UNIX and Win32. In UNIX, <ACE_HANDLE> is an int, whereas in Win32 it's a void *. This class hides all these details from the bulk of the <ACE_Select_Reactor> code. All of these methods are called with the main <Select_Reactor> token lock held.
Definition at line 271 of file Select_Reactor_Base.h.
|
|
Default "do-nothing" constructor.
Definition at line 114 of file Select_Reactor_Base.cpp. References ACE_TRACE.
00115 : select_reactor_ (select_reactor), 00116 max_size_ (0), 00117 max_handlep1_ (0), 00118 event_handlers_ (0) 00119 { 00120 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::ACE_Select_Reactor_Handler_Repository"); 00121 } |
|
|
Destructor.
Definition at line 17 of file Select_Reactor_Base.i.
00018 {
00019 }
|
|
||||||||||||||||
|
Bind the <ACE_Event_Handler *> to the <ACE_HANDLE> with the appropriate <ACE_Reactor_Mask> settings.
Definition at line 199 of file Select_Reactor_Base.cpp. References ACE_Reactor_Mask, ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, ACE_Reactor::ADD_MASK, ACE_Select_Reactor_Impl::bit_ops, ACE_Event_Handler::get_handle, invalid_handle, ACE_Select_Reactor_Impl::is_suspended_i, max_handlep1_, max_size_, select_reactor_, ssize_t, and ACE_Select_Reactor_Impl::state_changed_.
00202 {
00203 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::bind");
00204
00205 if (handle == ACE_INVALID_HANDLE)
00206 handle = event_handler->get_handle ();
00207
00208 if (this->invalid_handle (handle))
00209 return -1;
00210
00211 #if defined (ACE_WIN32)
00212 int assigned_slot = -1;
00213
00214 for (ssize_t i = 0; i < this->max_handlep1_; i++)
00215 {
00216 // Found it, so let's just reuse this location.
00217 if (ACE_SELECT_REACTOR_HANDLE (i) == handle)
00218 {
00219 assigned_slot = i;
00220 break;
00221 }
00222 // Here's the first free slot, so let's take it.
00223 else if (ACE_SELECT_REACTOR_HANDLE (i) == ACE_INVALID_HANDLE
00224 && assigned_slot == -1)
00225 assigned_slot = i;
00226 }
00227
00228 if (assigned_slot > -1)
00229 // We found a free spot, let's reuse it.
00230 {
00231 ACE_SELECT_REACTOR_HANDLE (assigned_slot) = handle;
00232 ACE_SELECT_REACTOR_EVENT_HANDLER (this, assigned_slot) = event_handler;
00233 }
00234 else if (this->max_handlep1_ < this->max_size_)
00235 {
00236 // Insert at the end of the active portion.
00237 ACE_SELECT_REACTOR_HANDLE (this->max_handlep1_) = handle;
00238 ACE_SELECT_REACTOR_EVENT_HANDLER (this, this->max_handlep1_) = event_handler;
00239 this->max_handlep1_++;
00240 }
00241 else
00242 {
00243 // No more room at the inn!
00244 errno = ENOMEM;
00245 return -1;
00246 }
00247 #else
00248 ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle) = event_handler;
00249
00250 if (this->max_handlep1_ < handle + 1)
00251 this->max_handlep1_ = handle + 1;
00252 #endif /* ACE_WIN32 */
00253
00254 if (this->select_reactor_.is_suspended_i (handle))
00255 {
00256 this->select_reactor_.bit_ops (handle,
00257 mask,
00258 this->select_reactor_.suspend_set_,
00259 ACE_Reactor::ADD_MASK);
00260 }
00261 else
00262 {
00263 this->select_reactor_.bit_ops (handle,
00264 mask,
00265 this->select_reactor_.wait_set_,
00266 ACE_Reactor::ADD_MASK);
00267
00268 // Note the fact that we've changed the state of the <wait_set_>,
00269 // which is used by the dispatching loop to determine whether it can
00270 // keep going or if it needs to reconsult select().
00271 this->select_reactor_.state_changed_ = 1;
00272 }
00273
00274 /*
00275 // @@NOTE: We used to do this in earlier versions of ACE+TAO. But
00276 // this is totally wrong..
00277 // Clear any suspend masks for it too.
00278 this->select_reactor_.bit_ops (handle,
00279 mask,
00280 this->select_reactor_.suspend_set_,
00281 ACE_Reactor::CLR_MASK);
00282 */
00283
00284 return 0;
00285 }
|
|
|
Close down the repository.
Definition at line 137 of file Select_Reactor_Base.cpp. References ACE_TRACE, event_handlers_, and unbind_all. Referenced by ACE_Select_Reactor_T::close.
00138 {
00139 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::close");
00140
00141 if (this->event_handlers_ != 0)
00142 {
00143 this->unbind_all ();
00144
00145 delete [] this->event_handlers_;
00146 this->event_handlers_ = 0;
00147 }
00148 return 0;
00149 }
|
|
|
Dump the state of an object.
Definition at line 458 of file Select_Reactor_Base.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, ACE_Select_Reactor_Handler_Repository_Iterator::advance, ACE_Event_Handler::get_handle, LM_DEBUG, and ACE_Select_Reactor_Handler_Repository_Iterator::next. Referenced by ACE_Select_Reactor_T::dump.
00459 {
00460 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::dump");
00461
00462 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00463 ACE_DEBUG ((LM_DEBUG,
00464 ACE_LIB_TEXT ("(%t) max_handlep1_ = %d, max_size_ = %d\n"),
00465 this->max_handlep1_, this->max_size_));
00466 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("[")));
00467
00468 ACE_Event_Handler *eh = 0;
00469
00470 for (ACE_Select_Reactor_Handler_Repository_Iterator iter (this);
00471 iter.next (eh) != 0;
00472 iter.advance ())
00473 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (eh = %x, eh->handle_ = %d)"),
00474 eh, eh->get_handle ()));
00475
00476 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" ]")));
00477 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00478 }
|
|
||||||||||||
|
Return the <ACE_Event_Handler *> associated with <ACE_HANDLE>. If <index_p> is non-0, then return the index location of the <handle>, if found. Definition at line 154 of file Select_Reactor_Base.cpp. References ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, handle_in_range, max_handlep1_, and ssize_t. Referenced by ACE_TP_Reactor::handle_socket_events, ACE_Select_Reactor_T::is_suspended_i, ACE_TP_Reactor::remove_handler, ACE_Select_Reactor_T::resume_i, ACE_Select_Reactor_T::suspend_i, and unbind.
00156 {
00157 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::find");
00158
00159 ACE_Event_Handler *eh = 0;
00160 ssize_t i;
00161
00162 // Only bother to search for the <handle> if it's in range.
00163 if (this->handle_in_range (handle))
00164 {
00165 #if defined (ACE_WIN32)
00166 i = 0;
00167
00168 for (; i < this->max_handlep1_; i++)
00169 if (ACE_SELECT_REACTOR_HANDLE (i) == handle)
00170 {
00171 eh = ACE_SELECT_REACTOR_EVENT_HANDLER (this, i);
00172 break;
00173 }
00174 #else
00175 i = handle;
00176
00177 eh = ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle);
00178 #endif /* ACE_WIN32 */
00179 }
00180 else
00181 // g++ can't figure out that <i> won't be used below if the handle
00182 // is out of range, so keep it happy by defining <i> here . . .
00183 i = 0;
00184
00185 if (eh != 0)
00186 {
00187 if (index_p != 0)
00188 *index_p = i;
00189 }
00190 else
00191 errno = ENOENT;
00192
00193 return eh;
00194 }
|
|
|
Definition at line 51 of file Select_Reactor_Base.cpp. References ACE_TRACE, and max_handlep1_. Referenced by ACE_Select_Reactor_Impl::bit_ops, and find.
00052 {
00053 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::handle_in_range");
00054 #if defined (ACE_WIN32)
00055 // It's too expensive to perform more exhaustive validity checks on
00056 // Win32 due to the way that they implement SOCKET HANDLEs.
00057 if (handle != ACE_INVALID_HANDLE)
00058 #else /* !ACE_WIN32 */
00059 if (handle >= 0 && handle < this->max_handlep1_)
00060 #endif /* ACE_WIN32 */
00061 return 1;
00062 else
00063 {
00064 errno = EINVAL;
00065 return 0;
00066 }
00067 }
|
|
|
Definition at line 30 of file Select_Reactor_Base.cpp. References ACE_TRACE, and max_size_. Referenced by bind.
00031 {
00032 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::invalid_handle");
00033 #if defined (ACE_WIN32)
00034 // It's too expensive to perform more exhaustive validity checks on
00035 // Win32 due to the way that they implement SOCKET HANDLEs.
00036 if (handle == ACE_INVALID_HANDLE)
00037 #else /* !ACE_WIN32 */
00038 if (handle < 0 || handle >= this->max_size_)
00039 #endif /* ACE_WIN32 */
00040 {
00041 errno = EINVAL;
00042 return 1;
00043 }
00044 else
00045 return 0;
00046 }
|
|
|
Maximum ACE_HANDLE value, plus 1.
Definition at line 70 of file Select_Reactor_Base.cpp. References ACE_TRACE, and max_handlep1_. Referenced by ACE_QtReactor::QtWaitForMultipleEvents, ACE_TkReactor::TkWaitForMultipleEvents, ACE_XtReactor::wait_for_multiple_events, ACE_TkReactor::wait_for_multiple_events, ACE_QtReactor::wait_for_multiple_events, ACE_FlReactor::wait_for_multiple_events, and ACE_XtReactor::XtWaitForMultipleEvents.
00071 {
00072 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::max_handlep1");
00073
00074 return this->max_handlep1_;
00075 }
|
|
|
Initialize a repository of the appropriate <size>. On Unix platforms, the size parameter should be as large as the maximum number of file descriptors allowed for a given process. This is necessary since a file descriptor is used to directly index the array of event handlers maintained by the Reactor's handler repository. Direct indexing is used for efficiency reasons. Definition at line 78 of file Select_Reactor_Base.cpp. References ACE_NEW_RETURN, ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, max_handlep1_, max_size_, ACE::set_handle_limit, and size.
00079 {
00080 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::open");
00081 this->max_size_ = size;
00082 this->max_handlep1_ = 0;
00083
00084 #if defined (ACE_WIN32)
00085 // Try to allocate the memory.
00086 ACE_NEW_RETURN (this->event_handlers_,
00087 ACE_Event_Tuple[size],
00088 -1);
00089
00090 // Initialize the ACE_Event_Handler * to { ACE_INVALID_HANDLE, 0 }.
00091 for (size_t h = 0; h < size; h++)
00092 {
00093 ACE_SELECT_REACTOR_HANDLE (h) = ACE_INVALID_HANDLE;
00094 ACE_SELECT_REACTOR_EVENT_HANDLER (this, h) = 0;
00095 }
00096 #else
00097 // Try to allocate the memory.
00098 ACE_NEW_RETURN (this->event_handlers_,
00099 ACE_Event_Handler *[size],
00100 -1);
00101
00102 // Initialize the ACE_Event_Handler * to NULL.
00103 for (size_t h = 0; h < size; h++)
00104 ACE_SELECT_REACTOR_EVENT_HANDLER (this, h) = 0;
00105 #endif /* ACE_WIN32 */
00106
00107 // Try to increase the number of handles if <size> is greater than
00108 // the current limit.
00109 return ACE::set_handle_limit (ACE_static_cast (int, size));
00110 }
|
|
|
Returns the current table size.
Definition at line 27 of file Select_Reactor_Base.i. References max_size_. Referenced by open, and ACE_Select_Reactor_T::size.
00028 {
00029 return this->max_size_;
00030 }
|
|
||||||||||||
|
Remove the binding of <ACE_HANDLE> in accordance with the <mask>.
Definition at line 290 of file Select_Reactor_Base.cpp. References ACE_BIT_ENABLED, ACE_Reactor_Mask, ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, ACE_Select_Reactor_Impl::bit_ops, ACE_Reactor::CLR_MASK, ACE_Event_Handler::DONT_CALL, ACE_Select_Reactor_Handle_Set::ex_mask_, find, ACE_Event_Handler::handle_close, ACE_Handle_Set::is_set, max_handlep1_, ACE_Handle_Set::max_set, ACE_Select_Reactor_Handle_Set::rd_mask_, select_reactor_, ACE_Select_Reactor_Impl::state_changed_, ACE_Select_Reactor_Impl::suspend_set_, ACE_Select_Reactor_Impl::wait_set_, and ACE_Select_Reactor_Handle_Set::wr_mask_. Referenced by unbind_all.
00292 {
00293 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::unbind");
00294
00295 size_t slot;
00296 ACE_Event_Handler *eh = this->find (handle, &slot);
00297
00298 if (eh == 0)
00299 return -1;
00300
00301 // Clear out the <mask> bits in the Select_Reactor's wait_set.
00302 this->select_reactor_.bit_ops (handle,
00303 mask,
00304 this->select_reactor_.wait_set_,
00305 ACE_Reactor::CLR_MASK);
00306
00307 // And suspend_set.
00308 this->select_reactor_.bit_ops (handle,
00309 mask,
00310 this->select_reactor_.suspend_set_,
00311 ACE_Reactor::CLR_MASK);
00312
00313 // Note the fact that we've changed the state of the <wait_set_>,
00314 // which is used by the dispatching loop to determine whether it can
00315 // keep going or if it needs to reconsult select().
00316 this->select_reactor_.state_changed_ = 1;
00317
00318 // Close down the <Event_Handler> unless we've been instructed not
00319 // to.
00320 if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::DONT_CALL) == 0)
00321 eh->handle_close (handle, mask);
00322
00323 // If there are no longer any outstanding events on this <handle>
00324 // then we can totally shut down the Event_Handler.
00325
00326 int has_any_wait_mask =
00327 (this->select_reactor_.wait_set_.rd_mask_.is_set (handle)
00328 || this->select_reactor_.wait_set_.wr_mask_.is_set (handle)
00329 || this->select_reactor_.wait_set_.ex_mask_.is_set (handle));
00330 int has_any_suspend_mask =
00331 (this->select_reactor_.suspend_set_.rd_mask_.is_set (handle)
00332 || this->select_reactor_.suspend_set_.wr_mask_.is_set (handle)
00333 || this->select_reactor_.suspend_set_.ex_mask_.is_set (handle));
00334
00335 if (!has_any_wait_mask && !has_any_suspend_mask)
00336 #if defined (ACE_WIN32)
00337 {
00338 ACE_SELECT_REACTOR_HANDLE (slot) = ACE_INVALID_HANDLE;
00339 ACE_SELECT_REACTOR_EVENT_HANDLER (this, slot) = 0;
00340
00341 if (this->max_handlep1_ == (int) slot + 1)
00342 {
00343 // We've deleted the last entry (i.e., i + 1 == the current
00344 // size of the array), so we need to figure out the last
00345 // valid place in the array that we should consider in
00346 // subsequent searches.
00347
00348 int i;
00349
00350 for (i = this->max_handlep1_ - 1;
00351 i >= 0 && ACE_SELECT_REACTOR_HANDLE (i) == ACE_INVALID_HANDLE;
00352 i--)
00353 continue;
00354
00355 this->max_handlep1_ = i + 1;
00356 }
00357 }
00358 #else
00359 {
00360 ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle) = 0;
00361
00362 if (this->max_handlep1_ == handle + 1)
00363 {
00364 // We've deleted the last entry, so we need to figure out
00365 // the last valid place in the array that is worth looking
00366 // at.
00367 ACE_HANDLE wait_rd_max = this->select_reactor_.wait_set_.rd_mask_.max_set ();
00368 ACE_HANDLE wait_wr_max = this->select_reactor_.wait_set_.wr_mask_.max_set ();
00369 ACE_HANDLE wait_ex_max = this->select_reactor_.wait_set_.ex_mask_.max_set ();
00370
00371 ACE_HANDLE suspend_rd_max = this->select_reactor_.suspend_set_.rd_mask_.max_set ();
00372 ACE_HANDLE suspend_wr_max = this->select_reactor_.suspend_set_.wr_mask_.max_set ();
00373 ACE_HANDLE suspend_ex_max = this->select_reactor_.suspend_set_.ex_mask_.max_set ();
00374
00375 // Compute the maximum of six values.
00376 this->max_handlep1_ = wait_rd_max;
00377 if (this->max_handlep1_ < wait_wr_max)
00378 this->max_handlep1_ = wait_wr_max;
00379 if (this->max_handlep1_ < wait_ex_max)
00380 this->max_handlep1_ = wait_ex_max;
00381
00382 if (this->max_handlep1_ < suspend_rd_max)
00383 this->max_handlep1_ = suspend_rd_max;
00384 if (this->max_handlep1_ < suspend_wr_max)
00385 this->max_handlep1_ = suspend_wr_max;
00386 if (this->max_handlep1_ < suspend_ex_max)
00387 this->max_handlep1_ = suspend_ex_max;
00388
00389 this->max_handlep1_++;
00390 }
00391 }
00392 #endif /* ACE_WIN32 */
00393
00394 return 0;
00395 }
|
|
|
Remove all the <ACE_HANDLE, ACE_Event_Handler> tuples.
Definition at line 124 of file Select_Reactor_Base.cpp. References ACE_SELECT_REACTOR_HANDLE, ACE_Event_Handler::ALL_EVENTS_MASK, max_handlep1_, and unbind. Referenced by close.
00125 {
00126 // Unbind all of the <handle, ACE_Event_Handler>s.
00127 for (int handle = 0;
00128 handle < this->max_handlep1_;
00129 handle++)
00130 this->unbind (ACE_SELECT_REACTOR_HANDLE (handle),
00131 ACE_Event_Handler::ALL_EVENTS_MASK);
00132
00133 return 0;
00134 }
|
|
|
Definition at line 274 of file Select_Reactor_Base.h. |
|
|
Declare the dynamic allocation hooks.
Definition at line 341 of file Select_Reactor_Base.h. |
|
|
The NT version implements this via a dynamically allocated array of <ACE_Event_Tuple *>. Since NT implements ACE_HANDLE as a void * we can't directly index into this array. Therefore, we just do a linear search (for now). Next, we'll modify things to use hashing or something faster... Definition at line 364 of file Select_Reactor_Base.h. Referenced by close. |
|
|
The highest currently active handle, plus 1 (ranges between 0 and <max_size_>.
Definition at line 352 of file Select_Reactor_Base.h. Referenced by ACE_Select_Reactor_Handler_Repository_Iterator::advance, bind, ACE_Select_Reactor_Handler_Repository_Iterator::done, find, handle_in_range, max_handlep1, ACE_Select_Reactor_Handler_Repository_Iterator::next, open, unbind, and unbind_all. |
|
|
Maximum number of handles.
Definition at line 348 of file Select_Reactor_Base.h. Referenced by bind, invalid_handle, open, and size. |
|
|
Reference to our <Select_Reactor>.
Definition at line 345 of file Select_Reactor_Base.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002