3 //=============================================================================
7 * @author Irfan Pyarali <irfan@cs.wustl.edu>
8 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
10 //=============================================================================
15 #include /**/ "ace/pre.h"
17 // Timer Queue is a complicated template class. A simple forward
18 // declaration will not work.
19 #include "ace/Timer_Queuefwd.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 // Contains the timer related interface for the Reactor.
26 #include "ace/Reactor_Timer_Interface.h"
28 // Event_Handler.h contains the definition of ACE_Reactor_Mask
29 #include "ace/Event_Handler.h"
31 // Get ACE_Time_Value in
32 #include "ace/Time_Value.h"
34 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
36 class ACE_Reactor_Impl
;
39 class ACE_Sig_Handler
;
43 * Hook to specialize the Reactor implementation with the concrete
44 * Reactor type, for example, select, thread pool reactor known
47 //@@ REACTOR_SPL_INCLUDE_FORWARD_DECL_ADD_HOOK
52 * @brief This class forwards all methods to its delegation/implementation class, e.g.,
53 * ACE_Select_Reactor or ACE_WFMO_Reactor.
55 class ACE_Export ACE_Reactor
: public ACE_Reactor_Timer_Interface
58 /// Operations on the "ready" mask and the "dispatch" mask.
61 /// Retrieve current value of the the "ready" mask or the
64 /// Set value of bits to new mask (changes the entire mask).
66 /// Bitwise "or" the value into the mask (only changes enabled
69 /// Bitwise "and" the negation of the value out of the mask (only
70 /// changes enabled bits).
75 * You can specify a hook function to event-handling methods that will
76 * be called after each iteration of event handling. If the hook function
77 * returns a non-zero value, the event loop will immediately resume
78 * waiting for the next event(s) to process without checking the error
79 * status of the just-completed iteration of event handling or the
80 * end-of-loop indication. If the hook function returns 0, the event
81 * handling error status and the end-of-loop indication will be checked
82 * as normal, just as if there is no hook function specified.
84 typedef int (*REACTOR_EVENT_HOOK
)(ACE_Reactor
*);
86 /// Get pointer to a process-wide ACE_Reactor.
87 static ACE_Reactor
*instance (void);
90 * Set pointer to a process-wide ACE_Reactor and return existing
91 * pointer. If @a delete_reactor == true then we'll delete the Reactor
92 * at destruction time.
94 static ACE_Reactor
*instance (ACE_Reactor
*, bool delete_reactor
= false);
96 /// Delete the dynamically allocated Singleton
97 static void close_singleton (void);
99 /// Name of the dll in which the dll lives.
100 static const ACE_TCHAR
*dll_name (void);
102 /// Name of the component--ACE_Reactor in this case.
103 static const ACE_TCHAR
*name (void);
105 // = Singleton reactor event loop management methods.
107 // Note that these method ONLY work on the "Singleton Reactor,"
108 // i.e., the one returned from ACE_Reactor::instance().
110 * Run the event loop until the
111 * ACE_Reactor::handle_events()/ACE_Reactor::alertable_handle_events()
112 * method returns -1 or the end_event_loop() method is invoked.
113 * Note that this method can only be used by the singleton
114 * ACE_Reactor::instance(). Thus, to run another reactor use
115 * ACE_Reactor::run_reactor_event_loop().
117 * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
119 static int run_event_loop (void);
120 static int run_alertable_event_loop (void);
123 * Run the event loop until the ACE_Reactor::handle_events() or
124 * <ACE_Reactor::alertable_handle_events> methods returns -1, the
125 * end_event_loop() method is invoked, or the ACE_Time_Value
126 * expires. Note that this method can only be used by the singleton
127 * ACE_Reactor::instance(). Thus, to run another reactor use
128 * <ACE_Reactor::run_reactor_event_loop>.
130 * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
132 static int run_event_loop (ACE_Time_Value
&tv
);
133 static int run_alertable_event_loop (ACE_Time_Value
&tv
);
136 * Instruct the ACE_Reactor::instance() to terminate its event loop
137 * and notifies the ACE_Reactor::instance() so that it can wake up
138 * and close down gracefully. Note that this method can only be
139 * used by the singleton ACE_Reactor::instance(). Thus, to
140 * terminate another reactor, use
141 * <ACE_Reactor::end_reactor_event_loop>.
143 * @deprecated Use ACE_Reactor::instance()->end_reactor_event_loop() instead
145 static int end_event_loop (void);
148 * Report if the ACE_Reactor::instance()'s event loop is finished.
149 * Note that this method can only be used by the singleton
150 * ACE_Reactor::instance(). Thus, to check another reactor use
151 * <ACE_Reactor::reactor_event_loop_done>.
153 * @deprecated Use ACE_Reactor::instance()->reactor_event_loop_done() instead
155 static int event_loop_done (void);
158 * Resets the ACE_Reactor::end_event_loop_ static so that the
159 * run_event_loop() method can be restarted. Note that this method
160 * can only be used by the singleton ACE_Reactor::instance(). Thus,
161 * to reset another reactor use ACE_Reactor::reset_reactor_event_loop().
163 * @deprecated Use ACE_Reactor::instance()->reset_reactor_event_loop()
166 static void reset_event_loop (void);
169 * The singleton reactor is used by the ACE_Service_Config.
170 * Therefore, we must check for the reconfiguration request and
171 * handle it after handling an event.
173 static int check_reconfiguration (ACE_Reactor
*);
175 // = Reactor event loop management methods.
177 // These methods work with an instance of a reactor.
179 * Run the event loop until the ACE_Reactor::handle_events() or
180 * ACE_Reactor::alertable_handle_events() method returns -1 or
181 * the end_reactor_event_loop() method is invoked.
183 int run_reactor_event_loop (REACTOR_EVENT_HOOK
= 0);
184 int run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK
= 0);
187 * Run the event loop until the ACE_Reactor::handle_events() or
188 * ACE_Reactor::alertable_handle_events() method returns -1, the
189 * end_reactor_event_loop() method is invoked, or the ACE_Time_Value
190 * expires while the underlying event demultiplexer is waiting for
192 * Note that it is possible for events to continuously be available,
193 * avoiding the need to wait for events. In this situation the timeout
194 * value will not have an opportunity to expire until the next time
195 * the underlying event demultiplexer waits for events.
197 int run_reactor_event_loop (ACE_Time_Value
&tv
,
198 REACTOR_EVENT_HOOK
= 0);
199 int run_alertable_reactor_event_loop (ACE_Time_Value
&tv
,
200 REACTOR_EVENT_HOOK
= 0);
203 * Instruct the Reactor to terminate its event loop and notifies the
204 * Reactor so that it can wake up and deactivate
205 * itself. Deactivating the Reactor would allow the Reactor to be
206 * shutdown gracefully. Internally the Reactor calls deactivate ()
207 * on the underlying implementation.
208 * Any queued notifications remain queued on return from this method.
209 * If the event loop is restarted in the future, the notifications
210 * will be dispatched then. If the reactor is closed or deleted without
211 * further dispatching, the notifications will be lost.
213 int end_reactor_event_loop (void);
215 /// Indicate if the Reactor's event loop has been ended.
216 int reactor_event_loop_done (void);
218 /// Resets the ACE_Reactor::end_event_loop_ static so that the
219 /// run_event_loop() method can be restarted.
220 void reset_reactor_event_loop (void);
223 * Create the Reactor using @a implementation. The flag
224 * @a delete_implementation tells the Reactor whether or not to
225 * delete the @a implementation on destruction.
227 ACE_Reactor (ACE_Reactor_Impl
*implementation
= 0,
228 bool delete_implementation
= false);
230 /// Close down and release all resources.
232 * Any notifications that remain queued on this reactor instance are
235 virtual ~ACE_Reactor (void);
238 * Initialize the ACE_Reactor to manage @a max_number_of_handles.
239 * If @a restart is false then the ACE_Reactor's handle_events()
240 * method will be restarted automatically when @c EINTR occurs. If
241 * @a signal_handler or @a timer_queue are non-0 they are used as the
242 * signal handler and timer queue, respectively.
244 int open (size_t max_number_of_handles
,
245 bool restart
= false,
246 ACE_Sig_Handler
*signal_handler
= 0,
247 ACE_Timer_Queue
*timer_queue
= 0);
249 /// Use a user specified signal handler instead.
250 int set_sig_handler (ACE_Sig_Handler
*signal_handler
);
252 /// Set a user-specified timer queue.
253 int timer_queue (ACE_Timer_Queue
*tq
);
255 /// Return the current ACE_Timer_Queue.
256 ACE_Timer_Queue
*timer_queue (void) const;
258 /// Close down and release all resources.
261 // = Event loop drivers.
264 * Returns non-zero if there are I/O events "ready" for dispatching,
265 * but does not actually dispatch the event handlers. By default,
266 * don't block while checking this, i.e., "poll".
268 int work_pending (const ACE_Time_Value
&max_wait_time
= ACE_Time_Value::zero
);
271 * This event loop driver blocks for up to @a max_wait_time before
272 * returning. It will return earlier if events occur. Note that
273 * @a max_wait_time can be 0, in which case this method blocks
274 * indefinitely until events occur.
276 * @a max_wait_time is decremented to reflect how much time this call
277 * took. For instance, if a time value of 3 seconds is passed to
278 * handle_events and an event occurs after 2 seconds,
279 * @a max_wait_time will equal 1 second. This can be used if an
280 * application wishes to handle events for some fixed amount of
283 * Returns the total number of timers and I/O ACE_Event_Handlers
284 * that were dispatched, 0 if the @a max_wait_time elapsed without
285 * dispatching any handlers, or -1 if an error occurs.
287 * The only difference between alertable_handle_events() and
288 * handle_events() is that in the alertable case, the eventloop will
289 * return when the system queues an I/O completion routine or an
290 * Asynchronous Procedure Call.
292 int handle_events (ACE_Time_Value
*max_wait_time
= 0);
293 int alertable_handle_events (ACE_Time_Value
*max_wait_time
= 0);
296 * This method is just like the one above, except the
297 * @a max_wait_time value is a reference and can therefore never be
300 * The only difference between alertable_handle_events() and
301 * handle_events() is that in the alertable case, the eventloop will
302 * return when the system queues an I/O completion routine or an
303 * Asynchronous Procedure Call.
305 int handle_events (ACE_Time_Value
&max_wait_time
);
306 int alertable_handle_events (ACE_Time_Value
&max_wait_time
);
308 // = Register and remove handlers.
311 * Register handler for I/O events.
313 * A handler can be associated with multiple handles. A handle
314 * cannot be associated with multiple handlers.
316 * The handle will come from ACE_Event_Handler::get_handle().
318 * Reactor will call ACE_Event_Handler::add_reference() for a new
319 * handler/handle pair.
321 * If this handler/handle pair has already been registered, any new
322 * masks specified will be added. In this case,
323 * ACE_Event_Handler::add_reference() will not be called.
325 * If the registered handler is currently suspended, it will remain
326 * suspended. When the handler is resumed, it will have the
327 * existing masks plus any masks added through this call. Handlers
328 * do not have partial suspensions.
330 int register_handler (ACE_Event_Handler
*event_handler
,
331 ACE_Reactor_Mask mask
);
334 * Register handler for I/O events.
336 * Same as register_handler(ACE_Event_Handler*,ACE_Reactor_Mask),
337 * except handle is explicitly specified.
339 int register_handler (ACE_HANDLE io_handle
,
340 ACE_Event_Handler
*event_handler
,
341 ACE_Reactor_Mask mask
);
343 #if defined (ACE_WIN32)
345 * Register handler for OS events.
347 * Register an @a event_handler that will be notified when
348 * <event_handle> is signaled. This will call back its
349 * <handle_signal> hook method.
351 * Reactor will call ACE_Event_Handler::add_reference() for a new
352 * handler/handle pair.
354 * This interface is only available Win32 platforms because
355 * ACE_HANDLE is an int on non-Win32 platforms and compilers are not
356 * able to tell the difference between
357 * register_handler(ACE_Event_Handler*,ACE_Reactor_Mask) and
358 * register_handler(ACE_Event_Handler*,ACE_HANDLE).
360 int register_handler (ACE_Event_Handler
*event_handler
,
361 ACE_HANDLE event_handle
= ACE_INVALID_HANDLE
);
362 #endif /* ACE_WIN32 */
365 * Register handler for I/O events.
368 * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
369 * except that the user gets to specify the event handle that will
370 * be used for this registration. This only applies to Reactors
371 * that use event handles for I/O registrations.
373 int register_handler (ACE_HANDLE event_handle
,
374 ACE_HANDLE io_handle
,
375 ACE_Event_Handler
*event_handler
,
376 ACE_Reactor_Mask mask
);
379 * Register handler for multiple I/O events.
381 * Shorthand for calling
382 * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
383 * multiple times for the same @a event_handler and @a masks but
384 * different @a handles.
386 int register_handler (const ACE_Handle_Set
&handles
,
387 ACE_Event_Handler
*event_handler
,
388 ACE_Reactor_Mask masks
);
391 * Register handler for signals.
393 * Register @a new_sh to handle the signal @a signum using the
394 * @a new_disp. Returns the @a old_sh that was previously registered
395 * (if any), along with the @a old_disp of the signal handler.
397 * Reactor will call ACE_Event_Handler::add_reference() on @a new_sh
398 * and ACE_Event_Handler::remove_reference() on @a old_sh.
400 int register_handler (int signum
,
401 ACE_Event_Handler
*new_sh
,
402 ACE_Sig_Action
*new_disp
= 0,
403 ACE_Event_Handler
**old_sh
= 0,
404 ACE_Sig_Action
*old_disp
= 0);
407 * Register handler for multiple signals.
409 * Shorthand for calling
410 * register_handler(int,ACE_Event_Handler*,ACE_Sig_Action*,ACE_Event_Handler**,ACE_Sig_Action*)
411 * multiple times for the same @a event_handler and @a sig_action but
412 * different <signals>.
414 int register_handler (const ACE_Sig_Set
&sigset
,
415 ACE_Event_Handler
*event_handler
,
416 ACE_Sig_Action
*sig_action
= 0);
419 * Remove @a masks from @a handle registration.
421 * For I/O handles, @a masks are removed from the Reactor. Unless
422 * @a masks includes ACE_Event_Handler::DONT_CALL,
423 * ACE_Event_Handler::handle_close() will be called with the @a masks
424 * that have been removed. If all masks have been removed,
425 * ACE_Event_Handler::remove_reference() will be called.
427 * For OS handles, the @a handle is removed from the Reactor. Unless
428 * @a masks includes ACE_Event_Handler::DONT_CALL,
429 * ACE_Event_Handler::handle_close() will be called with
430 * ACE_Event_Handler::NULL_MASK.
431 * ACE_Event_Handler::remove_reference() will also be called.
433 int remove_handler (ACE_HANDLE handle
,
434 ACE_Reactor_Mask masks
);
437 * Remove @a masks from @a event_handler registration.
439 * Same as remove_handler(ACE_HANDLE,ACE_Reactor_Mask), except
440 * @a handle comes from ACE_Event_Handler::get_handle().
442 int remove_handler (ACE_Event_Handler
*event_handler
,
443 ACE_Reactor_Mask masks
);
446 * Remove @a masks from multiple <handle> registrations.
448 * Shorthand for calling remove_handler(ACE_HANDLE,ACE_Reactor_Mask)
449 * multiple times for the same @a masks but different @a handles.
451 int remove_handler (const ACE_Handle_Set
&handles
,
452 ACE_Reactor_Mask masks
);
455 * Remove signal handler registration.
457 * Remove the ACE_Event_Handler currently associated with @a signum.
458 * Install the new disposition (if given) and return the previous
459 * disposition (if desired by the caller).
461 * Note that the registered handler's ACE_Event_Handler::handle_close ()
462 * callback will be called to indicate the signal handler has been removed.
463 * Unlike with I/O handles, there is no way to prevent this callback. The
464 * handle_close() callback can check the passed mask for the value
465 * ACE_Event_Handler::SIGNAL_MASK to tell when the callback is the result
466 * of a signal handler removal.
468 int remove_handler (int signum
,
469 ACE_Sig_Action
*new_disp
,
470 ACE_Sig_Action
*old_disp
= 0,
474 * Remove multiple signal handler registrations.
476 * Shorthand for calling
477 * remove_handler(int,ACE_Sig_Action*,ACE_Sig_Action*,int) multiple
478 * times for every signal in @a sigset.
480 int remove_handler (const ACE_Sig_Set
&sigset
);
482 // = Suspend and resume Handlers.
485 * Suspend @a handle temporarily.
487 int suspend_handler (ACE_HANDLE handle
);
490 * Suspend @a event_handler temporarily.
492 * Handle is obtained from ACE_Event_Handler::get_handle().
494 int suspend_handler (ACE_Event_Handler
*event_handler
);
497 * Suspend @a handles temporarily.
499 * Shorthand for calling suspend_handler(ACE_HANDLE) with multiple
502 int suspend_handler (const ACE_Handle_Set
&handles
);
505 * Suspend all registered handles temporarily.
507 int suspend_handlers (void);
512 int resume_handler (ACE_HANDLE handle
);
515 * Resume @a event_handler.
517 * Handle is obtained from ACE_Event_Handler::get_handle().
519 int resume_handler (ACE_Event_Handler
*event_handler
);
524 * Shorthand for calling resume_handler(ACE_HANDLE) with multiple
527 int resume_handler (const ACE_Handle_Set
&handles
);
530 * Resume all registered handles.
532 int resume_handlers (void);
534 /// Does the reactor allow the application to resume the handle on
535 /// its own ie. can it pass on the control of handle resumption to
536 /// the application. A positive value indicates that the handlers
537 /// are application resumable. A value of 0 indicates otherwise.
538 int resumable_handler (void);
540 // = Timer management.
543 * Schedule a timer event.
545 * Schedule a timer event that will expire after an @a delay amount
546 * of time. The return value of this method, a timer_id value,
547 * uniquely identifies the @a event_handler in the ACE_Reactor's
548 * internal list of timers. This timer_id value can be used to
549 * cancel the timer with the cancel_timer() call.
551 * Reactor will call ACE_Event_Handler::add_reference() on the
552 * handler. After the timeout occurs and
553 * ACE_Event_Handler::handle_timeout() has completed, the handler
554 * will be implicitly removed from the Reactor and
555 * ACE_Event_Handler::remove_reference() will be called.
557 * @see cancel_timer()
558 * @see reset_timer_interval()
560 * @param event_handler Event handler to schedule on reactor. The handler's
561 * handle_timeout() method will be called when this
562 * scheduled timer expires.
563 * @param arg Argument passed to the handle_timeout() method of
565 * @param delay Time interval after which the timer will expire.
566 * @param interval Time interval for which the timer will be
567 * automatically rescheduled if the handle_timeout()
568 * callback does not return a value less than 0.
570 * @retval timer id, on success. The id can be used to
571 * cancel or reschedule this timer.
572 * @retval -1 on failure, with errno set.
574 virtual long schedule_timer (ACE_Event_Handler
*event_handler
,
576 const ACE_Time_Value
&delay
,
577 const ACE_Time_Value
&interval
=
578 ACE_Time_Value::zero
);
579 #if defined (ACE_HAS_CPP11)
580 template<class Rep1
, class Period1
, class Rep2
= int, class Period2
= std::ratio
<1>>
581 long schedule_timer (ACE_Event_Handler
*event_handler
,
583 const std::chrono::duration
<Rep1
, Period1
>& delay
,
584 const std::chrono::duration
<Rep2
, Period2
>& interval
=
585 std::chrono::duration
<Rep2
, Period2
>::zero ())
587 ACE_Time_Value
const tv_delay (delay
);
588 ACE_Time_Value
const tv_interval (interval
);
589 return this->schedule_timer (event_handler
, arg
, tv_delay
, tv_interval
);
593 * Reset recurring timer interval.
595 * Resets the interval of the timer represented by @a timer_id to
596 * @a interval, which is specified in relative time to the current
597 * gettimeofday(). If @a interval is equal to
598 * ACE_Time_Value::zero, the timer will become a non-rescheduling
599 * timer. Returns 0 if successful, -1 if not.
601 * This change will not take effect until the next timeout.
603 virtual int reset_timer_interval (long timer_id
,
604 const ACE_Time_Value
&interval
);
605 #if defined (ACE_HAS_CPP11)
606 template<class Rep
, class Period
>
607 int reset_timer_interval (long timer_id
,
608 const std::chrono::duration
<Rep
, Period
>& interval
)
610 ACE_Time_Value
const tv_interval (interval
);
611 return this->reset_timer_interval (timer_id
, tv_interval
);
618 * Cancel timer associated with @a timer_id that was returned from
619 * the schedule_timer() method. If arg is non-NULL then it will be
620 * set to point to the ``magic cookie'' argument passed in when the
621 * handler was registered. This makes it possible to free up the
622 * memory and avoid memory leaks. Returns 1 if cancellation
623 * succeeded and 0 if the @a timer_id wasn't found.
625 * On successful cancellation, ACE_Event_Handler::handle_close()
626 * will be called with ACE_Event_Handler::TIMER_MASK.
627 * ACE_Event_Handler::remove_reference() will also be called.
629 virtual int cancel_timer (long timer_id
,
630 const void **arg
= 0,
631 int dont_call_handle_close
= 1);
634 * Cancel all timers associated with event handler.
636 * Shorthand for calling cancel_timer(long,const void **,int)
637 * multiple times for all timer associated with @a event_handler.
639 * ACE_Event_Handler::handle_close() will be called with
640 * ACE_Event_Handler::TIMER_MASK only once irrespective of the
641 * number of timers associated with the event handler.
642 * ACE_Event_Handler::remove_reference() will also be called once
643 * for every timer associated with the event handler.
645 * In case this operation is called with a nil event_handler
646 * it returns with 0 as the number of handlers cancelled.
648 * Returns number of handlers cancelled.
650 virtual int cancel_timer (ACE_Event_Handler
*event_handler
,
651 int dont_call_handle_close
= 1);
653 // = High-level Event_Handler scheduling operations
655 /// Add @a masks_to_be_added to the @a event_handler's entry.
656 /// @a event_handler must already have been registered.
657 /// Note that this call does not cause the Reactor to re-examine
658 /// its set of handlers - the new masks will be noticed the next
659 /// time the Reactor waits for activity. If there is no other
660 /// activity expected, or you need immediate re-examination of the
661 /// wait masks, either call ACE_Reactor::notify after this call, or
662 /// use ACE_Reactor::register_handler instead.
663 int schedule_wakeup (ACE_Event_Handler
*event_handler
,
664 ACE_Reactor_Mask masks_to_be_added
);
666 /// Add @a masks_to_be_added to the @a handle's entry. <event_handler>
667 /// associated with @a handle must already have been registered.
668 /// Note that this call does not cause the Reactor to re-examine
669 /// its set of handlers - the new masks will be noticed the next
670 /// time the Reactor waits for activity. If there is no other
671 /// activity expected, or you need immediate re-examination of
672 /// the wait masks, either call ACE_Reactor::notify after this call,
673 /// or use ACE_Reactor::register_handler instead.
674 int schedule_wakeup (ACE_HANDLE handle
,
675 ACE_Reactor_Mask masks_to_be_added
);
677 /// Clear @a masks_to_be_cleared from the @a event_handler's entry.
678 /// Note that this call does not cause the Reactor to re-examine
679 /// its set of handlers - the new masks will be noticed the next
680 /// time the Reactor waits for activity. If there is no other
681 /// activity expected, or you need immediate re-examination of
682 /// the wait masks, either call ACE_Reactor::notify after this
683 /// call, or use ACE_Reactor::register_handler instead.
684 int cancel_wakeup (ACE_Event_Handler
*event_handler
,
685 ACE_Reactor_Mask masks_to_be_cleared
);
687 /// Clear @a masks_to_be_cleared from the @a handle's entry.
688 /// Note that this call does not cause the Reactor to re-examine
689 /// its set of handlers - the new masks will be noticed the next
690 /// time the Reactor waits for activity. If there is no other
691 /// activity expected, or you need immediate re-examination of
692 /// the wait masks, either call ACE_Reactor::notify after this
693 /// call, or use ACE_Reactor::register_handler instead.
694 int cancel_wakeup (ACE_HANDLE handle
,
695 ACE_Reactor_Mask masks_to_be_cleared
);
697 // = Notification methods.
700 * Dispatch user specified events.
702 * Handler will be dispatched irrespective of whether it is
703 * registered, not registered, or suspended in the Reactor.
705 * If user specified event is successfully queued,
706 * ACE_Event_Handler::add_reference() will be called. After the
707 * notify occurs and the upcall to the handler completes, the
708 * handler will be implicitly removed from the Reactor and
709 * ACE_Event_Handler::remove_reference() will be called. No other
710 * upcall reference counting is done.
712 * For I/O or OS events, the upcall is invoked with an
713 * ACE_INVALID_HANDLE.
715 * For timer events, the upcall is invoked with a null ACT.
717 * @param event_handler: IN - Handler on which the event will be
719 * @param masks: IN - Events to be dispatched - multiple events can
721 * @param timeout: INOUT - Relative time up to which to wait for
722 * user specified event to be queued. If tv is 0, wait
723 * indefinitely. When the call returns, tv has the time remaining
724 * after the call completes.
726 int notify (ACE_Event_Handler
*event_handler
= 0,
727 ACE_Reactor_Mask masks
= ACE_Event_Handler::EXCEPT_MASK
,
728 ACE_Time_Value
*timeout
= 0);
731 * Set the maximum number of times that ACE_Reactor will
732 * iterate and dispatch the ACE_Event_Handlers that are passed in
733 * via the notify queue before breaking out of its
734 * ACE_Message_Queue::dequeue() loop. By default, this is set to
735 * -1, which means "iterate until the queue is empty." Setting this
736 * to a value like "1 or 2" will increase "fairness" (and thus
737 * prevent starvation) at the expense of slightly higher dispatching
740 void max_notify_iterations (int iterations
);
743 * Get the maximum number of times that the ACE_Reactor will
744 * iterate and dispatch the ACE_Event_Handler's that are passed in
745 * via the notify queue before breaking out of its
746 * ACE_Message_Queue::dequeue() loop.
748 int max_notify_iterations (void);
751 * Purge any notifications pending in this reactor for the specified
752 * ACE_Event_Handler object. If @a eh == 0, all notifications for
753 * all handlers are removed (but not any notifications posted just
754 * to wake up the reactor itself). Returns the number of
755 * notifications purged. Returns -1 on error.
757 * After the purging occurs, the handler will be implicitly removed
758 * from the Reactor and ACE_Event_Handler::remove_reference() will
761 int purge_pending_notifications (ACE_Event_Handler
*eh
,
763 ACE_Event_Handler::ALL_EVENTS_MASK
);
765 // = Assorted helper methods.
768 * Return the Event_Handler associated with @a handle. Return 0 if
769 * @a handle is not registered.
771 * Reactor will call ACE_Event_Handler::add_reference() on the
772 * handler before returning it.
774 ACE_Event_Handler
*find_handler (ACE_HANDLE handle
);
777 * Check to see if @a handle is associated with a valid Event_Handler
778 * bound to @a mask. Return the @c event_handler associated with this
779 * @a handler if @a event_handler != 0.
781 * Reactor will call ACE_Event_Handler::add_reference() on the
782 * handler before returning it if @a event_handler != 0.
784 int handler (ACE_HANDLE handle
,
785 ACE_Reactor_Mask mask
,
786 ACE_Event_Handler
**event_handler
= 0);
789 * Check to see if @a signum is associated with a valid Event_Handler
790 * bound to a signal. Return the @a event_handler associated with
791 * this @c handler if @a event_handler != 0.
793 int handler (int signum
,
794 ACE_Event_Handler
**event_handler
= 0);
796 /// Returns true if Reactor has been successfully initialized, else
798 int initialized (void);
800 /// Returns the current size of the Reactor's internal descriptor
802 size_t size (void) const;
804 /// Returns a reference to the Reactor's internal lock.
805 ACE_Lock
&lock (void);
807 /// Wake up all threads in waiting in the event loop
808 void wakeup_all_threads (void);
810 /// Transfers ownership of Reactor to the @a new_owner.
811 int owner (ACE_thread_t new_owner
,
812 ACE_thread_t
*old_owner
= 0);
814 /// Return the ID of the "owner" thread.
815 int owner (ACE_thread_t
*owner
);
817 /// Set position of the owner thread.
818 void requeue_position (int position
);
820 /// Get position of the owner thread.
821 int requeue_position (void);
823 /// Get the existing restart value.
826 /// Set a new value for restart and return the original value.
827 bool restart (bool r
);
829 // = Low-level wait_set mask manipulation methods.
831 /// GET/SET/ADD/CLR the dispatch mask "bit" bound with the
832 /// @a event_handler and @a mask.
833 int mask_ops (ACE_Event_Handler
*event_handler
,
834 ACE_Reactor_Mask mask
,
837 /// GET/SET/ADD/CLR the dispatch MASK "bit" bound with the @a handle
839 int mask_ops (ACE_HANDLE handle
,
840 ACE_Reactor_Mask mask
,
843 // = Low-level ready_set mask manipulation methods.
844 /// GET/SET/ADD/CLR the ready "bit" bound with the @a event_handler
846 int ready_ops (ACE_Event_Handler
*event_handler
,
847 ACE_Reactor_Mask mask
,
850 /// GET/SET/ADD/CLR the ready "bit" bound with the @a handle and @a mask.
851 int ready_ops (ACE_HANDLE handle
,
852 ACE_Reactor_Mask mask
,
855 /// Get the implementation class
856 ACE_Reactor_Impl
*implementation (void) const;
859 * Returns 0, if the size of the current message has been put in
860 * @a size returns -1, if not. ACE_HANDLE allows the reactor to
861 * check if the caller is valid. Used for CLASSIX Reactor
864 int current_info (ACE_HANDLE handle
, size_t &msg_size
);
866 /// Return true if we any event associations were made by the reactor
867 /// for the handles that it waits on, false otherwise.
868 bool uses_event_associations (void);
870 /// Declare the dynamic allocation hooks.
871 ACE_ALLOC_HOOK_DECLARE
;
873 /// Dump the state of the object.
874 void dump (void) const;
877 /// Set the implementation class.
878 void implementation (ACE_Reactor_Impl
*implementation
);
880 /// Delegation/implementation class that all methods will be
882 ACE_Reactor_Impl
*implementation_
;
884 /// Flag used to indicate whether we are responsible for cleaning up
885 /// the implementation instance
886 bool delete_implementation_
;
888 /// Pointer to a process-wide ACE_Reactor singleton.
889 static ACE_Reactor
*reactor_
;
891 /// Must delete the reactor_ singleton if true.
892 static bool delete_reactor_
;
894 /// Deny access since member-wise won't work...
895 ACE_Reactor (const ACE_Reactor
&);
896 ACE_Reactor
&operator = (const ACE_Reactor
&);
899 ACE_END_VERSIONED_NAMESPACE_DECL
902 #if defined (__ACE_INLINE__)
903 #include "ace/Reactor.inl"
904 #endif /* __ACE_INLINE__ */
906 #include /**/ "ace/post.h"
908 #endif /* ACE_REACTOR_H */