2 * Scheduling timers with the Reactor
5 #include "ace/OS_NS_time.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Reactor.h"
8 #include "ace/Event_Handler.h"
10 // Listing 1 code/ch07
11 class MyTimerHandler
: public ACE_Event_Handler
14 int handle_timeout (const ACE_Time_Value
¤t_time
,
17 time_t epoch
= ((timespec_t
)current_time
).tv_sec
;
20 ACE_TEXT ("handle_timeout: %s\n"),
21 ACE_OS::ctime (&epoch
)));
28 // Create a SIGINT handler so that we can exit
29 // the program politely
30 class SigintHandler
: public ACE_Event_Handler
33 int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0)
37 ACE_Reactor::instance ()->end_reactor_event_loop ();
43 int ACE_TMAIN (int, ACE_TCHAR
*[])
45 // Listing 2 code/ch07
46 MyTimerHandler
* timer
= new MyTimerHandler ();
47 ACE_Time_Value
initialDelay (3);
48 ACE_Time_Value
interval (5);
49 ACE_Reactor::instance()->schedule_timer (timer
,
56 SigintHandler
* handleExit
= new SigintHandler ();
57 ACE_Reactor::instance()->register_handler (SIGINT
,
60 ACE_Reactor::instance ()->run_reactor_event_loop ();