#include <ace/Reactor.h> class ACE_Reactor {
public:
enum { DEFAULT_SIZE = ACE_DEFAULT_REACTOR_SIZE, GET_MASK = 1, SET_MASK = 2, ADD_MASK = 3, CLR_MASK = 4 };ACE_Reactor (ACE_Sig_Handler * = 0);
ACE_Reactor (size_t size, int restart = 0, ACE_Sig_Handler * = 0);
virtual int open ( size_t size = DEFAULT_SIZE, int restart = 0, ACE_Sig_Handler * = 0 );
virtual void close (void);
virtual ~ACE_Reactor (void);
virtual int schedule_timer ( ACE_Event_Handler *, const void *arg, const ACE_Time_Value &delta, const ACE_Time_Value &interval = ACE_Time_Value::zero );
virtual int cancel_timer (ACE_Event_Handler *event_handler);
virtual int cancel_timer (int timer_id, const void **arg = 0);
virtual int handle_events (ACE_Time_Value *how_long = 0);
virtual int handle_events (ACE_Time_Value &how_long);
virtual int register_handler ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int register_handler ( ACE_HANDLE handle, ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int register_handler ( const ACE_Handle_Set &handles, ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int register_handler ( int signum, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp = 0, ACE_Event_Handler **old_sh = 0, ACE_Sig_Action *old_disp = 0 );
virtual int register_handler ( const ACE_Sig_Set &sigset, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp = 0 );
virtual int remove_handler ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int remove_handler (ACE_HANDLE handle, ACE_Reactor_Mask);
virtual int remove_handler ( const ACE_Handle_Set &handle_set, ACE_Reactor_Mask );
virtual int remove_handler ( int signum, ACE_Sig_Action *new_disp, ACE_Sig_Action *old_disp = 0, int sigkey = -1 );
virtual int remove_handler (const ACE_Sig_Set &sigset);
virtual int suspend_handler (ACE_Event_Handler *eh);
virtual int suspend_handler (ACE_HANDLE handle);
virtual int resume_handler (ACE_Event_Handler *eh);
virtual int resume_handler (ACE_HANDLE handle);
virtual int suspend_handlers (void);
virtual int resume_handlers (void);
virtual int handler ( ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Event_Handler **eh = 0 );
virtual int handler (int signum, ACE_Event_Handler ** = 0);
virtual int schedule_wakeup ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int schedule_wakeup ( ACE_HANDLE handle, ACE_Reactor_Mask mask );
virtual int cancel_wakeup ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int cancel_wakeup ( ACE_HANDLE handle, ACE_Reactor_Mask mask );
virtual int mask_ops ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask, int ops );
virtual int mask_ops ( ACE_HANDLE handle, ACE_Reactor_Mask mask, int ops );
virtual int ready_ops ( ACE_Event_Handler *eh, ACE_Reactor_Mask mask, int ops );
virtual int ready_ops ( ACE_HANDLE handle, ACE_Reactor_Mask, int ops );
virtual int notify ( ACE_Event_Handler * = 0, ACE_Reactor_Mask = ACE_Event_Handler::EXCEPT_MASK );
void requeue_position (int);
int requeue_position (void);
void owner (ACE_thread_t n_id, ACE_thread_t *o_id = 0);
int owner (ACE_thread_t *);
void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
protected:
virtual int attach ( ACE_HANDLE handle, ACE_Event_Handler *eh, ACE_Reactor_Mask mask );
virtual int detach (ACE_HANDLE handle, ACE_Reactor_Mask);
virtual int suspend (ACE_HANDLE handle);
virtual int resume (ACE_HANDLE handle);
virtual int remove_handlers ( const ACE_Handle_Set &handles, ACE_Reactor_Mask );
virtual int register_handlers ( const ACE_Handle_Set &handles, ACE_Event_Handler *handler, ACE_Reactor_Mask mask );
virtual int handler_i ( ACE_HANDLE handle, ACE_Reactor_Mask, ACE_Event_Handler ** = 0 );
virtual int handler_i (int signum, ACE_Event_Handler ** = 0);
virtual int any_ready (void) const;
virtual int handle_error (void);
virtual int check_handles (void);
virtual int bit_ops ( ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Handle_Set &rd, ACE_Handle_Set &wr, ACE_Handle_Set &ex, int ops );
virtual int fill_in_ready ( ACE_Handle_Set &, ACE_Handle_Set &, ACE_Handle_Set & );
virtual int wait_for_multiple_events ( ACE_Handle_Set &, ACE_Handle_Set &, ACE_Handle_Set &, ACE_Time_Value * );
virtual void dispatch ( int, ACE_Handle_Set &, ACE_Handle_Set &, ACE_Handle_Set & );
virtual void notify_handle ( ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Handle_Set &, ACE_Event_Handler *eh, ACE_EH_PTMF callback );
ACE_Timer_Queue *timer_queue_;
ACE_Handler_Repository handler_rep_;
ACE_Sig_Handler *signal_handler_;
int delete_signal_handler_;
ACE_Handle_Set rd_handle_mask_;
ACE_Handle_Set wr_handle_mask_;
ACE_Handle_Set ex_handle_mask_;
ACE_Handle_Set rd_handle_mask_ready_;
ACE_Handle_Set wr_handle_mask_ready_;
ACE_Handle_Set ex_handle_mask_ready_;
int restart_;
int requeue_position_;
int initialized_;
ACE_thread_t owner_;
ACE_Notification_Handler notification_handler_;
ACE_Reactor_Token token_;
void renew (void);
friend class ACE_Notification_Handler;
friend class ACE_Handler_Repository;
pollfd *handle_sets_to_poll_fds (ACE_HANDLE &width);
void poll_fds_to_handle_sets ( ACE_HANDLE width, ACE_Handle_Set &, ACE_Handle_Set &, ACE_Handle_Set &, int nfound );
pollfd *poll_h_;
private:
ACE_Time_Value timer_skew_;
ACE_Reactor (const ACE_Reactor &);
ACE_Reactor &operator = (const ACE_Reactor &);
};
ACE_Reactor (ACE_Sig_Handler * = 0);
ACE_Reactor (size_t size, int restart = 0, ACE_Sig_Handler * = 0);
size
.
virtual int open (
size_t size = DEFAULT_SIZE,
int restart = 0,
ACE_Sig_Handler * = 0
);
size
.
virtual void close (void);
virtual ~ACE_Reactor (void);
virtual int schedule_timer (
ACE_Event_Handler *,
const void *arg,
const ACE_Time_Value &delta,
const ACE_Time_Value &interval = ACE_Time_Value::zero
);
event_handler
that will expire after delay
amount
of time. If it expires then arg
is passed in as the value to
the event_handler
's handle_timeout
callback method. If
interval
is != to ACE_Time_Value::zero
then it is used to
reschedule the event_handler
automatically. This method
returns a timer handle that uniquely identifies the
event_handler
in an internal list. This timer handle can be
used to cancel an event_handler
before it expires. The
cancellation ensures that timer_ids are unique up to values of
greater than 2 billion timers. As long as timers don't stay
around longer than this there should be no problems with
accidentally deleting the wrong timer.
virtual int cancel_timer (ACE_Event_Handler *event_handler);
event_handlers
that match the address of
event_handler
.
virtual int cancel_timer (int timer_id, const void **arg = 0);
ACE_Event_Handler
that matches the timer_id
value (which was returned from the schedule
method). If arg is
non-NULL then it will be set to point to the ``magic cookie''
argument passed in when the Event_Handler
was registered. This
makes it possible to free up the memory and avoid memory leaks.
virtual int handle_events (ACE_Time_Value *how_long = 0);
how_long
before
returning (will return earlier if I/O or signal events occur).
Note that how_long
can be 0, in which case this method blocks
until I/O events or signals occur.
virtual int handle_events (ACE_Time_Value &how_long);
how_long
before
returning (will return earlier if I/O or signal events occur).
virtual int register_handler (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
eh
with a particular mask
. Note
that the Reactor will call eh-get_handle() to extract the
underlying I/O handle).
virtual int register_handler (
ACE_HANDLE handle,
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
eh
with a particular mask
. Note
that since the handle
is given the Reactor will *not* call
eh-get_handle() to extract the underlying I/O handle).
virtual int register_handler (
const ACE_Handle_Set &handles,
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
eh
with all the handles
in the Handle_Set
.
virtual int register_handler (
int signum,
ACE_Event_Handler *new_sh,
ACE_Sig_Action *new_disp = 0,
ACE_Event_Handler **old_sh = 0,
ACE_Sig_Action *old_disp = 0
);
new_sh
to handle the signal signum
using the
new_disp
. Returns the old_sh
that was previously registered
(if any), along with the old_disp
of the signal handler.
virtual int register_handler (
const ACE_Sig_Set &sigset,
ACE_Event_Handler *new_sh,
ACE_Sig_Action *new_disp = 0
);
new_sh
to handle a set of signals sigset
using the
new_disp
.
virtual int remove_handler (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
mask
binding of eh
from the Reactor. If there
are no more bindings for this eh
then it is removed from the
Reactor. Note that the Reactor will call eh-get_handle() to
extract the underlying I/O handle.
virtual int remove_handler (ACE_HANDLE handle, ACE_Reactor_Mask);
mask
bind of Event_Handler
whose handle is
handle
from the Reactor. If there are no more bindings for
this eh
then it is removed from the Reactor.
virtual int remove_handler (
const ACE_Handle_Set &handle_set,
ACE_Reactor_Mask
);
mask
bindings for handles in the handle_set
bind of Event_Handler
. If there are no more bindings for any
of these handlers then they are removed from the Reactor.
virtual int remove_handler (
int signum,
ACE_Sig_Action *new_disp,
ACE_Sig_Action *old_disp = 0,
int sigkey = -1
);
signum
.
sigkey
is ignored in this implementation since there is only
one instance of a signal handler. Install the new disposition
(if given) and return the previous disposition (if desired by the
caller). Returns 0 on success and -1 if signum
is invalid.
virtual int remove_handler (const ACE_Sig_Set &sigset);
remove_handler
for every signal in sigset
.
virtual int suspend_handler (ACE_Event_Handler *eh);
Event_Handler
associated with eh
.
virtual int suspend_handler (ACE_HANDLE handle);
Event_Handler
associated with handle
.
virtual int resume_handler (ACE_Event_Handler *eh);
Event_Handler
associated with
eh
.
virtual int resume_handler (ACE_HANDLE handle);
Event_Handler
associated with
handle
.
virtual int suspend_handlers (void);
Event_Handlers
in the Reactor.
virtual int resume_handlers (void);
Event_Handlers
in the Reactor.
virtual int handler (
ACE_HANDLE handle,
ACE_Reactor_Mask mask,
ACE_Event_Handler **eh = 0
);
handle
is associated with a valid Event_Handler
bound to mask
. Return the eh
associated with this handler
if eh
!= 0.
virtual int handler (int signum, ACE_Event_Handler ** = 0);
signum
is associated with a valid Event_Handler
bound to a signal. Return the eh
associated with this
handler
if eh
!= 0.
virtual int schedule_wakeup (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
eh
and the mask
.
virtual int schedule_wakeup (
ACE_HANDLE handle,
ACE_Reactor_Mask mask
);
handle
and the mask
.
virtual int cancel_wakeup (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
eh
and the mask
.
virtual int cancel_wakeup (ACE_HANDLE handle, ACE_Reactor_Mask mask);
handle
and the mask
.
virtual int mask_ops (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask,
int ops
);
eh
and
mask
.
virtual int mask_ops (
ACE_HANDLE handle,
ACE_Reactor_Mask mask,
int ops
);
handle
and mask
.
virtual int ready_ops (
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask,
int ops
);
eh
and mask
.
virtual int ready_ops (ACE_HANDLE handle, ACE_Reactor_Mask, int ops);
handle
and mask
.
virtual int notify (
ACE_Event_Handler * = 0,
ACE_Reactor_Mask = ACE_Event_Handler::EXCEPT_MASK
);
void requeue_position (int);
int requeue_position (void);
void owner (ACE_thread_t n_id, ACE_thread_t *o_id = 0);
int owner (ACE_thread_t *);
void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
virtual int attach (
ACE_HANDLE handle,
ACE_Event_Handler *eh,
ACE_Reactor_Mask mask
);
handle
and eh
with the
mask
.
virtual int detach (ACE_HANDLE handle, ACE_Reactor_Mask);
handle
and eh
with the
mask
.
virtual int suspend (ACE_HANDLE handle);
Event_Handler
associated with handle
virtual int resume (ACE_HANDLE handle);
Event_Handler
associated with handle
virtual int remove_handlers (
const ACE_Handle_Set &handles,
ACE_Reactor_Mask
);
handles
.
virtual int register_handlers (
const ACE_Handle_Set &handles,
ACE_Event_Handler *handler,
ACE_Reactor_Mask mask
);
handles
.
virtual int handler_i (
ACE_HANDLE handle,
ACE_Reactor_Mask,
ACE_Event_Handler ** = 0
);
handler
method.
virtual int handler_i (int signum, ACE_Event_Handler ** = 0);
handler
method.
virtual int any_ready (void) const;
virtual int handle_error (void);
virtual int check_handles (void);
virtual int bit_ops (
ACE_HANDLE handle,
ACE_Reactor_Mask mask,
ACE_Handle_Set &rd,
ACE_Handle_Set &wr,
ACE_Handle_Set &ex,
int ops
);
virtual int fill_in_ready (
ACE_Handle_Set &,
ACE_Handle_Set &,
ACE_Handle_Set &
);
virtual int wait_for_multiple_events (
ACE_Handle_Set &,
ACE_Handle_Set &,
ACE_Handle_Set &,
ACE_Time_Value *
);
virtual void dispatch (
int,
ACE_Handle_Set &,
ACE_Handle_Set &,
ACE_Handle_Set &
);
virtual void notify_handle (
ACE_HANDLE handle,
ACE_Reactor_Mask mask,
ACE_Handle_Set &,
ACE_Event_Handler *eh,
ACE_EH_PTMF callback
);
callback
in the context of the eh
associated with handle
that a particular event has occurred.
ACE_Timer_Queue *timer_queue_;
ACE_Handler_Repository handler_rep_;
ACE_Event_Handler *
s used to keep track
of the user-defined callbacks.
ACE_Sig_Handler *signal_handler_;
int delete_signal_handler_;
Handle_Sets
are waited for by poll() or
select().
ACE_Handle_Set rd_handle_mask_;
ACE_Handle_Set wr_handle_mask_;
ACE_Handle_Set ex_handle_mask_;
ACE_Handle_Set rd_handle_mask_ready_;
ACE_Handle_Set wr_handle_mask_ready_;
ACE_Handle_Set ex_handle_mask_ready_;
int restart_;
int requeue_position_;
int initialized_;
ACE_thread_t owner_;
ACE_Notification_Handler notification_handler_;
ACE_Reactor_Token token_;
void renew (void);
requeue_position_
.
friend class ACE_Notification_Handler;
friend class ACE_Handler_Repository;
pollfd *handle_sets_to_poll_fds (ACE_HANDLE &width);
void poll_fds_to_handle_sets (
ACE_HANDLE width,
ACE_Handle_Set &,
ACE_Handle_Set &,
ACE_Handle_Set &,
int nfound
);
pollfd *poll_h_;