Fixed typos
[ACE_TAO.git] / ACE / ace / Asynch_Pseudo_Task.cpp
blob0b6a14b60e549fdd382144417e5450fa0d652145
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 ()
16 this->stop ();
19 int
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")),
26 -1);
28 return this->activate () == -1 ? -1 : 0; // If started, return 0
31 int
32 ACE_Asynch_Pseudo_Task::stop (void)
34 if (this->thr_count () == 0) // already stopped
35 return 0;
37 if (this->reactor_.end_reactor_event_loop () == -1)
38 return -1;
40 this->wait ();
41 this->reactor_.close ();
42 return 0;
45 int
46 ACE_Asynch_Pseudo_Task::svc (void)
48 #if !defined (ACE_WIN32)
50 sigset_t RT_signals;
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")));
60 #endif
62 reactor_.owner (ACE_Thread::self ());
63 reactor_.run_reactor_event_loop ();
65 return 0;
70 int
71 ACE_Asynch_Pseudo_Task::register_io_handler (ACE_HANDLE handle,
72 ACE_Event_Handler *handler,
73 ACE_Reactor_Mask mask,
74 int flg_suspend)
76 // Register the handler with the reactor.
77 if (-1 == this->reactor_.register_handler (handle, handler, mask))
78 return -1;
80 if (flg_suspend == 0)
81 return 0;
83 // Suspend the handle now. Enable only when the accept is issued
84 // by the application.
85 if (this->reactor_.suspend_handler (handle) == -1)
87 ACELIB_ERROR
88 ((LM_ERROR,
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);
93 return -1;
96 return 0;
99 int
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