2 //=============================================================================
6 * Tests the WFMO_Reactor's ability to handle regular APC
9 * @author Irfan Pyarali <irfan@cs.wustl.edu>
11 //=============================================================================
13 #include "ace/OS_main.h"
15 #if defined (ACE_WIN32) && _WIN32_WINNT >= 0x400
17 #include "ace/Reactor.h"
18 #include "ace/Auto_Event.h"
19 #include "ace/Log_Msg.h"
21 class Event_Handler
: public ACE_Event_Handler
24 int handle_signal (int signum
, siginfo_t
* = 0, ucontext_t
* = 0);
26 int handle_timeout (const ACE_Time_Value
&tv
, const void *arg
= 0);
28 ACE_Auto_Event handle_
;
32 static Event_Handler
*global_event_handler
;
38 "(%t) apc occurred @ %T\n"));
40 global_event_handler
->handle_
.signal ();
46 DWORD result
= ::QueueUserAPC (reinterpret_cast<PAPCFUNC
> (&apc_callback
),
47 // pointer to APC function
48 ::GetCurrentThread (), // handle to the thread
49 0); // argument for the APC function
55 Event_Handler::handle_signal (int, siginfo_t
*, ucontext_t
*)
59 if (this->iterations_
== 0)
61 ACE_Reactor::instance ()->remove_handler (this->handle_
.handle (),
62 ACE_Event_Handler::DONT_CALL
);
63 ACE_Reactor::end_event_loop ();
70 Event_Handler::handle_timeout (const ACE_Time_Value
&,
74 "(%t) timeout occurred @ %T\n"));
80 ACE_TMAIN (int, ACE_TCHAR
*[])
82 Event_Handler event_handler
;
83 event_handler
.iterations_
= 5;
84 global_event_handler
= &event_handler
;
86 int result
= ACE_Reactor::instance ()->register_handler (&event_handler
,
87 event_handler
.handle_
.handle ());
88 ACE_TEST_ASSERT (result
== 0);
90 ACE_Time_Value
timeout (2);
91 result
= ACE_Reactor::instance ()->schedule_timer (&event_handler
,
95 ACE_TEST_ASSERT (result
!= -1);
97 ACE_Reactor::run_alertable_event_loop ();
99 ACE_Reactor::instance ()->cancel_timer(&event_handler
);
103 #else /* !ACE_WIN32 */
105 ACE_TMAIN (int, ACE_TCHAR
*[])
109 #endif /* ACE_WIN32 */