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

Public Member Functions | |
| ACE_Select_Reactor_Handler_Repository (ACE_Select_Reactor_Impl &) | |
| Default "do-nothing" constructor. | |
| ~ACE_Select_Reactor_Handler_Repository (void) | |
| Destructor. | |
| int | open (size_t size) |
| Initialize a repository of the appropriate . | |
| int | close (void) |
| Close down the repository. | |
| ACE_Event_Handler * | find (ACE_HANDLE handle, size_t *index_p=0) |
| int | bind (ACE_HANDLE, ACE_Event_Handler *, ACE_Reactor_Mask) |
| int | unbind (ACE_HANDLE, ACE_Reactor_Mask mask) |
| Remove the binding of ACE_HANDLE in accordance with the mask. | |
| int | unbind_all (void) |
| Remove all the <ACE_HANDLE, ACE_Event_Handler> tuples. | |
| int | invalid_handle (ACE_HANDLE handle) |
| int | handle_in_range (ACE_HANDLE handle) |
| size_t | size (void) const |
| Returns the current table size. | |
| size_t | max_handlep1 (void) |
| Maximum ACE_HANDLE value, plus 1. | |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Attributes | |
| ACE_Select_Reactor_Impl & | select_reactor_ |
| Reference to our . | |
| ssize_t | max_size_ |
| Maximum number of handles. | |
| int | max_handlep1_ |
| 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 token lock held.
Definition at line 275 of file Select_Reactor_Base.h.
|
|
Default "do-nothing" constructor.
Definition at line 119 of file Select_Reactor_Base.cpp. References ACE_TRACE.
00120 : select_reactor_ (select_reactor), 00121 max_size_ (0), 00122 max_handlep1_ (0), 00123 event_handlers_ (0) 00124 { 00125 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::ACE_Select_Reactor_Handler_Repository"); 00126 } |
|
|
Destructor.
Definition at line 15 of file Select_Reactor_Base.inl.
00016 {
00017 }
|
|
||||||||||||||||
|
Bind the ACE_Event_Handler * to the ACE_HANDLE with the appropriate ACE_Reactor_Mask settings. Definition at line 204 of file Select_Reactor_Base.cpp. References ACE_Reactor_Mask, ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, ACE_Event_Handler::add_reference(), ACE_Select_Reactor_Impl::bit_ops(), ACE_Event_Handler::get_handle(), invalid_handle(), ACE_Select_Reactor_Impl::is_suspended_i(), max_handlep1_, and ssize_t.
00207 {
00208 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::bind");
00209
00210 if (handle == ACE_INVALID_HANDLE)
00211 handle = event_handler->get_handle ();
00212
00213 if (this->invalid_handle (handle))
00214 return -1;
00215
00216 // Is this handle already in the Reactor?
00217 int existing_handle = 0;
00218
00219 #if defined (ACE_WIN32)
00220
00221 ssize_t assigned_slot = -1;
00222
00223 for (ssize_t i = 0; i < this->max_handlep1_; ++i)
00224 {
00225 // If handle is already registered.
00226 if (ACE_SELECT_REACTOR_HANDLE (i) == handle)
00227 {
00228 // Cannot use a different handler for an existing handle.
00229 if (ACE_SELECT_REACTOR_EVENT_HANDLER (this, i) !=
00230 event_handler)
00231 return -1;
00232
00233 // Remember location.
00234 assigned_slot = i;
00235
00236 // Remember that this handle is already registered in the
00237 // Reactor.
00238 existing_handle = 1;
00239
00240 // We can stop looking now.
00241 break;
00242 }
00243 else
00244 // Here's the first free slot, so let's take it.
00245 if (ACE_SELECT_REACTOR_HANDLE (i) == ACE_INVALID_HANDLE &&
00246 assigned_slot == -1)
00247 {
00248 assigned_slot = i;
00249 }
00250 }
00251
00252 if (assigned_slot > -1)
00253 // We found a spot.
00254 {
00255 ACE_SELECT_REACTOR_HANDLE (assigned_slot) = handle;
00256 ACE_SELECT_REACTOR_EVENT_HANDLER (this, assigned_slot) = event_handler;
00257 }
00258 else if (this->max_handlep1_ < this->max_size_)
00259 {
00260 // Insert at the end of the active portion.
00261 ACE_SELECT_REACTOR_HANDLE (this->max_handlep1_) = handle;
00262 ACE_SELECT_REACTOR_EVENT_HANDLER (this, this->max_handlep1_) = event_handler;
00263 ++this->max_handlep1_;
00264 }
00265 else
00266 {
00267 // No more room at the inn!
00268 errno = ENOMEM;
00269 return -1;
00270 }
00271
00272 #else
00273
00274 // Check if this handle is already registered.
00275 ACE_Event_Handler *current_handler =
00276 ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle);
00277
00278 if (current_handler)
00279 {
00280 // Cannot use a different handler for an existing handle.
00281 if (current_handler != event_handler)
00282 return -1;
00283
00284 // Remember that this handle is already registered in the
00285 // Reactor.
00286 existing_handle = 1;
00287 }
00288
00289 ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle) = event_handler;
00290
00291 if (this->max_handlep1_ < handle + 1)
00292 this->max_handlep1_ = handle + 1;
00293
00294 #endif /* ACE_WIN32 */
00295
00296 if (this->select_reactor_.is_suspended_i (handle))
00297 {
00298 this->select_reactor_.bit_ops (handle,
00299 mask,
00300 this->select_reactor_.suspend_set_,
00301 ACE_Reactor::ADD_MASK);
00302 }
00303 else
00304 {
00305 this->select_reactor_.bit_ops (handle,
00306 mask,
00307 this->select_reactor_.wait_set_,
00308 ACE_Reactor::ADD_MASK);
00309
00310 // Note the fact that we've changed the state of the <wait_set_>,
00311 // which is used by the dispatching loop to determine whether it can
00312 // keep going or if it needs to reconsult select().
00313 // this->select_reactor_.state_changed_ = 1;
00314 }
00315
00316 // If new entry, call add_reference() if needed.
00317 if (!existing_handle)
00318 event_handler->add_reference ();
00319
00320 return 0;
00321 }
|
|
|
Close down the repository.
Definition at line 142 of file Select_Reactor_Base.cpp. References ACE_TRACE, event_handlers_, and unbind_all(). Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::close().
00143 {
00144 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::close");
00145
00146 if (this->event_handlers_ != 0)
00147 {
00148 this->unbind_all ();
00149
00150 delete [] this->event_handlers_;
00151 this->event_handlers_ = 0;
00152 }
00153 return 0;
00154 }
|
|
|
Dump the state of an object.
Definition at line 520 of file Select_Reactor_Base.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, ACE_Event_Handler::get_handle(), and LM_DEBUG. Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::dump().
00521 {
00522 #if defined (ACE_HAS_DUMP)
00523 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::dump");
00524
00525 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00526 ACE_DEBUG ((LM_DEBUG,
00527 ACE_LIB_TEXT ("max_handlep1_ = %d, max_size_ = %d\n"),
00528 this->max_handlep1_, this->max_size_));
00529 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("[")));
00530
00531 ACE_Event_Handler *event_handler = 0;
00532
00533 for (ACE_Select_Reactor_Handler_Repository_Iterator iter (this);
00534 iter.next (event_handler) != 0;
00535 iter.advance ())
00536 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" (event_handler = %x, event_handler->handle_ = %d)\n"),
00537 event_handler, event_handler->get_handle ()));
00538
00539 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" ]\n")));
00540 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00541 #endif /* ACE_HAS_DUMP */
00542 }
|
|
||||||||||||
|
Return the <ACE_Event_Handler *> associated with ACE_HANDLE. If is non-0, then return the index location of the , if found. Definition at line 159 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_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::is_suspended_i(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::resume_i(), ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::suspend_i(), and unbind().
00161 {
00162 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::find");
00163
00164 ACE_Event_Handler *eh = 0;
00165 ssize_t i;
00166
00167 // Only bother to search for the <handle> if it's in range.
00168 if (this->handle_in_range (handle))
00169 {
00170 #if defined (ACE_WIN32)
00171 i = 0;
00172
00173 for (; i < this->max_handlep1_; ++i)
00174 if (ACE_SELECT_REACTOR_HANDLE (i) == handle)
00175 {
00176 eh = ACE_SELECT_REACTOR_EVENT_HANDLER (this, i);
00177 break;
00178 }
00179 #else
00180 i = handle;
00181
00182 eh = ACE_SELECT_REACTOR_EVENT_HANDLER (this, handle);
00183 #endif /* ACE_WIN32 */
00184 }
00185 else
00186 // g++ can't figure out that <i> won't be used below if the handle
00187 // is out of range, so keep it happy by defining <i> here . . .
00188 i = 0;
00189
00190 if (eh != 0)
00191 {
00192 if (index_p != 0)
00193 *index_p = i;
00194 }
00195 else
00196 errno = ENOENT;
00197
00198 return eh;
00199 }
|
|
|
Definition at line 56 of file Select_Reactor_Base.cpp. References ACE_TRACE, and max_handlep1_. Referenced by ACE_Select_Reactor_Impl::bit_ops(), and find().
00057 {
00058 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::handle_in_range");
00059 #if defined (ACE_WIN32)
00060 // It's too expensive to perform more exhaustive validity checks on
00061 // Win32 due to the way that they implement SOCKET HANDLEs.
00062 if (handle != ACE_INVALID_HANDLE)
00063 #else /* !ACE_WIN32 */
00064 if (handle >= 0 && handle < this->max_handlep1_)
00065 #endif /* ACE_WIN32 */
00066 return 1;
00067 else
00068 {
00069 errno = EINVAL;
00070 return 0;
00071 }
00072 }
|
|
|
Definition at line 35 of file Select_Reactor_Base.cpp. References ACE_TRACE. Referenced by bind().
00036 {
00037 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::invalid_handle");
00038 #if defined (ACE_WIN32)
00039 // It's too expensive to perform more exhaustive validity checks on
00040 // Win32 due to the way that they implement SOCKET HANDLEs.
00041 if (handle == ACE_INVALID_HANDLE)
00042 #else /* !ACE_WIN32 */
00043 if (handle < 0 || handle >= this->max_size_)
00044 #endif /* ACE_WIN32 */
00045 {
00046 errno = EINVAL;
00047 return 1;
00048 }
00049 else
00050 return 0;
00051 }
|
|
|
Maximum ACE_HANDLE value, plus 1.
Definition at line 75 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().
00076 {
00077 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::max_handlep1");
00078
00079 return this->max_handlep1_;
00080 }
|
|
|
Initialize a repository of the appropriate . 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 83 of file Select_Reactor_Base.cpp. References ACE_NEW_RETURN, ACE_SELECT_REACTOR_EVENT_HANDLER, ACE_SELECT_REACTOR_HANDLE, ACE_TRACE, max_handlep1_, and ACE::set_handle_limit().
00084 {
00085 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::open");
00086 this->max_size_ = size;
00087 this->max_handlep1_ = 0;
00088
00089 #if defined (ACE_WIN32)
00090 // Try to allocate the memory.
00091 ACE_NEW_RETURN (this->event_handlers_,
00092 ACE_Event_Tuple[size],
00093 -1);
00094
00095 // Initialize the ACE_Event_Handler * to { ACE_INVALID_HANDLE, 0 }.
00096 for (size_t h = 0; h < size; ++h)
00097 {
00098 ACE_SELECT_REACTOR_HANDLE (h) = ACE_INVALID_HANDLE;
00099 ACE_SELECT_REACTOR_EVENT_HANDLER (this, h) = 0;
00100 }
00101 #else
00102 // Try to allocate the memory.
00103 ACE_NEW_RETURN (this->event_handlers_,
00104 ACE_Event_Handler *[size],
00105 -1);
00106
00107 // Initialize the ACE_Event_Handler * to NULL.
00108 for (size_t h = 0; h < size; ++h)
00109 ACE_SELECT_REACTOR_EVENT_HANDLER (this, h) = 0;
00110 #endif /* ACE_WIN32 */
00111
00112 // Try to increase the number of handles if <size> is greater than
00113 // the current limit.
00114 return ACE::set_handle_limit (static_cast<int> (size), 1);
00115 }
|
|
|
Returns the current table size.
Definition at line 25 of file Select_Reactor_Base.inl. Referenced by ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >::size().
00026 {
00027 return this->max_size_;
00028 }
|
|
||||||||||||
|
Remove the binding of ACE_HANDLE in accordance with the mask.
Definition at line 326 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_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_, ACE_Event_Handler::reference_counting_policy(), ACE_Event_Handler::remove_reference(), ACE_Select_Reactor_Impl::suspend_set_, ACE_Select_Reactor_Impl::wait_set_, and ACE_Select_Reactor_Handle_Set::wr_mask_. Referenced by unbind_all().
00328 {
00329 ACE_TRACE ("ACE_Select_Reactor_Handler_Repository::unbind");
00330
00331 size_t slot = 0;
00332 ACE_Event_Handler *event_handler = this->find (handle, &slot);
00333
00334 if (event_handler == 0)
00335 return -1;
00336
00337 // Clear out the <mask> bits in the Select_Reactor's wait_set.
00338 this->select_reactor_.bit_ops (handle,
00339 mask,
00340 this->select_reactor_.wait_set_,
00341 ACE_Reactor::CLR_MASK);
00342
00343 // And suspend_set.
00344 this->select_reactor_.bit_ops (handle,
00345 mask,
00346 this->select_reactor_.suspend_set_,
00347 ACE_Reactor::CLR_MASK);
00348
00349 // Note the fact that we've changed the state of the <wait_set_>,
00350 // which is used by the dispatching loop to determine whether it can
00351 // keep going or if it needs to reconsult select().
00352 // this->select_reactor_.state_changed_ = 1;
00353
00354 // If there are no longer any outstanding events on this <handle>
00355 // then we can totally shut down the Event_Handler.
00356
00357 int has_any_wait_mask =
00358 (this->select_reactor_.wait_set_.rd_mask_.is_set (handle)
00359 || this->select_reactor_.wait_set_.wr_mask_.is_set (handle)
00360 || this->select_reactor_.wait_set_.ex_mask_.is_set (handle));
00361 int has_any_suspend_mask =
00362 (this->select_reactor_.suspend_set_.rd_mask_.is_set (handle)
00363 || this->select_reactor_.suspend_set_.wr_mask_.is_set (handle)
00364 || this->select_reactor_.suspend_set_.ex_mask_.is_set (handle));
00365
00366 int complete_removal = 0;
00367
00368 if (!has_any_wait_mask && !has_any_suspend_mask)
00369 {
00370 // The handle has been completed removed.
00371 complete_removal = 1;
00372
00373 ACE_SELECT_REACTOR_EVENT_HANDLER (this, slot) = 0;
00374
00375 #if defined (ACE_WIN32)
00376
00377 ACE_SELECT_REACTOR_HANDLE (slot) = ACE_INVALID_HANDLE;
00378
00379 if (this->max_handlep1_ == (int) slot + 1)
00380 {
00381 // We've deleted the last entry (i.e., i + 1 == the current
00382 // size of the array), so we need to figure out the last
00383 // valid place in the array that we should consider in
00384 // subsequent searches.
00385
00386 int i;
00387
00388 for (i = this->max_handlep1_ - 1;
00389 i >= 0 && ACE_SELECT_REACTOR_HANDLE (i) == ACE_INVALID_HANDLE;
00390 --i)
00391 continue;
00392
00393 this->max_handlep1_ = i + 1;
00394 }
00395
00396 #else
00397
00398 if (this->max_handlep1_ == handle + 1)
00399 {
00400 // We've deleted the last entry, so we need to figure out
00401 // the last valid place in the array that is worth looking
00402 // at.
00403 ACE_HANDLE wait_rd_max =
00404 this->select_reactor_.wait_set_.rd_mask_.max_set ();
00405 ACE_HANDLE wait_wr_max =
00406 this->select_reactor_.wait_set_.wr_mask_.max_set ();
00407 ACE_HANDLE wait_ex_max =
00408 this->select_reactor_.wait_set_.ex_mask_.max_set ();
00409
00410 ACE_HANDLE suspend_rd_max =
00411 this->select_reactor_.suspend_set_.rd_mask_.max_set ();
00412 ACE_HANDLE suspend_wr_max =
00413 this->select_reactor_.suspend_set_.wr_mask_.max_set ();
00414 ACE_HANDLE suspend_ex_max =
00415 this->select_reactor_.suspend_set_.ex_mask_.max_set ();
00416
00417 // Compute the maximum of six values.
00418 this->max_handlep1_ = wait_rd_max;
00419 if (this->max_handlep1_ < wait_wr_max)
00420 this->max_handlep1_ = wait_wr_max;
00421 if (this->max_handlep1_ < wait_ex_max)
00422 this->max_handlep1_ = wait_ex_max;
00423
00424 if (this->max_handlep1_ < suspend_rd_max)
00425 this->max_handlep1_ = suspend_rd_max;
00426 if (this->max_handlep1_ < suspend_wr_max)
00427 this->max_handlep1_ = suspend_wr_max;
00428 if (this->max_handlep1_ < suspend_ex_max)
00429 this->max_handlep1_ = suspend_ex_max;
00430
00431 ++this->max_handlep1_;
00432 }
00433
00434 #endif /* ACE_WIN32 */
00435
00436 }
00437
00438 int requires_reference_counting =
00439 event_handler->reference_counting_policy ().value () ==
00440 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00441
00442 // Close down the <Event_Handler> unless we've been instructed not
00443 // to.
00444 if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::DONT_CALL) == 0)
00445 event_handler->handle_close (handle, mask);
00446
00447 // Call remove_reference() if the removal is complete and reference
00448 // counting is needed.
00449 if (complete_removal && requires_reference_counting)
00450 {
00451 event_handler->remove_reference ();
00452 }
00453
00454 return 0;
00455 }
|
|
|
Remove all the <ACE_HANDLE, ACE_Event_Handler> tuples.
Definition at line 129 of file Select_Reactor_Base.cpp. References ACE_SELECT_REACTOR_HANDLE, max_handlep1_, and unbind(). Referenced by close().
00130 {
00131 // Unbind all of the <handle, ACE_Event_Handler>s.
00132 for (int slot = 0;
00133 slot < this->max_handlep1_;
00134 ++slot)
00135 this->unbind (ACE_SELECT_REACTOR_HANDLE (slot),
00136 ACE_Event_Handler::ALL_EVENTS_MASK);
00137
00138 return 0;
00139 }
|
|
|
Definition at line 278 of file Select_Reactor_Base.h. |
|
|
Declare the dynamic allocation hooks.
Definition at line 345 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 368 of file Select_Reactor_Base.h. Referenced by close(). |
|
|
The highest currently active handle, plus 1 (ranges between 0 and . Definition at line 356 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 352 of file Select_Reactor_Base.h. |
|
|
Reference to our .
Definition at line 349 of file Select_Reactor_Base.h. |
1.3.6