Asynch_Pseudo_Task.cpp

Go to the documentation of this file.
00001 // Asynch_Pseudo_Task.cpp,v 1.9 2005/10/28 16:14:51 ossama Exp
00002 
00003 #include "ace/Asynch_Pseudo_Task.h"
00004 
00005 #include "ace/OS_NS_errno.h"
00006 #include "ace/OS_NS_signal.h"
00007 
00008 ACE_RCSID(ace, Asynch_Pseudo_Task, "Asynch_Pseudo_Task.cpp,v 1.9 2005/10/28 16:14:51 ossama Exp")
00009 
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 ACE_Asynch_Pseudo_Task::ACE_Asynch_Pseudo_Task()
00013   : select_reactor_ (),               // should be initialized before reactor_
00014     reactor_ (&select_reactor_, 0)    // don't delete implementation
00015 {
00016 }
00017 
00018 ACE_Asynch_Pseudo_Task::~ACE_Asynch_Pseudo_Task()
00019 {
00020   this->stop();
00021 }
00022 
00023 int
00024 ACE_Asynch_Pseudo_Task::start (void)
00025 {
00026   if (this->reactor_.initialized () == 0)
00027     ACE_ERROR_RETURN ((LM_ERROR,
00028                        ACE_LIB_TEXT ("%N:%l:%p\n"),
00029                        ACE_LIB_TEXT ("start reactor is not initialized")),
00030                        -1);
00031 
00032   return this->activate () == -1 ? -1 : 0;   // If started, return 0
00033 }
00034 
00035 int
00036 ACE_Asynch_Pseudo_Task::stop (void)
00037 {
00038   if (this->thr_count () == 0)  // already stopped
00039     return 0;
00040 
00041   if (this->reactor_.end_reactor_event_loop () == -1)
00042     return -1;
00043 
00044   this->wait ();
00045   this->reactor_.close ();
00046   return 0;
00047 }
00048 
00049 int
00050 ACE_Asynch_Pseudo_Task::svc (void)
00051 {
00052 #if !defined (ACE_WIN32)
00053 
00054   sigset_t RT_signals;
00055 
00056   sigemptyset (&RT_signals);
00057   for (int si = ACE_SIGRTMIN; si <= ACE_SIGRTMAX; si++)
00058     sigaddset (&RT_signals, si);
00059 
00060   if (ACE_OS::pthread_sigmask (SIG_BLOCK, &RT_signals, 0) != 0)
00061     ACE_ERROR ((LM_ERROR,
00062                 ACE_LIB_TEXT ("Error:(%P | %t):%p\n"),
00063                 ACE_LIB_TEXT ("pthread_sigmask")));
00064 #endif
00065 
00066   reactor_.owner (ACE_Thread::self());
00067   reactor_.run_reactor_event_loop ();
00068 
00069   return 0;
00070 }
00071 
00072 
00073 
00074 int
00075 ACE_Asynch_Pseudo_Task::register_io_handler (ACE_HANDLE handle,
00076                                              ACE_Event_Handler *handler,
00077                                              ACE_Reactor_Mask mask,
00078                                              int flg_suspend)
00079 {
00080   // Register the handler with the reactor.
00081   if (-1 == this->reactor_.register_handler (handle, handler, mask))
00082     return -1;
00083 
00084   if (flg_suspend == 0)
00085     return 0;
00086 
00087   // Suspend the handle now. Enable only when the accept is issued
00088   // by the application.
00089   if (this->reactor_.suspend_handler (handle) == -1)
00090     {
00091       ACE_ERROR
00092         ((LM_ERROR,
00093           ACE_LIB_TEXT ("%N:%l:%p\n"),
00094           ACE_LIB_TEXT ("register_io_handler (suspended)")));
00095       this->reactor_.remove_handler (handle,
00096                                      ACE_Event_Handler::ALL_EVENTS_MASK
00097                                      | ACE_Event_Handler::DONT_CALL);
00098       return -1;
00099     }
00100 
00101   return 0;
00102 }
00103 
00104 int
00105 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_HANDLE handle)
00106 {
00107   return this->reactor_.remove_handler (handle ,
00108                                         ACE_Event_Handler::ALL_EVENTS_MASK
00109                                         | ACE_Event_Handler::DONT_CALL);
00110 }
00111 
00112 int
00113 ACE_Asynch_Pseudo_Task::remove_io_handler (ACE_Handle_Set &set)
00114 {
00115   return this->reactor_.remove_handler (set,
00116                                         ACE_Event_Handler::ALL_EVENTS_MASK
00117                                         | ACE_Event_Handler::DONT_CALL);
00118 }
00119 
00120 int
00121 ACE_Asynch_Pseudo_Task::suspend_io_handler (ACE_HANDLE handle)
00122 {
00123   return this->reactor_.suspend_handler (handle);
00124 }
00125 
00126 int
00127 ACE_Asynch_Pseudo_Task::resume_io_handler (ACE_HANDLE handle)
00128 {
00129   return this->reactor_.resume_handler (handle);
00130 }
00131 
00132 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:46 2006 for ACE by doxygen 1.3.6