1 #include "ace/Asynch_Pseudo_Task.h"
3 #include "ace/OS_NS_errno.h"
4 #include "ace/OS_NS_signal.h"
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_Asynch_Pseudo_Task::ACE_Asynch_Pseudo_Task ()
9 : select_reactor_ (), // should be initialized before reactor_
10 reactor_ (&select_reactor_
, 0) // don't delete implementation
14 ACE_Asynch_Pseudo_Task::~ACE_Asynch_Pseudo_Task ()
20 ACE_Asynch_Pseudo_Task::start (void)
22 if (this->reactor_
.initialized () == 0)
23 ACELIB_ERROR_RETURN ((LM_ERROR
,
24 ACE_TEXT ("%N:%l:%p\n"),
25 ACE_TEXT ("start reactor is not initialized")),
28 return this->activate () == -1 ? -1 : 0; // If started, return 0
32 ACE_Asynch_Pseudo_Task::stop (void)
34 if (this->thr_count () == 0) // already stopped
37 if (this->reactor_
.end_reactor_event_loop () == -1)
41 this->reactor_
.close ();
46 ACE_Asynch_Pseudo_Task::svc (void)
48 #if !defined (ACE_WIN32)
52 sigemptyset (&RT_signals
);
53 for (int si
= ACE_SIGRTMIN
; si
<= ACE_SIGRTMAX
; si
++)
54 sigaddset (&RT_signals
, si
);
56 if (ACE_OS::pthread_sigmask (SIG_BLOCK
, &RT_signals
, 0) != 0)
57 ACELIB_ERROR ((LM_ERROR
,
58 ACE_TEXT ("Error:(%P | %t):%p\n"),
59 ACE_TEXT ("pthread_sigmask")));
62 reactor_
.owner (ACE_Thread::self ());
63 reactor_
.run_reactor_event_loop ();
71 ACE_Asynch_Pseudo_Task::register_io_handler (ACE_HANDLE handle
,
72 ACE_Event_Handler
*handler
,
73 ACE_Reactor_Mask mask
,
76 // Register the handler with the reactor.
77 if (-1 == this->reactor_
.register_handler (handle
, handler
, mask
))
83 // Suspend the handle now. Enable only when the accept is issued
84 // by the application.
85 if (this->reactor_
.suspend_handler (handle
) == -1)
89 ACE_TEXT ("%N:%l:%p\n"),
90 ACE_TEXT ("register_io_handler (suspended)")));
91 this->reactor_
.remove_handler (handle
, ACE_Event_Handler::ALL_EVENTS_MASK
92 | ACE_Event_Handler::DONT_CALL
);
100 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_HANDLE handle
)
102 return this->reactor_
.remove_handler (handle
,
103 ACE_Event_Handler::ALL_EVENTS_MASK
104 | ACE_Event_Handler::DONT_CALL
);
108 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_Handle_Set
&set
)
110 return this->reactor_
.remove_handler (set
, ACE_Event_Handler::ALL_EVENTS_MASK
111 | ACE_Event_Handler::DONT_CALL
);
115 ACE_Asynch_Pseudo_Task::suspend_io_handler (ACE_HANDLE handle
)
117 return this->reactor_
.suspend_handler (handle
);
121 ACE_Asynch_Pseudo_Task::resume_io_handler (ACE_HANDLE handle
)
123 return this->reactor_
.resume_handler (handle
);
126 ACE_END_VERSIONED_NAMESPACE_DECL