// $Id$ #define ACE_BUILD_DLL // ACE_RCSID(ace, Proactor, "$Id$") #include "ace/WIN32_Proactor.h" #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) // WIN implemenatation of the Proactor. #include "ace/Task_T.h" #include "ace/Log_Msg.h" #include "ace/Object_Manager.h" #if !defined (__ACE_INLINE__) #include "ace/WIN32_Proactor.i" #endif /* __ACE_INLINE__ */ class ACE_Export ACE_WIN32_Proactor_Timer_Handler : public ACE_Task { // = TITLE // A Handler for timer. It helps in the management of timers // registered with the Proactor. // // = DESCRIPTION // This object has a thread that will wait on the earliest time // in a list of timers and an event. When a timer expires, the // thread will post a completion event on the port and go back // to waiting on the timer queue and event. If the event is // signaled, the thread will refresh the time it is currently // waiting on (in case the earliest time has changed) friend class ACE_WIN32_Proactor; // Proactor has special privileges // Access needed to: timer_event_ public: ACE_WIN32_Proactor_Timer_Handler (ACE_WIN32_Proactor &win32_proactor); // Constructor. ~ACE_WIN32_Proactor_Timer_Handler (void); // Destructor. protected: virtual int svc (void); // Run by a daemon thread to handle deferred processing. In other // words, this method will do the waiting on the earliest timer and // event. ACE_Auto_Event timer_event_; // Event to wait on. ACE_WIN32_Proactor &win32_proactor_; // Proactor. int shutting_down_; // Flag used to indicate when we are shutting down. }; ACE_WIN32_Proactor_Timer_Handler::ACE_WIN32_Proactor_Timer_Handler (ACE_WIN32_Proactor &win32_proactor) : ACE_Task (&win32_proactor.thr_mgr_), win32_proactor_ (win32_proactor), shutting_down_ (0) { } ACE_WIN32_Proactor_Timer_Handler::~ACE_WIN32_Proactor_Timer_Handler (void) { // Mark for closing down. this->shutting_down_ = 1; // Signal timer event. this->timer_event_.signal (); } int ACE_WIN32_Proactor_Timer_Handler::svc (void) { u_long time; ACE_Time_Value absolute_time; while (this->shutting_down_ == 0) { // default value time = ACE_INFINITE; // If the timer queue is not empty if (!this->win32_proactor_.timer_queue ()->is_empty ()) { // Get the earliest absolute time. absolute_time = this->win32_proactor_.timer_queue ()->earliest_time () - this->win32_proactor_.timer_queue ()->gettimeofday (); // Time to wait. time = absolute_time.msec (); // Make sure the time is positive. if (time < 0) time = 0; } // Wait for event upto