00001
00002
00003 #include "ace/OS_NS_errno.h"
00004 #include "ace/Dev_Poll_Reactor.h"
00005 #include "ace/Signal.h"
00006 #include "ace/Sig_Handler.h"
00007
00008 ACE_RCSID (ace,
00009 Dev_Poll_Reactor,
00010 "$Id: Dev_Poll_Reactor.cpp 90177 2010-05-19 11:44:22Z vzykov $")
00011
00012 #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
00013
00014 # include "ace/OS_NS_unistd.h"
00015 # include "ace/OS_NS_fcntl.h"
00016 # include "ace/OS_NS_stropts.h"
00017
00018 # if defined (ACE_HAS_DEV_POLL)
00019 # if defined (linux)
00020 # include <linux/devpoll.h>
00021 # elif defined (HPUX_VERS) && HPUX_VERS < 1123
00022 # include <devpoll.h>
00023 # else
00024 # include <sys/devpoll.h>
00025 # endif
00026 # endif
00027
00028 #if !defined (__ACE_INLINE__)
00029 # include "ace/Dev_Poll_Reactor.inl"
00030 #endif
00031
00032
00033 #include "ace/Handle_Set.h"
00034 #include "ace/Reactor.h"
00035 #include "ace/Timer_Heap.h"
00036 #include "ace/Timer_Queue.h"
00037 #include "ace/ACE.h"
00038 #include "ace/Reverse_Lock_T.h"
00039 #include "ace/Recursive_Thread_Mutex.h"
00040 #include "ace/Null_Mutex.h"
00041 #include "ace/os_include/os_poll.h"
00042 #include "ace/OS_NS_sys_mman.h"
00043 #include "ace/Guard_T.h"
00044 #include "ace/OS_NS_string.h"
00045 #include "ace/OS_NS_sys_time.h"
00046
00047 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00048
00049 ACE_Dev_Poll_Reactor_Notify::ACE_Dev_Poll_Reactor_Notify (void)
00050 : dp_reactor_ (0)
00051 , notification_pipe_ ()
00052 , max_notify_iterations_ (-1)
00053 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00054 , notification_queue_ ()
00055 #endif
00056 , dispatching_ (false)
00057 {
00058 }
00059
00060 int
00061 ACE_Dev_Poll_Reactor_Notify::open (ACE_Reactor_Impl *r,
00062 ACE_Timer_Queue * ,
00063 int disable_notify_pipe)
00064 {
00065 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::open");
00066
00067 if (disable_notify_pipe == 0)
00068 {
00069 this->dp_reactor_ = dynamic_cast<ACE_Dev_Poll_Reactor *> (r);
00070
00071 if (this->dp_reactor_ == 0)
00072 {
00073 errno = EINVAL;
00074 return -1;
00075 }
00076
00077 if (this->notification_pipe_.open () == -1)
00078 return -1;
00079
00080 #if defined (F_SETFD)
00081
00082 ACE_OS::fcntl (this->notification_pipe_.read_handle (), F_SETFD, 1);
00083 ACE_OS::fcntl (this->notification_pipe_.write_handle (), F_SETFD, 1);
00084 #endif
00085
00086 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00087 if (notification_queue_.open () == -1)
00088 {
00089 return -1;
00090 }
00091
00092 if (ACE::set_flags (this->notification_pipe_.write_handle (),
00093 ACE_NONBLOCK) == -1)
00094 return -1;
00095 #endif
00096
00097
00098
00099
00100 if (ACE::set_flags (this->notification_pipe_.read_handle (),
00101 ACE_NONBLOCK) == -1)
00102 return -1;
00103 }
00104
00105 return 0;
00106 }
00107
00108 int
00109 ACE_Dev_Poll_Reactor_Notify::close (void)
00110 {
00111 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::close");
00112
00113 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00114 notification_queue_.reset ();
00115 #endif
00116
00117 return this->notification_pipe_.close ();
00118 }
00119
00120 int
00121 ACE_Dev_Poll_Reactor_Notify::notify (ACE_Event_Handler *eh,
00122 ACE_Reactor_Mask mask,
00123 ACE_Time_Value *timeout)
00124 {
00125 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::notify");
00126
00127
00128
00129 if (this->dp_reactor_ == 0)
00130 return 0;
00131
00132 ACE_Notification_Buffer buffer (eh, mask);
00133
00134 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00135 ACE_UNUSED_ARG (timeout);
00136 ACE_Dev_Poll_Handler_Guard eh_guard (eh);
00137
00138
00139
00140 int push_result = this->notification_queue_.push_new_notification (buffer);
00141 if (-1 == push_result || 1 == push_result)
00142 return -1 == push_result ? -1 : 0;
00143
00144
00145
00146 eh_guard.release ();
00147
00148
00149
00150
00151
00152
00153 ssize_t n = ACE::send (this->notification_pipe_.write_handle (),
00154 (char *) &buffer,
00155 1);
00156 if (n == -1 && (errno != EAGAIN))
00157 return -1;
00158
00159 return 0;
00160 #else
00161
00162 ACE_Dev_Poll_Handler_Guard eh_guard (eh);
00163
00164 ssize_t n = ACE::send (this->notification_pipe_.write_handle (),
00165 (char *) &buffer,
00166 sizeof buffer,
00167 timeout);
00168 if (n == -1)
00169 return -1;
00170
00171 eh_guard.release ();
00172
00173 return 0;
00174 #endif
00175 }
00176
00177 int
00178 ACE_Dev_Poll_Reactor_Notify::dispatch_notifications (
00179 int & ,
00180 ACE_Handle_Set & )
00181 {
00182 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::dispatch_notifications");
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 ACE_NOTSUP_RETURN (-1);
00193 }
00194
00195 int
00196 ACE_Dev_Poll_Reactor_Notify::read_notify_pipe (ACE_HANDLE handle,
00197 ACE_Notification_Buffer &buffer)
00198 {
00199 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::read_notify_pipe");
00200
00201
00202
00203
00204
00205
00206
00207
00208 size_t to_read;
00209 char *read_p;
00210
00211 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00212
00213
00214
00215
00216
00217
00218
00219 char b[1024];
00220 read_p = b;
00221 to_read = sizeof(b);
00222 (void)ACE::recv (handle, read_p, to_read);
00223
00224 bool more_messages_queued = false;
00225 ACE_Notification_Buffer next;
00226 int result = notification_queue_.pop_next_notification (buffer,
00227 more_messages_queued,
00228 next);
00229
00230 if (result <= 0)
00231 return result;
00232
00233
00234
00235
00236 if (more_messages_queued)
00237 (void) ACE::send (this->notification_pipe_.write_handle (),
00238 (char *)&next,
00239 1);
00240 return 1;
00241 #else
00242 to_read = sizeof buffer;
00243 read_p = (char *)&buffer;
00244
00245 ssize_t n = ACE::recv (handle, read_p, to_read);
00246
00247 if (n > 0)
00248 {
00249
00250 if (static_cast<size_t> (n) != to_read)
00251 {
00252 size_t remainder = to_read - n;
00253
00254
00255
00256
00257
00258 if (ACE::recv (handle, &read_p[n], remainder) <= 0)
00259 return -1;
00260 }
00261
00262 return 1;
00263 }
00264
00265
00266 if (n <= 0 && (errno != EWOULDBLOCK && errno != EAGAIN))
00267 return -1;
00268
00269 return 0;
00270 #endif
00271 }
00272
00273
00274 int
00275 ACE_Dev_Poll_Reactor_Notify::handle_input (ACE_HANDLE handle)
00276 {
00277 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::handle_input");
00278
00279 {
00280 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->dispatching_lock_, -1));
00281 if (this->dispatching_)
00282 return 0;
00283 this->dispatching_ = true;
00284 }
00285
00286 int number_dispatched = 0;
00287 int result = 0;
00288 ACE_Notification_Buffer buffer;
00289
00290 while ((result = this->read_notify_pipe (handle, buffer)) > 0)
00291 {
00292
00293
00294 if (this->dispatch_notify (buffer) > 0)
00295 ++number_dispatched;
00296
00297
00298
00299
00300 if (number_dispatched == this->max_notify_iterations_)
00301 break;
00302 }
00303
00304 if (result == -1)
00305 {
00306
00307
00308 number_dispatched = -1;
00309 }
00310
00311 this->dispatching_ = false;
00312
00313 return number_dispatched;
00314 }
00315
00316 ACE_HANDLE
00317 ACE_Dev_Poll_Reactor_Notify::notify_handle (void)
00318 {
00319 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::notify_handle");
00320
00321 return this->notification_pipe_.read_handle ();
00322 }
00323
00324 int
00325 ACE_Dev_Poll_Reactor_Notify::is_dispatchable (ACE_Notification_Buffer &)
00326 {
00327 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::is_dispatchable");
00328
00329 ACE_NOTSUP_RETURN (-1);
00330 }
00331
00332 int
00333 ACE_Dev_Poll_Reactor_Notify::dispatch_notify (ACE_Notification_Buffer &buffer)
00334 {
00335 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::dispatch_notify");
00336
00337
00338
00339
00340
00341
00342 if (buffer.eh_ != 0)
00343 {
00344 int result = 0;
00345
00346
00347
00348
00349 ACE_Dev_Poll_Handler_Guard eh_guard (buffer.eh_, false);
00350
00351 switch (buffer.mask_)
00352 {
00353 case ACE_Event_Handler::READ_MASK:
00354 case ACE_Event_Handler::ACCEPT_MASK:
00355 result = buffer.eh_->handle_input (ACE_INVALID_HANDLE);
00356 break;
00357 case ACE_Event_Handler::WRITE_MASK:
00358 result = buffer.eh_->handle_output (ACE_INVALID_HANDLE);
00359 break;
00360 case ACE_Event_Handler::EXCEPT_MASK:
00361 result = buffer.eh_->handle_exception (ACE_INVALID_HANDLE);
00362 break;
00363 default:
00364
00365 ACE_ERROR ((LM_ERROR,
00366 ACE_TEXT ("dispatch_notify invalid mask = %d\n"),
00367 buffer.mask_));
00368 }
00369 if (result == -1)
00370 buffer.eh_->handle_close (ACE_INVALID_HANDLE, buffer.mask_);
00371 }
00372
00373 return 1;
00374 }
00375
00376 void
00377 ACE_Dev_Poll_Reactor_Notify::max_notify_iterations (int iterations)
00378 {
00379 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::max_notify_iterations");
00380
00381
00382 if (iterations == 0)
00383 iterations = 1;
00384
00385 this->max_notify_iterations_ = iterations;
00386 }
00387
00388 int
00389 ACE_Dev_Poll_Reactor_Notify::max_notify_iterations (void)
00390 {
00391 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::max_notify_iterations");
00392
00393 return this->max_notify_iterations_;
00394 }
00395
00396 int
00397 ACE_Dev_Poll_Reactor_Notify::purge_pending_notifications (
00398 ACE_Event_Handler *eh,
00399 ACE_Reactor_Mask mask)
00400 {
00401 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::purge_pending_notifications");
00402
00403 #if defined (ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
00404
00405 return notification_queue_.purge_pending_notifications (eh, mask);
00406
00407 #else
00408 ACE_UNUSED_ARG (eh);
00409 ACE_UNUSED_ARG (mask);
00410 ACE_NOTSUP_RETURN (-1);
00411 #endif
00412 }
00413
00414 void
00415 ACE_Dev_Poll_Reactor_Notify::dump (void) const
00416 {
00417 #if defined (ACE_HAS_DUMP)
00418 ACE_TRACE ("ACE_Dev_Poll_Reactor_Notify::dump");
00419
00420 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00421 ACE_DEBUG ((LM_DEBUG,
00422 ACE_TEXT ("dp_reactor_ = %@"),
00423 this->dp_reactor_));
00424 this->notification_pipe_.dump ();
00425 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00426 #endif
00427 }
00428
00429
00430
00431 ACE_Dev_Poll_Reactor::Handler_Repository::Handler_Repository (void)
00432 : size_ (0),
00433 max_size_ (0),
00434 handlers_ (0)
00435 {
00436 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::Handler_Repository");
00437 }
00438
00439 bool
00440 ACE_Dev_Poll_Reactor::Handler_Repository::invalid_handle (
00441 ACE_HANDLE handle) const
00442 {
00443 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::invalid_handle");
00444
00445 if (handle < 0 || handle >= this->max_size_)
00446 {
00447 errno = EINVAL;
00448 return true;
00449 }
00450 else
00451 return false;
00452 }
00453
00454 bool
00455 ACE_Dev_Poll_Reactor::Handler_Repository::handle_in_range (
00456 ACE_HANDLE handle) const
00457 {
00458 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::handle_in_range");
00459
00460 if (handle >= 0 && handle < this->max_size_)
00461 return true;
00462 else
00463 {
00464 errno = EINVAL;
00465 return false;
00466 }
00467 }
00468
00469 int
00470 ACE_Dev_Poll_Reactor::Handler_Repository::open (size_t size)
00471 {
00472 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::open");
00473
00474 this->max_size_ = size;
00475
00476
00477 ACE_NEW_RETURN (this->handlers_, Event_Tuple[size], -1);
00478
00479
00480
00481 return ACE::set_handle_limit (size);
00482 }
00483
00484 int
00485 ACE_Dev_Poll_Reactor::Handler_Repository::unbind_all (void)
00486 {
00487 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::unbind_all");
00488
00489
00490 for (int handle = 0;
00491 handle < this->max_size_;
00492 ++handle)
00493 {
00494 Event_Tuple *entry = this->find (handle);
00495 if (entry == 0)
00496 continue;
00497
00498
00499 bool const requires_reference_counting =
00500 entry->event_handler->reference_counting_policy ().value () ==
00501 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00502
00503 (void) entry->event_handler->handle_close (handle, entry->mask);
00504 this->unbind (handle, requires_reference_counting);
00505 }
00506
00507 return 0;
00508 }
00509
00510 int
00511 ACE_Dev_Poll_Reactor::Handler_Repository::close (void)
00512 {
00513 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::close");
00514
00515 if (this->handlers_ != 0)
00516 {
00517 this->unbind_all ();
00518
00519 delete [] this->handlers_;
00520 this->handlers_ = 0;
00521 }
00522
00523 return 0;
00524 }
00525
00526 ACE_Dev_Poll_Reactor::Event_Tuple *
00527 ACE_Dev_Poll_Reactor::Handler_Repository::find (ACE_HANDLE handle)
00528 {
00529 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::find");
00530
00531 Event_Tuple *tuple = 0;
00532
00533
00534 if (!this->handle_in_range (handle))
00535 {
00536 errno = ERANGE;
00537 return 0;
00538 }
00539
00540 tuple = &(this->handlers_[handle]);
00541 if (tuple->event_handler == 0)
00542 {
00543 errno = ENOENT;
00544 tuple = 0;
00545 }
00546
00547 return tuple;
00548 }
00549
00550 int
00551 ACE_Dev_Poll_Reactor::Handler_Repository::bind (
00552 ACE_HANDLE handle,
00553 ACE_Event_Handler *event_handler,
00554 ACE_Reactor_Mask mask)
00555 {
00556 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::bind");
00557
00558 if (event_handler == 0)
00559 return -1;
00560
00561 if (handle == ACE_INVALID_HANDLE)
00562 handle = event_handler->get_handle ();
00563
00564 if (this->invalid_handle (handle))
00565 return -1;
00566
00567 this->handlers_[handle].event_handler = event_handler;
00568 this->handlers_[handle].mask = mask;
00569 event_handler->add_reference ();
00570 ++this->size_;
00571
00572 return 0;
00573 }
00574
00575 int
00576 ACE_Dev_Poll_Reactor::Handler_Repository::unbind (ACE_HANDLE handle,
00577 bool decr_refcnt)
00578 {
00579 ACE_TRACE ("ACE_Dev_Poll_Reactor::Handler_Repository::unbind");
00580
00581 Event_Tuple *entry = this->find (handle);
00582 if (entry == 0)
00583 return -1;
00584
00585 if (decr_refcnt)
00586 entry->event_handler->remove_reference ();
00587
00588 entry->event_handler = 0;
00589 entry->mask = ACE_Event_Handler::NULL_MASK;
00590 entry->suspended = false;
00591 entry->controlled = false;
00592 --this->size_;
00593 return 0;
00594 }
00595
00596
00597
00598 ACE_Dev_Poll_Reactor::ACE_Dev_Poll_Reactor (ACE_Sig_Handler *sh,
00599 ACE_Timer_Queue *tq,
00600 int disable_notify_pipe,
00601 ACE_Reactor_Notify *notify,
00602 int mask_signals,
00603 int s_queue)
00604 : initialized_ (false)
00605 , poll_fd_ (ACE_INVALID_HANDLE)
00606
00607 #if defined (ACE_HAS_EVENT_POLL)
00608 , epoll_wait_in_progress_ (false)
00609 #endif
00610 #if defined (ACE_HAS_DEV_POLL)
00611 , dp_fds_ (0)
00612 , start_pfds_ (0)
00613 , end_pfds_ (0)
00614 #endif
00615 , deactivated_ (0)
00616 , token_ (*this, s_queue)
00617 , lock_adapter_ (token_)
00618 , timer_queue_ (0)
00619 , delete_timer_queue_ (false)
00620 , signal_handler_ (0)
00621 , delete_signal_handler_ (false)
00622 , notify_handler_ (0)
00623 , delete_notify_handler_ (false)
00624 , mask_signals_ (mask_signals)
00625 , restart_ (0)
00626 {
00627 ACE_TRACE ("ACE_Dev_Poll_Reactor::ACE_Dev_Poll_Reactor");
00628
00629 if (this->open (ACE::max_handles (),
00630 0,
00631 sh,
00632 tq,
00633 disable_notify_pipe,
00634 notify) == -1)
00635 ACE_ERROR ((LM_ERROR,
00636 ACE_TEXT ("%p\n"),
00637 ACE_TEXT ("ACE_Dev_Poll_Reactor::open ")
00638 ACE_TEXT ("failed inside ")
00639 ACE_TEXT ("ACE_Dev_Poll_Reactor::CTOR")));
00640 }
00641
00642 ACE_Dev_Poll_Reactor::ACE_Dev_Poll_Reactor (size_t size,
00643 bool rs,
00644 ACE_Sig_Handler *sh,
00645 ACE_Timer_Queue *tq,
00646 int disable_notify_pipe,
00647 ACE_Reactor_Notify *notify,
00648 int mask_signals,
00649 int s_queue)
00650 : initialized_ (false)
00651 , poll_fd_ (ACE_INVALID_HANDLE)
00652
00653 #if defined (ACE_HAS_DEV_POLL)
00654 , dp_fds_ (0)
00655 , start_pfds_ (0)
00656 , end_pfds_ (0)
00657 #endif
00658 , deactivated_ (0)
00659 , token_ (*this, s_queue)
00660 , lock_adapter_ (token_)
00661 , timer_queue_ (0)
00662 , delete_timer_queue_ (false)
00663 , signal_handler_ (0)
00664 , delete_signal_handler_ (false)
00665 , notify_handler_ (0)
00666 , delete_notify_handler_ (false)
00667 , mask_signals_ (mask_signals)
00668 , restart_ (0)
00669 {
00670 if (this->open (size,
00671 rs,
00672 sh,
00673 tq,
00674 disable_notify_pipe,
00675 notify) == -1)
00676 ACE_ERROR ((LM_ERROR,
00677 ACE_TEXT ("%p\n"),
00678 ACE_TEXT ("ACE_Dev_Poll_Reactor::open ")
00679 ACE_TEXT ("failed inside ACE_Dev_Poll_Reactor::CTOR")));
00680 }
00681
00682 ACE_Dev_Poll_Reactor::~ACE_Dev_Poll_Reactor (void)
00683 {
00684 ACE_TRACE ("ACE_Dev_Poll_Reactor::~ACE_Dev_Poll_Reactor");
00685
00686 (void) this->close ();
00687 }
00688
00689 int
00690 ACE_Dev_Poll_Reactor::open (size_t size,
00691 bool restart,
00692 ACE_Sig_Handler *sh,
00693 ACE_Timer_Queue *tq,
00694 int disable_notify_pipe,
00695 ACE_Reactor_Notify *notify)
00696 {
00697 ACE_TRACE ("ACE_Dev_Poll_Reactor::open");
00698
00699 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
00700
00701
00702 if (this->initialized_)
00703 return -1;
00704
00705 #ifdef ACE_HAS_EVENT_POLL
00706 ACE_OS::memset (&this->event_, 0, sizeof (this->event_));
00707 this->event_.data.fd = ACE_INVALID_HANDLE;
00708 #endif
00709
00710 this->restart_ = restart;
00711 this->signal_handler_ = sh;
00712 this->timer_queue_ = tq;
00713 this->notify_handler_ = notify;
00714
00715 int result = 0;
00716
00717
00718 if (this->signal_handler_ == 0)
00719 {
00720 ACE_NEW_RETURN (this->signal_handler_,
00721 ACE_Sig_Handler,
00722 -1);
00723
00724 if (this->signal_handler_ == 0)
00725 result = -1;
00726 else
00727 this->delete_signal_handler_ = true;
00728 }
00729
00730
00731 if (result != -1 && this->timer_queue_ == 0)
00732 {
00733 ACE_NEW_RETURN (this->timer_queue_,
00734 ACE_Timer_Heap,
00735 -1);
00736
00737 if (this->timer_queue_ == 0)
00738 result = -1;
00739 else
00740 this->delete_timer_queue_ = true;
00741 }
00742
00743
00744 if (result != -1 && this->notify_handler_ == 0)
00745 {
00746 ACE_NEW_RETURN (this->notify_handler_,
00747 ACE_Dev_Poll_Reactor_Notify,
00748 -1);
00749
00750 if (this->notify_handler_ == 0)
00751 result = -1;
00752 else
00753 this->delete_notify_handler_ = true;
00754 }
00755
00756 #if defined (ACE_HAS_EVENT_POLL)
00757
00758
00759 this->poll_fd_ = ::epoll_create (size);
00760 if (this->poll_fd_ == -1)
00761 result = -1;
00762
00763 #else
00764
00765
00766
00767 ACE_NEW_RETURN (this->dp_fds_,
00768 pollfd[size],
00769 -1);
00770
00771
00772 this->poll_fd_ = ACE_OS::open ("/dev/poll", O_RDWR);
00773 if (this->poll_fd_ == ACE_INVALID_HANDLE)
00774 result = -1;
00775
00776 #endif
00777
00778 if (result != -1 && this->handler_rep_.open (size) == -1)
00779 result = -1;
00780
00781
00782
00783 else if (this->notify_handler_->open (this,
00784 0,
00785 disable_notify_pipe) == -1
00786 || (disable_notify_pipe == 0
00787 && this->register_handler_i (
00788 this->notify_handler_->notify_handle (),
00789 this->notify_handler_,
00790 ACE_Event_Handler::READ_MASK) == -1))
00791 result = -1;
00792
00793 if (result != -1)
00794
00795 this->initialized_ = true;
00796 else
00797
00798 (void) this->close ();
00799
00800 return result;
00801 }
00802
00803 int
00804 ACE_Dev_Poll_Reactor::current_info (ACE_HANDLE, size_t & )
00805 {
00806 ACE_NOTSUP_RETURN (-1);
00807 }
00808
00809
00810 int
00811 ACE_Dev_Poll_Reactor::set_sig_handler (ACE_Sig_Handler *signal_handler)
00812 {
00813 if (this->delete_signal_handler_)
00814 delete this->signal_handler_;
00815
00816 this->signal_handler_ = signal_handler;
00817 this->delete_signal_handler_ = false;
00818
00819 return 0;
00820 }
00821
00822 int
00823 ACE_Dev_Poll_Reactor::timer_queue (ACE_Timer_Queue *tq)
00824 {
00825 if (this->delete_timer_queue_)
00826 delete this->timer_queue_;
00827
00828 this->timer_queue_ = tq;
00829 this->delete_timer_queue_ = false;
00830
00831 return 0;
00832
00833 }
00834
00835 ACE_Timer_Queue *
00836 ACE_Dev_Poll_Reactor::timer_queue (void) const
00837 {
00838 return this->timer_queue_;
00839 }
00840
00841 int
00842 ACE_Dev_Poll_Reactor::close (void)
00843 {
00844 ACE_TRACE ("ACE_Dev_Poll_Reactor::close");
00845
00846 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
00847
00848 int result = 0;
00849
00850 if (this->poll_fd_ != ACE_INVALID_HANDLE)
00851 {
00852 result = ACE_OS::close (this->poll_fd_);
00853 }
00854
00855 #if defined (ACE_HAS_EVENT_POLL)
00856
00857 ACE_OS::memset (&this->event_, 0, sizeof (this->event_));
00858 this->event_.data.fd = ACE_INVALID_HANDLE;
00859
00860 #else
00861
00862 delete [] this->dp_fds_;
00863 this->dp_fds_ = 0;
00864 this->start_pfds_ = 0;
00865 this->end_pfds_ = 0;
00866
00867 #endif
00868
00869 if (this->delete_signal_handler_)
00870 {
00871 delete this->signal_handler_;
00872 this->signal_handler_ = 0;
00873 this->delete_signal_handler_ = false;
00874 }
00875
00876 (void) this->handler_rep_.close ();
00877
00878 if (this->delete_timer_queue_)
00879 {
00880 delete this->timer_queue_;
00881 this->timer_queue_ = 0;
00882 this->delete_timer_queue_ = false;
00883 }
00884
00885 if (this->notify_handler_ != 0)
00886 this->notify_handler_->close ();
00887
00888 if (this->delete_notify_handler_)
00889 {
00890 delete this->notify_handler_;
00891 this->notify_handler_ = 0;
00892 this->delete_notify_handler_ = false;
00893 }
00894
00895 this->poll_fd_ = ACE_INVALID_HANDLE;
00896
00897 this->initialized_ = false;
00898
00899 return result;
00900 }
00901
00902 int
00903 ACE_Dev_Poll_Reactor::work_pending (const ACE_Time_Value & max_wait_time)
00904 {
00905 ACE_TRACE ("ACE_Dev_Poll_Reactor::work_pending");
00906
00907
00908
00909
00910
00911 ACE_Time_Value mwt (max_wait_time);
00912 ACE_MT (ACE_Countdown_Time countdown (&mwt));
00913
00914 Token_Guard guard (this->token_);
00915 int const result = guard.acquire_quietly (&mwt);
00916
00917
00918 if (!guard.is_owner ())
00919 return result;
00920
00921
00922 ACE_MT (countdown.update ());
00923
00924 return this->work_pending_i (&mwt);
00925 }
00926
00927 int
00928 ACE_Dev_Poll_Reactor::work_pending_i (ACE_Time_Value * max_wait_time)
00929 {
00930 ACE_TRACE ("ACE_Dev_Poll_Reactor::work_pending_i");
00931
00932 if (this->deactivated_)
00933 return 0;
00934
00935 #if defined (ACE_HAS_EVENT_POLL)
00936 if (this->event_.data.fd != ACE_INVALID_HANDLE)
00937 #else
00938 if (this->start_pfds_ != this->end_pfds_)
00939 #endif
00940 return 1;
00941
00942
00943 ACE_Time_Value timer_buf (0);
00944 ACE_Time_Value *this_timeout =
00945 this->timer_queue_->calculate_timeout (max_wait_time, &timer_buf);
00946
00947
00948 int const timers_pending =
00949 ((this_timeout != 0 && max_wait_time == 0)
00950 || (this_timeout != 0 && max_wait_time != 0
00951 && *this_timeout != *max_wait_time) ? 1 : 0);
00952
00953 long const timeout =
00954 (this_timeout == 0
00955 ? -1
00956 : static_cast<long> (this_timeout->msec ()));
00957
00958 #if defined (ACE_HAS_EVENT_POLL)
00959
00960
00961 {
00962 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, grd, this->to_be_resumed_lock_, -1);
00963 this->epoll_wait_in_progress_ = true;
00964 for (Resume_Map::iterator i = this->to_be_resumed_.begin ();
00965 i != this->to_be_resumed_.end ();
00966 ++i)
00967 {
00968
00969
00970 Event_Tuple *info = this->handler_rep_.find (i->first);
00971 if (info != 0 && info->event_handler == i->second)
00972 {
00973 this->resume_handler_i (i->first);
00974 }
00975 }
00976 this->to_be_resumed_.clear ();
00977 }
00978
00979
00980 int const nfds = ::epoll_wait (this->poll_fd_,
00981 &this->event_,
00982 1,
00983 static_cast<int> (timeout));
00984
00985
00986 this->epoll_wait_in_progress_ = false;
00987
00988 #else
00989
00990 struct dvpoll dvp;
00991
00992 dvp.dp_fds = this->dp_fds_;
00993 dvp.dp_nfds = this->handler_rep_.size ();
00994 dvp.dp_timeout = timeout;
00995
00996
00997 int const nfds = ACE_OS::ioctl (this->poll_fd_, DP_POLL, &dvp);
00998
00999
01000 this->start_pfds_ = dvp.dp_fds;
01001
01002
01003
01004
01005 if (nfds > -1)
01006 this->end_pfds_ = this->start_pfds_ + nfds;
01007 #endif
01008
01009
01010 return (nfds == 0 && timers_pending != 0 ? 1 : nfds);
01011 }
01012
01013
01014 int
01015 ACE_Dev_Poll_Reactor::handle_events (ACE_Time_Value *max_wait_time)
01016 {
01017 ACE_TRACE ("ACE_Dev_Poll_Reactor::handle_events");
01018
01019
01020
01021
01022
01023 ACE_MT (ACE_Countdown_Time countdown (max_wait_time));
01024
01025 Token_Guard guard (this->token_);
01026 int const result = guard.acquire_quietly (max_wait_time);
01027
01028
01029 if (!guard.is_owner ())
01030 return result;
01031
01032 if (this->deactivated_)
01033 return -1;
01034
01035
01036 ACE_MT (countdown.update ());
01037
01038 return this->handle_events_i (max_wait_time, guard);
01039 }
01040
01041 int
01042 ACE_Dev_Poll_Reactor::handle_events_i (ACE_Time_Value *max_wait_time,
01043 Token_Guard &guard)
01044 {
01045 ACE_TRACE ("ACE_Dev_Poll_Reactor::handle_events_i");
01046
01047 int result = 0;
01048
01049
01050
01051
01052
01053
01054 do
01055 {
01056 result = this->work_pending_i (max_wait_time);
01057 if (result == -1 && (this->restart_ == 0 || errno != EINTR))
01058 ACE_ERROR ((LM_ERROR, ACE_TEXT("%t: %p\n"), ACE_TEXT("work_pending_i")));
01059 }
01060 while (result == -1 && this->restart_ != 0 && errno == EINTR);
01061
01062 if (result == 0 || (result == -1 && errno == ETIME))
01063 return 0;
01064 else if (result == -1)
01065 {
01066 if (errno != EINTR)
01067 return -1;
01068
01069
01070
01071
01072
01073 if (ACE_Sig_Handler::sig_pending () != 0)
01074 {
01075 ACE_Sig_Handler::sig_pending (0);
01076 return 1;
01077 }
01078 return -1;
01079 }
01080
01081
01082 return this->dispatch (guard);
01083 }
01084
01085
01086
01087 int
01088 ACE_Dev_Poll_Reactor::dispatch (Token_Guard &guard)
01089 {
01090 ACE_TRACE ("ACE_Dev_Poll_Reactor::dispatch");
01091
01092
01093
01094
01095
01096 int result = 0;
01097
01098
01099
01100
01101 if ((result = this->dispatch_timer_handler (guard)) != 0)
01102 return result;
01103
01104
01105 result = this->dispatch_io_event (guard);
01106
01107 return result;
01108 }
01109
01110 int
01111 ACE_Dev_Poll_Reactor::dispatch_timer_handler (Token_Guard &guard)
01112 {
01113 if (this->timer_queue_->is_empty ())
01114 return 0;
01115
01116
01117 ACE_Time_Value cur_time (this->timer_queue_->gettimeofday () +
01118 this->timer_queue_->timer_skew ());
01119
01120
01121
01122 ACE_Timer_Node_Dispatch_Info info;
01123 if (this->timer_queue_->dispatch_info (cur_time, info))
01124 {
01125 const void *upcall_act = 0;
01126
01127
01128 this->timer_queue_->preinvoke (info, cur_time, upcall_act);
01129
01130
01131 guard.release_token ();
01132
01133
01134 this->timer_queue_->upcall (info, cur_time);
01135
01136
01137 this->timer_queue_->postinvoke (info, cur_time, upcall_act);
01138
01139
01140 return 1;
01141 }
01142
01143 return 0;
01144 }
01145
01146 #if 0
01147 int
01148 ACE_Dev_Poll_Reactor::dispatch_notification_handlers (
01149 ACE_Select_Reactor_Handle_Set &dispatch_set,
01150 int &number_of_active_handles,
01151 int &number_of_handlers_dispatched)
01152 {
01153
01154
01155
01156
01157
01158
01159
01160 const int n =
01161 this->notify_handler_->dispatch_notifications (number_of_active_handles,
01162 dispatch_set.rd_mask_);
01163
01164 if (n == -1)
01165 return -1;
01166 else
01167 number_of_handlers_dispatched += n;
01168
01169 return 0;
01170 }
01171 #endif
01172
01173 int
01174 ACE_Dev_Poll_Reactor::dispatch_io_event (Token_Guard &guard)
01175 {
01176
01177
01178
01179
01180 #if defined (ACE_HAS_EVENT_POLL)
01181 const __uint32_t out_event = EPOLLOUT;
01182 const __uint32_t exc_event = EPOLLPRI;
01183 const __uint32_t in_event = EPOLLIN;
01184 const __uint32_t err_event = EPOLLHUP | EPOLLERR;
01185 #else
01186 const short out_event = POLLOUT;
01187 const short exc_event = POLLPRI;
01188 const short in_event = POLLIN;
01189 const short err_event = 0;
01190 #endif
01191
01192 #if defined (ACE_HAS_EVENT_POLL)
01193
01194
01195
01196 const ACE_HANDLE handle = this->event_.data.fd;
01197 __uint32_t revents = this->event_.events;
01198 this->event_.data.fd = ACE_INVALID_HANDLE;
01199 this->event_.events = 0;
01200 if (handle != ACE_INVALID_HANDLE)
01201
01202 #else
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218 struct pollfd *& pfds = this->start_pfds_;
01219 const ACE_HANDLE handle = pfds->fd;
01220 short &revents = pfds->revents;
01221 if (pfds < this->end_pfds_)
01222 #endif
01223
01224 {
01225
01226
01227
01228
01229
01230
01231 Event_Tuple *info = this->handler_rep_.find (handle);
01232 if (info == 0)
01233 {
01234 #ifdef ACE_HAS_EVENT_POLL
01235 this->event_.data.fd = ACE_INVALID_HANDLE;
01236 #endif
01237 return 0;
01238 }
01239
01240
01241
01242
01243
01244
01245
01246 ACE_Reactor_Mask disp_mask = 0;
01247 ACE_Event_Handler *eh = info->event_handler;
01248 int (ACE_Event_Handler::*callback)(ACE_HANDLE) = 0;
01249 if (ACE_BIT_ENABLED (revents, out_event))
01250 {
01251 disp_mask = ACE_Event_Handler::WRITE_MASK;
01252 callback = &ACE_Event_Handler::handle_output;
01253 ACE_CLR_BITS (revents, out_event);
01254 }
01255 else if (ACE_BIT_ENABLED (revents, exc_event))
01256 {
01257 disp_mask = ACE_Event_Handler::EXCEPT_MASK;
01258 callback = &ACE_Event_Handler::handle_exception;
01259 ACE_CLR_BITS (revents, exc_event);
01260 }
01261 else if (ACE_BIT_ENABLED (revents, in_event))
01262 {
01263 disp_mask = ACE_Event_Handler::READ_MASK;
01264 callback = &ACE_Event_Handler::handle_input;
01265 ACE_CLR_BITS (revents, in_event);
01266 }
01267 else if (ACE_BIT_ENABLED (revents, err_event))
01268 {
01269 this->remove_handler_i (handle,
01270 ACE_Event_Handler::ALL_EVENTS_MASK,
01271 info->event_handler);
01272 #ifdef ACE_HAS_DEV_POLL
01273 ++pfds;
01274 #endif
01275 return 1;
01276 }
01277 else
01278 {
01279 ACE_ERROR ((LM_ERROR,
01280 ACE_TEXT ("(%t) dispatch_io h %d unknown events 0x%x\n"),
01281 handle, revents));
01282 }
01283
01284 #ifdef ACE_HAS_DEV_POLL
01285
01286
01287
01288 if (revents == 0)
01289 ++pfds;
01290 #else
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300 bool reactor_resumes_eh = false;
01301 if (eh != this->notify_handler_)
01302 {
01303 info->suspended = true;
01304
01305 reactor_resumes_eh =
01306 eh->resume_handler () ==
01307 ACE_Event_Handler::ACE_REACTOR_RESUMES_HANDLER;
01308 }
01309 #endif
01310
01311 int status = 0;
01312 {
01313
01314
01315
01316
01317
01318 ACE_Dev_Poll_Handler_Guard eh_guard (eh);
01319
01320
01321 guard.release_token ();
01322
01323
01324
01325
01326
01327
01328 status = this->upcall (eh, callback, handle);
01329
01330 if (eh == this->notify_handler_)
01331 return status;
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342 if (status == 0)
01343 {
01344 #ifdef ACE_HAS_EVENT_POLL
01345
01346
01347 if (reactor_resumes_eh)
01348 {
01349 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
01350 grd,
01351 this->to_be_resumed_lock_,
01352 -1);
01353 bool map_was_empty = this->to_be_resumed_.empty();
01354 this->to_be_resumed_.insert
01355 (Resume_Map::value_type (handle, eh));
01356 if (this->epoll_wait_in_progress_ && map_was_empty)
01357 this->notify();
01358 }
01359 #endif
01360 return 1;
01361 }
01362
01363
01364
01365
01366
01367
01368 guard.acquire ();
01369 info = this->handler_rep_.find (handle);
01370 if (info != 0 && info->event_handler == eh)
01371 {
01372 if (status < 0)
01373 this->remove_handler_i (handle, disp_mask);
01374 }
01375 }
01376
01377
01378 return 1;
01379 }
01380
01381 return 0;
01382 }
01383
01384 int
01385 ACE_Dev_Poll_Reactor::alertable_handle_events (ACE_Time_Value *max_wait_time)
01386 {
01387 ACE_TRACE ("ACE_Dev_Poll_Reactor::alertable_handle_events");
01388
01389 return this->handle_events (max_wait_time);
01390 }
01391
01392 int
01393 ACE_Dev_Poll_Reactor::handle_events (ACE_Time_Value &max_wait_time)
01394 {
01395 ACE_TRACE ("ACE_Dev_Poll_Reactor::handle_events");
01396
01397 return this->handle_events (&max_wait_time);
01398 }
01399
01400 int
01401 ACE_Dev_Poll_Reactor::alertable_handle_events (ACE_Time_Value &max_wait_time)
01402 {
01403 ACE_TRACE ("ACE_Dev_Poll_Reactor::alertable_handle_events");
01404
01405 return this->handle_events (max_wait_time);
01406 }
01407
01408 int
01409 ACE_Dev_Poll_Reactor::deactivated (void)
01410 {
01411 return this->deactivated_;
01412 }
01413
01414 void
01415 ACE_Dev_Poll_Reactor::deactivate (int do_stop)
01416 {
01417 this->deactivated_ = do_stop;
01418 this->wakeup_all_threads ();
01419 }
01420
01421 int
01422 ACE_Dev_Poll_Reactor::register_handler (ACE_Event_Handler *handler,
01423 ACE_Reactor_Mask mask)
01424 {
01425 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler");
01426
01427 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01428
01429 return this->register_handler_i (handler->get_handle (),
01430 handler,
01431 mask);
01432 }
01433
01434 int
01435 ACE_Dev_Poll_Reactor::register_handler (ACE_HANDLE handle,
01436 ACE_Event_Handler *event_handler,
01437 ACE_Reactor_Mask mask)
01438 {
01439 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler");
01440
01441 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01442
01443 return this->register_handler_i (handle,
01444 event_handler,
01445 mask);
01446 }
01447
01448 int
01449 ACE_Dev_Poll_Reactor::register_handler_i (ACE_HANDLE handle,
01450 ACE_Event_Handler *event_handler,
01451 ACE_Reactor_Mask mask)
01452 {
01453 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler_i");
01454
01455 if (handle == ACE_INVALID_HANDLE
01456 || mask == ACE_Event_Handler::NULL_MASK)
01457 {
01458 errno = EINVAL;
01459 return -1;
01460 }
01461
01462 if (this->handler_rep_.find (handle) == 0)
01463 {
01464
01465 if (this->handler_rep_.bind (handle, event_handler, mask) != 0)
01466 return -1;
01467
01468 #if defined (ACE_HAS_EVENT_POLL)
01469
01470 Event_Tuple *info = this->handler_rep_.find (handle);
01471
01472 struct epoll_event epev;
01473 ACE_OS::memset (&epev, 0, sizeof (epev));
01474 static const int op = EPOLL_CTL_ADD;
01475
01476 epev.data.fd = handle;
01477 epev.events = this->reactor_mask_to_poll_event (mask);
01478
01479
01480
01481 if (event_handler != this->notify_handler_)
01482 epev.events |= EPOLLONESHOT;
01483
01484 if (::epoll_ctl (this->poll_fd_, op, handle, &epev) == -1)
01485 {
01486 ACE_ERROR ((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("epoll_ctl")));
01487 (void) this->handler_rep_.unbind (handle);
01488 return -1;
01489 }
01490 info->controlled = true;
01491
01492 #endif
01493 }
01494 else
01495 {
01496
01497
01498
01499 if (this->mask_ops_i (handle, mask, ACE_Reactor::ADD_MASK) == -1)
01500 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("mask_ops_i")),
01501 -1);
01502 }
01503
01504 #ifdef ACE_HAS_DEV_POLL
01505
01506 struct pollfd pfd;
01507
01508 pfd.fd = handle;
01509 pfd.events = this->reactor_mask_to_poll_event (mask);
01510 pfd.revents = 0;
01511
01512
01513 if (ACE_OS::write (this->poll_fd_, &pfd, sizeof (pfd)) != sizeof (pfd))
01514 {
01515 (void) this->handler_rep_.unbind (handle);
01516 return -1;
01517 }
01518 #endif
01519
01520
01521
01522
01523
01524
01525 return 0;
01526 }
01527
01528 int
01529 ACE_Dev_Poll_Reactor::register_handler (
01530 ACE_HANDLE ,
01531 ACE_HANDLE ,
01532 ACE_Event_Handler * ,
01533 ACE_Reactor_Mask )
01534 {
01535 ACE_NOTSUP_RETURN (-1);
01536 }
01537
01538 int
01539 ACE_Dev_Poll_Reactor::register_handler (const ACE_Handle_Set &handle_set,
01540 ACE_Event_Handler *event_handler,
01541 ACE_Reactor_Mask mask)
01542 {
01543 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler");
01544
01545 ACE_Handle_Set_Iterator handle_iter (handle_set);
01546
01547 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01548
01549
01550
01551
01552
01553
01554 for (ACE_HANDLE h = handle_iter ();
01555 h != ACE_INVALID_HANDLE;
01556 h = handle_iter ())
01557 if (this->register_handler_i (h, event_handler, mask) == -1)
01558 return -1;
01559
01560 return 0;
01561 }
01562
01563 int
01564 ACE_Dev_Poll_Reactor::register_handler (int signum,
01565 ACE_Event_Handler *new_sh,
01566 ACE_Sig_Action *new_disp,
01567 ACE_Event_Handler **old_sh,
01568 ACE_Sig_Action *old_disp)
01569 {
01570 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler");
01571
01572 return this->signal_handler_->register_handler (signum,
01573 new_sh,
01574 new_disp,
01575 old_sh,
01576 old_disp);
01577 }
01578
01579 int
01580 ACE_Dev_Poll_Reactor::register_handler (const ACE_Sig_Set &sigset,
01581 ACE_Event_Handler *new_sh,
01582 ACE_Sig_Action *new_disp)
01583 {
01584 ACE_TRACE ("ACE_Dev_Poll_Reactor::register_handler");
01585
01586 int result = 0;
01587
01588 #if (ACE_NSIG > 0)
01589
01590 for (int s = 1; s < ACE_NSIG; ++s)
01591 if ((sigset.is_member (s) == 1)
01592 && this->signal_handler_->register_handler (s,
01593 new_sh,
01594 new_disp) == -1)
01595 result = -1;
01596
01597 #else
01598
01599 ACE_UNUSED_ARG (sigset);
01600 ACE_UNUSED_ARG (new_sh);
01601 ACE_UNUSED_ARG (new_disp);
01602
01603 #endif
01604
01605 return result;
01606 }
01607
01608 int
01609 ACE_Dev_Poll_Reactor::remove_handler (ACE_Event_Handler *handler,
01610 ACE_Reactor_Mask mask)
01611 {
01612 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler");
01613
01614 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01615
01616 return this->remove_handler_i (handler->get_handle (), mask);
01617 }
01618
01619 int
01620 ACE_Dev_Poll_Reactor::remove_handler (ACE_HANDLE handle,
01621 ACE_Reactor_Mask mask)
01622 {
01623 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler");
01624
01625 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01626
01627 return this->remove_handler_i (handle, mask);
01628 }
01629
01630 int
01631 ACE_Dev_Poll_Reactor::remove_handler_i (ACE_HANDLE handle,
01632 ACE_Reactor_Mask mask,
01633 ACE_Event_Handler *eh)
01634 {
01635 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler_i");
01636
01637
01638
01639 bool handle_reg_changed = true;
01640 Event_Tuple *info = this->handler_rep_.find (handle);
01641 if (info == 0 && eh == 0)
01642 return -1;
01643 if (info != 0 && (eh == 0 || info->event_handler == eh))
01644 {
01645 if (this->mask_ops_i (handle, mask, ACE_Reactor::CLR_MASK) == -1)
01646 return -1;
01647 handle_reg_changed = false;
01648 eh = info->event_handler;
01649 }
01650
01651
01652 bool const requires_reference_counting =
01653 eh->reference_counting_policy ().value () ==
01654 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
01655
01656 if (ACE_BIT_DISABLED (mask, ACE_Event_Handler::DONT_CALL))
01657 (void) eh->handle_close (handle, mask);
01658
01659
01660
01661 if (!handle_reg_changed && info->mask == ACE_Event_Handler::NULL_MASK)
01662 this->handler_rep_.unbind (handle, requires_reference_counting);
01663
01664 return 0;
01665 }
01666
01667 int
01668 ACE_Dev_Poll_Reactor::remove_handler (const ACE_Handle_Set &handle_set,
01669 ACE_Reactor_Mask mask)
01670 {
01671 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler");
01672
01673 ACE_Handle_Set_Iterator handle_iter (handle_set);
01674
01675 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01676
01677
01678
01679
01680
01681
01682 for (ACE_HANDLE h = handle_iter ();
01683 h != ACE_INVALID_HANDLE;
01684 h = handle_iter ())
01685 if (this->remove_handler_i (h, mask) == -1)
01686 return -1;
01687
01688 return 0;
01689 }
01690
01691 int
01692 ACE_Dev_Poll_Reactor::remove_handler (int signum,
01693 ACE_Sig_Action *new_disp,
01694 ACE_Sig_Action *old_disp,
01695 int sigkey)
01696 {
01697 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler");
01698
01699 return this->signal_handler_->remove_handler (signum,
01700 new_disp,
01701 old_disp,
01702 sigkey);
01703 }
01704
01705 int
01706 ACE_Dev_Poll_Reactor::remove_handler (const ACE_Sig_Set &sigset)
01707 {
01708 ACE_TRACE ("ACE_Dev_Poll_Reactor::remove_handler");
01709
01710 int result = 0;
01711
01712 #if (ACE_NSIG > 0)
01713
01714 for (int s = 1; s < ACE_NSIG; ++s)
01715 if ((sigset.is_member (s) == 1)
01716 && this->signal_handler_->remove_handler (s) == -1)
01717 result = -1;
01718
01719 #else
01720
01721 ACE_UNUSED_ARG (sigset);
01722
01723 #endif
01724
01725 return result;
01726 }
01727
01728 int
01729 ACE_Dev_Poll_Reactor::suspend_handler (ACE_Event_Handler *event_handler)
01730 {
01731 ACE_TRACE ("ACE_Dev_Poll_Reactor::suspend_handler");
01732
01733 if (event_handler == 0)
01734 {
01735 errno = EINVAL;
01736 return -1;
01737 }
01738
01739 ACE_HANDLE handle = event_handler->get_handle ();
01740
01741 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01742
01743 return this->suspend_handler_i (handle);
01744 }
01745
01746 int
01747 ACE_Dev_Poll_Reactor::suspend_handler (ACE_HANDLE handle)
01748 {
01749 ACE_TRACE ("ACE_Dev_Poll_Reactor::suspend_handler");
01750
01751 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01752
01753 return this->suspend_handler_i (handle);
01754 }
01755
01756 int
01757 ACE_Dev_Poll_Reactor::suspend_handler (const ACE_Handle_Set &handles)
01758 {
01759 ACE_TRACE ("ACE_Dev_Poll_Reactor::suspend_handler");
01760
01761 ACE_Handle_Set_Iterator handle_iter (handles);
01762 ACE_HANDLE h;
01763
01764 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01765
01766 while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
01767 if (this->suspend_handler_i (h) == -1)
01768 return -1;
01769
01770 return 0;
01771 }
01772
01773 int
01774 ACE_Dev_Poll_Reactor::suspend_handlers (void)
01775 {
01776 ACE_TRACE ("ACE_Dev_Poll_Reactor::suspend_handlers");
01777
01778 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01779
01780 size_t const len = this->handler_rep_.max_size ();
01781
01782 for (size_t i = 0; i < len; ++i)
01783 {
01784 Event_Tuple *info = this->handler_rep_.find (i);
01785 if (info != 0 && !info->suspended && this->suspend_handler_i (i) != 0)
01786 return -1;
01787 }
01788 return 0;
01789 }
01790
01791 int
01792 ACE_Dev_Poll_Reactor::suspend_handler_i (ACE_HANDLE handle)
01793 {
01794 ACE_TRACE ("ACE_Dev_Poll_Reactor::suspend_handler_i");
01795
01796 Event_Tuple *info = this->handler_rep_.find (handle);
01797 if (info == 0)
01798 return -1;
01799
01800 if (info->suspended)
01801 return 0;
01802
01803
01804
01805
01806
01807
01808
01809 #if defined (ACE_HAS_EVENT_POLL)
01810
01811 struct epoll_event epev;
01812 ACE_OS::memset (&epev, 0, sizeof (epev));
01813 static const int op = EPOLL_CTL_DEL;
01814
01815 epev.events = 0;
01816 epev.data.fd = handle;
01817
01818 if (::epoll_ctl (this->poll_fd_, op, handle, &epev) == -1)
01819 return -1;
01820 info->controlled = false;
01821 #else
01822
01823 struct pollfd pfd[1];
01824
01825 pfd[0].fd = handle;
01826 pfd[0].events = POLLREMOVE;
01827 pfd[0].revents = 0;
01828
01829 if (ACE_OS::write (this->poll_fd_, pfd, sizeof (pfd)) != sizeof (pfd))
01830 return -1;
01831
01832 #endif
01833
01834 info->suspended = true;
01835
01836 return 0;
01837 }
01838
01839 int
01840 ACE_Dev_Poll_Reactor::resume_handler (ACE_Event_Handler *event_handler)
01841 {
01842 ACE_TRACE ("ACE_Dev_Poll_Reactor::resume_handler");
01843
01844 if (event_handler == 0)
01845 {
01846 errno = EINVAL;
01847 return -1;
01848 }
01849
01850 ACE_HANDLE handle = event_handler->get_handle ();
01851
01852 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01853
01854 return this->resume_handler_i (handle);
01855 }
01856
01857 int
01858 ACE_Dev_Poll_Reactor::resume_handler (ACE_HANDLE handle)
01859 {
01860 ACE_TRACE ("ACE_Dev_Poll_Reactor::resume_handler");
01861
01862 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01863
01864 return this->resume_handler_i (handle);
01865 }
01866
01867 int
01868 ACE_Dev_Poll_Reactor::resume_handler (const ACE_Handle_Set &handles)
01869 {
01870 ACE_TRACE ("ACE_Dev_Poll_Reactor::resume_handler");
01871
01872 ACE_Handle_Set_Iterator handle_iter (handles);
01873 ACE_HANDLE h;
01874
01875 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01876
01877 while ((h = handle_iter ()) != ACE_INVALID_HANDLE)
01878 if (this->resume_handler_i (h) == -1)
01879 return -1;
01880
01881 return 0;
01882 }
01883
01884 int
01885 ACE_Dev_Poll_Reactor::resume_handlers (void)
01886 {
01887 ACE_TRACE ("ACE_Dev_Poll_Reactor::resume_handlers");
01888
01889 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01890
01891 size_t const len = this->handler_rep_.max_size ();
01892
01893 for (size_t i = 0; i < len; ++i)
01894 {
01895 Event_Tuple *info = this->handler_rep_.find (i);
01896 if (info != 0 && info->suspended && this->resume_handler_i (i) != 0)
01897 return -1;
01898 }
01899
01900 return 0;
01901 }
01902
01903 int
01904 ACE_Dev_Poll_Reactor::resume_handler_i (ACE_HANDLE handle)
01905 {
01906 ACE_TRACE ("ACE_Dev_Poll_Reactor::resume_handler_i");
01907
01908 Event_Tuple *info = this->handler_rep_.find (handle);
01909 if (info == 0)
01910 return -1;
01911
01912 if (!info->suspended)
01913 return 0;
01914
01915 ACE_Reactor_Mask mask = info->mask;
01916 if (mask == ACE_Event_Handler::NULL_MASK)
01917 {
01918 info->suspended = false;
01919 return 0;
01920 }
01921
01922
01923
01924
01925
01926 #if defined (ACE_HAS_EVENT_POLL)
01927
01928 struct epoll_event epev;
01929 ACE_OS::memset (&epev, 0, sizeof (epev));
01930 int op = EPOLL_CTL_ADD;
01931 if (info->controlled)
01932 op = EPOLL_CTL_MOD;
01933 epev.events = this->reactor_mask_to_poll_event (mask) | EPOLLONESHOT;
01934 epev.data.fd = handle;
01935
01936 if (::epoll_ctl (this->poll_fd_, op, handle, &epev) == -1)
01937 return -1;
01938 info->controlled = true;
01939
01940 #else
01941
01942 struct pollfd pfd[1];
01943
01944 pfd[0].fd = handle;
01945 pfd[0].events = this->reactor_mask_to_poll_event (mask);
01946 pfd[0].revents = 0;
01947
01948 if (ACE_OS::write (this->poll_fd_, pfd, sizeof (pfd)) != sizeof (pfd))
01949 return -1;
01950
01951 #endif
01952
01953 info->suspended = false;
01954
01955 return 0;
01956 }
01957
01958 int
01959 ACE_Dev_Poll_Reactor::resumable_handler (void)
01960 {
01961
01962
01963 return 0;
01964 }
01965
01966 bool
01967 ACE_Dev_Poll_Reactor::uses_event_associations (void)
01968 {
01969
01970
01971 return false;
01972 }
01973
01974 long
01975 ACE_Dev_Poll_Reactor::schedule_timer (ACE_Event_Handler *event_handler,
01976 const void *arg,
01977 const ACE_Time_Value &delay,
01978 const ACE_Time_Value &interval)
01979 {
01980 ACE_TRACE ("ACE_Dev_Poll_Reactor::schedule_timer");
01981
01982 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
01983
01984 if (0 != this->timer_queue_)
01985 return this->timer_queue_->schedule
01986 (event_handler,
01987 arg,
01988 this->timer_queue_->gettimeofday () + delay,
01989 interval);
01990
01991 errno = ESHUTDOWN;
01992 return -1;
01993 }
01994
01995 int
01996 ACE_Dev_Poll_Reactor::reset_timer_interval (long timer_id,
01997 const ACE_Time_Value &interval)
01998 {
01999 ACE_TRACE ("ACE_Dev_Poll_Reactor::reset_timer_interval");
02000
02001 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02002
02003 if (0 != this->timer_queue_)
02004 return this->timer_queue_->reset_interval (timer_id, interval);
02005
02006 errno = ESHUTDOWN;
02007 return -1;
02008 }
02009
02010 int
02011 ACE_Dev_Poll_Reactor::cancel_timer (ACE_Event_Handler *event_handler,
02012 int dont_call_handle_close)
02013 {
02014 ACE_TRACE ("ACE_Dev_Poll_Reactor::cancel_timer");
02015
02016 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02017
02018 return (this->timer_queue_ == 0
02019 ? 0
02020 : this->timer_queue_->cancel (event_handler,
02021 dont_call_handle_close));
02022 }
02023
02024 int
02025 ACE_Dev_Poll_Reactor::cancel_timer (long timer_id,
02026 const void **arg,
02027 int dont_call_handle_close)
02028 {
02029 ACE_TRACE ("ACE_Dev_Poll_Reactor::cancel_timer");
02030
02031 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02032
02033 return (this->timer_queue_ == 0
02034 ? 0
02035 : this->timer_queue_->cancel (timer_id,
02036 arg,
02037 dont_call_handle_close));
02038 }
02039
02040 int
02041 ACE_Dev_Poll_Reactor::schedule_wakeup (ACE_Event_Handler *eh,
02042 ACE_Reactor_Mask mask)
02043 {
02044 ACE_TRACE ("ACE_Dev_Poll_Reactor::schedule_wakeup");
02045
02046 return this->mask_ops (eh->get_handle (), mask, ACE_Reactor::ADD_MASK);
02047 }
02048
02049 int
02050 ACE_Dev_Poll_Reactor::schedule_wakeup (ACE_HANDLE handle,
02051 ACE_Reactor_Mask mask)
02052 {
02053 ACE_TRACE ("ACE_Dev_Poll_Reactor::schedule_wakeup");
02054
02055 return this->mask_ops (handle, mask, ACE_Reactor::ADD_MASK);
02056 }
02057
02058 int
02059 ACE_Dev_Poll_Reactor::cancel_wakeup (ACE_Event_Handler *eh,
02060 ACE_Reactor_Mask mask)
02061 {
02062 ACE_TRACE ("ACE_Dev_Poll_Reactor::cancel_wakeup");
02063
02064 return this->mask_ops (eh->get_handle (), mask, ACE_Reactor::CLR_MASK);
02065 }
02066
02067 int
02068 ACE_Dev_Poll_Reactor::cancel_wakeup (ACE_HANDLE handle,
02069 ACE_Reactor_Mask mask)
02070 {
02071 ACE_TRACE ("ACE_Dev_Poll_Reactor::cancel_wakeup");
02072
02073 return this->mask_ops (handle, mask, ACE_Reactor::CLR_MASK);
02074 }
02075
02076 int
02077 ACE_Dev_Poll_Reactor::notify (ACE_Event_Handler *eh,
02078 ACE_Reactor_Mask mask,
02079 ACE_Time_Value *timeout)
02080 {
02081 ACE_TRACE ("ACE_Dev_Poll_Reactor::notify");
02082
02083 ssize_t n = 0;
02084
02085
02086
02087
02088
02089 n = this->notify_handler_->notify (eh, mask, timeout);
02090
02091 return n == -1 ? -1 : 0;
02092 }
02093
02094 void
02095 ACE_Dev_Poll_Reactor::max_notify_iterations (int iterations)
02096 {
02097 ACE_TRACE ("ACE_Dev_Poll_Reactor::max_notify_iterations");
02098
02099 ACE_MT (ACE_GUARD (ACE_Dev_Poll_Reactor_Token, mon, this->token_));
02100
02101 this->notify_handler_->max_notify_iterations (iterations);
02102 }
02103
02104 int
02105 ACE_Dev_Poll_Reactor::max_notify_iterations (void)
02106 {
02107 ACE_TRACE ("ACE_Dev_Poll_Reactor::max_notify_iterations");
02108
02109 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02110
02111 return this->notify_handler_->max_notify_iterations ();
02112 }
02113
02114 int
02115 ACE_Dev_Poll_Reactor::purge_pending_notifications (ACE_Event_Handler * eh,
02116 ACE_Reactor_Mask mask)
02117 {
02118 if (this->notify_handler_ == 0)
02119 return 0;
02120
02121 return this->notify_handler_->purge_pending_notifications (eh, mask);
02122 }
02123
02124 ACE_Event_Handler *
02125 ACE_Dev_Poll_Reactor::find_handler (ACE_HANDLE handle)
02126 {
02127 ACE_MT (ACE_READ_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, 0));
02128
02129 Event_Tuple *info = this->handler_rep_.find (handle);
02130 if (info)
02131 {
02132 info->event_handler->add_reference ();
02133 return info->event_handler;
02134 }
02135 else
02136 {
02137 return 0;
02138 }
02139 }
02140
02141 int
02142 ACE_Dev_Poll_Reactor::handler (ACE_HANDLE handle,
02143 ACE_Reactor_Mask mask,
02144 ACE_Event_Handler **event_handler)
02145 {
02146 ACE_TRACE ("ACE_Dev_Poll_Reactor::handler");
02147
02148 ACE_MT (ACE_READ_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02149
02150 Event_Tuple *info = this->handler_rep_.find (handle);
02151
02152 if (info != 0
02153 && ACE_BIT_CMP_MASK (info->mask,
02154 mask,
02155 mask))
02156 {
02157 if (event_handler != 0)
02158 *event_handler = info->event_handler;
02159
02160 return 0;
02161 }
02162
02163 return -1;
02164 }
02165
02166 int
02167 ACE_Dev_Poll_Reactor::handler (int signum,
02168 ACE_Event_Handler **eh)
02169 {
02170 ACE_TRACE ("ACE_Dev_Poll_Reactor::handler");
02171
02172 ACE_Event_Handler *handler = this->signal_handler_->handler (signum);
02173
02174 if (handler == 0)
02175 return -1;
02176 else if (eh != 0)
02177 *eh = handler;
02178
02179 return 0;
02180 }
02181
02182 bool
02183 ACE_Dev_Poll_Reactor::initialized (void)
02184 {
02185 ACE_TRACE ("ACE_Dev_Poll_Reactor::initialized");
02186
02187 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, false));
02188
02189 return this->initialized_;
02190 }
02191
02192 size_t
02193 ACE_Dev_Poll_Reactor::size (void) const
02194 {
02195 return this->handler_rep_.size ();
02196 }
02197
02198 ACE_Lock &
02199 ACE_Dev_Poll_Reactor::lock (void)
02200 {
02201 ACE_TRACE ("ACE_Dev_Poll_Reactor::lock");
02202
02203 return this->lock_adapter_;
02204 }
02205
02206 void
02207 ACE_Dev_Poll_Reactor::wakeup_all_threads (void)
02208 {
02209 ACE_TRACE ("ACE_Dev_Poll_Reactor::wakeup_all_threads");
02210
02211
02212
02213 this->notify (0,
02214 ACE_Event_Handler::NULL_MASK,
02215 (ACE_Time_Value *) &ACE_Time_Value::zero);
02216 }
02217
02218 int
02219 ACE_Dev_Poll_Reactor::owner (ACE_thread_t ,
02220 ACE_thread_t * )
02221 {
02222 ACE_TRACE ("ACE_Dev_Poll_Reactor::owner");
02223
02224
02225
02226
02227 return 0;
02228 }
02229
02230 int
02231 ACE_Dev_Poll_Reactor::owner (ACE_thread_t * )
02232 {
02233 ACE_TRACE ("ACE_Dev_Poll_Reactor::owner");
02234
02235
02236
02237
02238 return 0;
02239 }
02240
02241 bool
02242 ACE_Dev_Poll_Reactor::restart (void)
02243 {
02244 ACE_TRACE ("ACE_Dev_Poll_Reactor::restart");
02245
02246 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, false));
02247
02248 return this->restart_;
02249 }
02250
02251 bool
02252 ACE_Dev_Poll_Reactor::restart (bool r)
02253 {
02254 ACE_TRACE ("ACE_Dev_Poll_Reactor::restart");
02255
02256 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, false));
02257
02258 bool current_value = this->restart_;
02259 this->restart_ = r;
02260 return current_value;
02261 }
02262
02263 void
02264 ACE_Dev_Poll_Reactor::requeue_position (int)
02265 {
02266 ACE_TRACE ("ACE_Dev_Poll_Reactor::requeue_position");
02267 }
02268
02269 int
02270 ACE_Dev_Poll_Reactor::requeue_position (void)
02271 {
02272 ACE_TRACE ("ACE_Dev_Poll_Reactor::requeue_position");
02273
02274 ACE_NOTSUP_RETURN (-1);
02275 }
02276
02277 int
02278 ACE_Dev_Poll_Reactor::mask_ops (ACE_Event_Handler *event_handler,
02279 ACE_Reactor_Mask mask,
02280 int ops)
02281 {
02282 ACE_TRACE ("ACE_Dev_Poll_Reactor::mask_ops");
02283
02284 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02285
02286 return this->mask_ops_i (event_handler->get_handle (), mask, ops);
02287 }
02288
02289 int
02290 ACE_Dev_Poll_Reactor::mask_ops (ACE_HANDLE handle,
02291 ACE_Reactor_Mask mask,
02292 int ops)
02293 {
02294 ACE_TRACE ("ACE_Dev_Poll_Reactor::mask_ops");
02295
02296 ACE_MT (ACE_GUARD_RETURN (ACE_Dev_Poll_Reactor_Token, mon, this->token_, -1));
02297
02298 return this->mask_ops_i (handle, mask, ops);
02299 }
02300
02301 int
02302 ACE_Dev_Poll_Reactor::mask_ops_i (ACE_HANDLE handle,
02303 ACE_Reactor_Mask mask,
02304 int ops)
02305 {
02306 ACE_TRACE ("ACE_Dev_Poll_Reactor::mask_ops_i");
02307
02308 Event_Tuple *info = this->handler_rep_.find (handle);
02309 if (info == 0)
02310 return -1;
02311
02312
02313 ACE_Sig_Guard sb;
02314
02315 ACE_Reactor_Mask const old_mask = info->mask;
02316 ACE_Reactor_Mask new_mask = old_mask;
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330 switch (ops)
02331 {
02332 case ACE_Reactor::GET_MASK:
02333
02334
02335 return old_mask;
02336
02337 case ACE_Reactor::CLR_MASK:
02338 ACE_CLR_BITS (new_mask, mask);
02339 break;
02340
02341 case ACE_Reactor::SET_MASK:
02342 new_mask = mask;
02343 break;
02344
02345 case ACE_Reactor::ADD_MASK:
02346 ACE_SET_BITS (new_mask, mask);
02347 break;
02348
02349 default:
02350 return -1;
02351 }
02352
02353
02354 info->mask = new_mask;
02355
02356
02357
02358
02359
02360
02361 if (!info->suspended || (info->controlled && new_mask == 0))
02362 {
02363
02364 short const events = this->reactor_mask_to_poll_event (new_mask);
02365
02366 #if defined (sun)
02367
02368
02369 struct pollfd pfd[2];
02370
02371 pfd[0].fd = handle;
02372 pfd[0].events = POLLREMOVE;
02373 pfd[0].revents = 0;
02374 pfd[1].fd = (events == POLLREMOVE ? ACE_INVALID_HANDLE : handle);
02375 pfd[1].events = events;
02376 pfd[1].revents = 0;
02377
02378
02379 if (ACE_OS::write (this->poll_fd_,
02380 pfd,
02381 sizeof (pfd)) != sizeof (pfd))
02382 return -1;
02383 #elif defined (ACE_HAS_EVENT_POLL)
02384
02385 struct epoll_event epev;
02386 ACE_OS::memset (&epev, 0, sizeof (epev));
02387 int op;
02388
02389
02390 if (new_mask == 0)
02391 {
02392 op = EPOLL_CTL_DEL;
02393 epev.events = 0;
02394 }
02395 else
02396 {
02397 op = EPOLL_CTL_MOD;
02398 epev.events = events | EPOLLONESHOT;
02399 }
02400
02401 epev.data.fd = handle;
02402
02403 if (::epoll_ctl (this->poll_fd_, op, handle, &epev) == -1)
02404 {
02405
02406
02407
02408
02409 if (op == EPOLL_CTL_MOD && errno == ENOENT &&
02410 ::epoll_ctl (this->poll_fd_, EPOLL_CTL_ADD, handle, &epev) == -1)
02411 return -1;
02412 }
02413 info->controlled = (op != EPOLL_CTL_DEL);
02414 #else
02415 pollfd pfd[1];
02416
02417 pfd[0].fd = handle;
02418 pfd[0].events = events;
02419 pfd[0].revents = 0;
02420
02421
02422 if (ACE_OS::write (this->poll_fd_,
02423 pfd,
02424 sizeof (pfd)) != sizeof (pfd))
02425 return -1;
02426 #endif
02427 }
02428
02429 return old_mask;
02430 }
02431
02432 int
02433 ACE_Dev_Poll_Reactor::ready_ops (ACE_Event_Handler * ,
02434 ACE_Reactor_Mask ,
02435 int )
02436 {
02437 ACE_TRACE ("ACE_Dev_Poll_Reactor::ready_ops");
02438
02439
02440
02441
02442 ACE_NOTSUP_RETURN (-1);
02443 }
02444
02445 int
02446 ACE_Dev_Poll_Reactor::ready_ops (ACE_HANDLE ,
02447 ACE_Reactor_Mask ,
02448 int )
02449 {
02450 ACE_TRACE ("ACE_Dev_Poll_Reactor::ready_ops");
02451
02452
02453
02454
02455 ACE_NOTSUP_RETURN (-1);
02456 }
02457
02458 void
02459 ACE_Dev_Poll_Reactor::dump (void) const
02460 {
02461 #if defined (ACE_HAS_DUMP)
02462 ACE_TRACE ("ACE_Dev_Poll_Reactor::dump");
02463
02464 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
02465 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("restart_ = %d\n"), this->restart_));
02466 ACE_DEBUG ((LM_DEBUG,
02467 ACE_TEXT ("initialized_ = %d"),
02468 this->initialized_));
02469 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("poll_fd_ = %d"), this->poll_fd_));
02470 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("size_ = %u"), this->handler_rep_.size ()));
02471 ACE_DEBUG ((LM_DEBUG,
02472 ACE_TEXT ("deactivated_ = %d"),
02473 this->deactivated_));
02474 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
02475 #endif
02476 }
02477
02478 short
02479 ACE_Dev_Poll_Reactor::reactor_mask_to_poll_event (ACE_Reactor_Mask mask)
02480 {
02481 ACE_TRACE ("ACE_Dev_Poll_Reactor::reactor_mask_to_poll_event");
02482
02483 if (mask == ACE_Event_Handler::NULL_MASK)
02484
02485 #if defined (ACE_HAS_EVENT_POLL)
02486 return EPOLL_CTL_DEL;
02487 #else
02488 return POLLREMOVE;
02489 #endif
02490
02491 short events = 0;
02492
02493
02494
02495 if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::READ_MASK)
02496 || ACE_BIT_ENABLED (mask, ACE_Event_Handler::ACCEPT_MASK)
02497 || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
02498 {
02499 #if defined (ACE_HAS_EVENT_POLL)
02500 ACE_SET_BITS (events, EPOLLIN);
02501 #else
02502 ACE_SET_BITS (events, POLLIN);
02503 #endif
02504 }
02505
02506
02507 if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::WRITE_MASK)
02508 || ACE_BIT_ENABLED (mask, ACE_Event_Handler::CONNECT_MASK))
02509 {
02510 #if defined (ACE_HAS_EVENT_POLL)
02511 ACE_SET_BITS (events, EPOLLOUT);
02512 #else
02513 ACE_SET_BITS (events, POLLOUT);
02514 #endif
02515 }
02516
02517
02518 if (ACE_BIT_ENABLED (mask, ACE_Event_Handler::EXCEPT_MASK))
02519 {
02520 #if defined (ACE_HAS_EVENT_POLL)
02521 ACE_SET_BITS (events, EPOLLPRI);
02522 #else
02523 ACE_SET_BITS (events, POLLPRI);
02524 #endif
02525 }
02526
02527 return events;
02528 }
02529
02530 namespace {
02531 void polite_sleep_hook (void *) { }
02532 }
02533
02534 int
02535 ACE_Dev_Poll_Reactor::Token_Guard::acquire_quietly (ACE_Time_Value *max_wait)
02536 {
02537 ACE_TRACE ("ACE_Dev_Poll_Reactor::Token_Guard::acquire_quietly");
02538
02539
02540 int result = 0;
02541 if (max_wait)
02542 {
02543 ACE_Time_Value tv = ACE_OS::gettimeofday ();
02544 tv += *max_wait;
02545
02546 ACE_MT (result = this->token_.acquire_read (&polite_sleep_hook,
02547 0,
02548 &tv));
02549 }
02550 else
02551 {
02552 ACE_MT (result = this->token_.acquire_read (&polite_sleep_hook));
02553 }
02554
02555
02556 if (result == -1)
02557 {
02558 if (errno == ETIME)
02559 return 0;
02560 else
02561 {
02562 ACE_ERROR ((LM_ERROR, ACE_TEXT("%t: %p\n"), ACE_TEXT("token acquire_read")));
02563 return -1;
02564 }
02565 }
02566
02567
02568 this->owner_ = 1;
02569
02570 return result;
02571 }
02572
02573 int
02574 ACE_Dev_Poll_Reactor::Token_Guard::acquire (ACE_Time_Value *max_wait)
02575 {
02576 ACE_TRACE ("ACE_Dev_Poll_Reactor::Token_Guard::acquire");
02577
02578
02579
02580 int result = 0;
02581 if (max_wait)
02582 {
02583 ACE_Time_Value tv = ACE_OS::gettimeofday ();
02584 tv += *max_wait;
02585
02586 ACE_MT (result = this->token_.acquire (0, 0, &tv));
02587 }
02588 else
02589 {
02590 ACE_MT (result = this->token_.acquire ());
02591 }
02592
02593
02594 if (result == -1)
02595 {
02596 if (errno == ETIME)
02597 return 0;
02598 else
02599 return -1;
02600 }
02601
02602
02603 this->owner_ = 1;
02604
02605 return result;
02606 }
02607
02608 ACE_END_VERSIONED_NAMESPACE_DECL
02609
02610 #endif