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 ()
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 ()
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 ()
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 ();
70 ACE_Asynch_Pseudo_Task::register_io_handler (ACE_HANDLE handle
,
71 ACE_Event_Handler
*handler
,
72 ACE_Reactor_Mask mask
,
75 // Register the handler with the reactor.
76 if (-1 == this->reactor_
.register_handler (handle
, handler
, mask
))
82 // Suspend the handle now. Enable only when the accept is issued
83 // by the application.
84 if (this->reactor_
.suspend_handler (handle
) == -1)
88 ACE_TEXT ("%N:%l:%p\n"),
89 ACE_TEXT ("register_io_handler (suspended)")));
90 this->reactor_
.remove_handler (handle
, ACE_Event_Handler::ALL_EVENTS_MASK
91 | ACE_Event_Handler::DONT_CALL
);
99 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_HANDLE handle
)
101 return this->reactor_
.remove_handler (handle
,
102 ACE_Event_Handler::ALL_EVENTS_MASK
103 | ACE_Event_Handler::DONT_CALL
);
107 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_Handle_Set
&set
)
109 return this->reactor_
.remove_handler (set
, ACE_Event_Handler::ALL_EVENTS_MASK
110 | ACE_Event_Handler::DONT_CALL
);
114 ACE_Asynch_Pseudo_Task::suspend_io_handler (ACE_HANDLE handle
)
116 return this->reactor_
.suspend_handler (handle
);
120 ACE_Asynch_Pseudo_Task::resume_io_handler (ACE_HANDLE handle
)
122 return this->reactor_
.resume_handler (handle
);
125 ACE_END_VERSIONED_NAMESPACE_DECL