summaryrefslogtreecommitdiff
path: root/examples/Reactor/WFMO_Reactor/test_apc.cpp
diff options
context:
space:
mode:
authorirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-03-23 06:06:12 +0000
committerirfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-03-23 06:06:12 +0000
commit796e49174648b87a7eacd944003cbbaabb0d8379 (patch)
tree5e3b38d15580ce70f37435ff8c70249cef46ff23 /examples/Reactor/WFMO_Reactor/test_apc.cpp
parent1df6e981cd9c404ba690a648493c3eefcb1a2fc8 (diff)
downloadATCD-796e49174648b87a7eacd944003cbbaabb0d8379.tar.gz
*** empty log message ***
Diffstat (limited to 'examples/Reactor/WFMO_Reactor/test_apc.cpp')
-rw-r--r--examples/Reactor/WFMO_Reactor/test_apc.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/examples/Reactor/WFMO_Reactor/test_apc.cpp b/examples/Reactor/WFMO_Reactor/test_apc.cpp
new file mode 100644
index 00000000000..00a1f4a9b1c
--- /dev/null
+++ b/examples/Reactor/WFMO_Reactor/test_apc.cpp
@@ -0,0 +1,100 @@
+// $Id$
+//
+// ============================================================================
+//
+// = LIBRARY
+// examples
+//
+// = FILENAME
+// test_apc.cpp
+//
+// = DESCRIPTION
+//
+// Tests the WFMO_Reactor's ability to handle regular APC
+// notifications.
+//
+// = AUTHOR
+//
+// Irfan Pyarali
+//
+// ============================================================================
+
+#include "ace/Reactor.h"
+
+void queue_apc (void);
+
+class Event_Handler : public ACE_Event_Handler
+{
+public:
+ int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
+
+ int handle_timeout (const ACE_Time_Value &tv,
+ const void *arg = 0);
+
+ ACE_Auto_Event handle_;
+ int iterations_;
+};
+
+int
+Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "handling signal: %d iterations left\n",
+ --this->iterations_));
+
+ if (this->iterations_ == 0)
+ ACE_Reactor::end_event_loop ();
+
+ return 0;
+}
+
+int
+Event_Handler::handle_timeout (const ACE_Time_Value &tv,
+ const void *arg)
+{
+ ACE_DEBUG ((LM_DEBUG, "(%t) timeout occured @ %T\n"));
+
+ queue_apc ();
+
+ return 0;
+}
+
+Event_Handler event_handler;
+
+void WINAPI
+apc_callback (DWORD)
+{
+ ACE_DEBUG ((LM_DEBUG, "(%t) apc occured @ %T\n"));
+
+ event_handler.handle_.signal ();
+}
+
+void
+queue_apc (void)
+{
+ DWORD result = ::QueueUserAPC (&apc_callback, // pointer to APC function
+ ::GetCurrentThread (), // handle to the thread
+ 0 // argument for the APC function
+ );
+ if (result == FALSE)
+ ACE_OS::exit (-1);
+}
+
+int
+main (void)
+{
+ event_handler.iterations_ = 5;
+ ACE_ASSERT (ACE_Reactor::instance ()->register_handler (&event_handler,
+ event_handler.handle_.handle ()) == 0);
+
+ ACE_Time_Value timeout (2);
+ ACE_ASSERT (ACE_Reactor::instance ()->schedule_timer (&event_handler,
+ 0,
+ timeout,
+ timeout) != -1);
+
+ ACE_Reactor::run_alertable_event_loop ();
+
+ return 0;
+}
+