reschedule.cpp

来自「ace开发环境 用来开发网络程序 其运用了设计模式、多平台、C++等多种知识」· C++ 代码 · 共 84 行

CPP
84
字号
/** * $Id: Reschedule.cpp 55038 2004-01-01 23:03:38Z shuston $ * * Changing the interval */#include "ace/OS_NS_time.h"#include "ace/Log_Msg.h"#include "ace/Reactor.h"#include "ace/Event_Handler.h"class MyTimerHandler : public ACE_Event_Handler{public:  int handle_timeout (const ACE_Time_Value &current_time,                      const void * = 0 )  {    time_t epoch = ((timespec_t)current_time).tv_sec;    ACE_DEBUG ((LM_INFO,                ACE_TEXT ("handle_timeout: %s"),                ACE_OS::ctime(&epoch)));    return 0;  }};// Listing 1 code/ch07class SigintHandler : public ACE_Event_Handler{public:  SigintHandler (long timerId, int currentInterval)    : ACE_Event_Handler(),      timerId_(timerId),      currentInterval_(currentInterval)  {  }  int handle_signal (int,                     siginfo_t * = 0,                     ucontext_t * = 0)  {    ACE_DEBUG ((LM_INFO,                ACE_TEXT ("Resetting interval of timer ")                ACE_TEXT ("%d to %d\n"),                this->timerId_,                ++this->currentInterval_));    ACE_Time_Value newInterval (this->currentInterval_);    ACE_Reactor::instance()->      reset_timer_interval (this->timerId_, newInterval);    return 0;  }private:  long timerId_;  int currentInterval_;};// Listing 1int ACE_TMAIN (int, ACE_TCHAR *[]){  ACE_Time_Value initialDelay (3);  ACE_Time_Value interval (5);  // Listing 2 code/ch07  MyTimerHandler *handler = new MyTimerHandler ();  long timerId =    ACE_Reactor::instance ()->schedule_timer (handler,                                              0,                                              initialDelay,                                              interval);  // Listing 2  // Listing 3 code/ch07  SigintHandler *handleSigint =    new SigintHandler (timerId, 5);  ACE_Reactor::instance ()->register_handler (SIGINT,                                              handleSigint);  // Listing 3  ACE_Reactor::instance ()->run_reactor_event_loop ();  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?