// $Id$ #define ACE_BUILD_DLL #include "ace/Proactor.h" ACE_RCSID(ace, Proactor, "$Id$") #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) \ || (defined (ACE_HAS_AIO_CALLS)) // This only works on Win32 platforms and on Unix platforms with aio // calls. #include "ace/Task_T.h" #include "ace/Log_Msg.h" #include "ace/Object_Manager.h" #if !defined (__ACE_INLINE__) #include "ace/Proactor.i" #endif /* __ACE_INLINE__ */ // Process-wide ACE_Proactor. ACE_Proactor *ACE_Proactor::proactor_ = 0; // Controls whether the Proactor is deleted when we shut down (we can // only delete it safely if we created it!) int ACE_Proactor::delete_proactor_ = 0; // Terminate the eventloop. sig_atomic_t ACE_Proactor::end_event_loop_ = 0; class ACE_Export ACE_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_Proactor; // Proactor has special privileges // Access needed to: timer_event_ public: ACE_Proactor_Timer_Handler (ACE_Proactor &proactor); // Constructor ~ACE_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_Proactor &proactor_; // Proactor. int shutting_down_; // Flag used to indicate when we are shutting down. }; ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler (ACE_Proactor &proactor) : ACE_Task (&proactor.thr_mgr_), proactor_ (proactor), shutting_down_ (0) { } ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler (void) { // Mark for closing down this->shutting_down_ = 1; // Signal timer event this->timer_event_.signal (); } int ACE_Proactor_Timer_Handler::svc (void) { #if defined (ACE_HAS_AIO_CALLS) // @@ To be implemented. return 0; #else /* ACE_HAS_AIO_CALLS */ 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->proactor_.timer_queue ()->is_empty ()) { // Get the earliest absolute time. absolute_time = this->proactor_.timer_queue ()->earliest_time () - this->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