diff options
author | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-12-18 20:32:22 +0000 |
---|---|---|
committer | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-12-18 20:32:22 +0000 |
commit | 2efb960e9b8c76174f922210ba66c1c8cf89ccbe (patch) | |
tree | cce0a95f8efb6d0515721cbffe9f98b500cf9121 /examples | |
parent | 2605c072815f9ccd60436bd6882080bbd832c962 (diff) | |
download | ATCD-2efb960e9b8c76174f922210ba66c1c8cf89ccbe.tar.gz |
Added new test application.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Reactor/ReactorEx/test_timeout.cpp | 72 | ||||
-rw-r--r-- | examples/Reactor/WFMO_Reactor/test_timeout.cpp | 72 |
2 files changed, 144 insertions, 0 deletions
diff --git a/examples/Reactor/ReactorEx/test_timeout.cpp b/examples/Reactor/ReactorEx/test_timeout.cpp new file mode 100644 index 00000000000..44871a2db2d --- /dev/null +++ b/examples/Reactor/ReactorEx/test_timeout.cpp @@ -0,0 +1,72 @@ +// ============================================================================ +// $Id: test_timeout.cpp + +// +// = LIBRARY +// examples +// +// = FILENAME +// test_timeout.cpp +// +// = DESCRIPTION +// This example application shows how to write ReactorEx and +// Proactor event loops that handle events for some fixed amount of +// time. +// +// = AUTHOR +// Tim Harrison +// +// ============================================================================ + +#include "ace/ReactorEx.h" +#include "ace/Proactor.h" +#include "ace/Time_Value.h" +#include "ace/Service_Config.h" +#include "ace/OS.h" + +class Timeout_Handler : public ACE_Event_Handler +// = TITLE +// Generic timeout handler. +{ +public: + Timeout_Handler (void) : count_ (0) {;} + + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg) + // Print out when timeouts occur. + { + ACE_DEBUG ((LM_DEBUG, "%d timeout occurred for %s.\n", + ++count_, + (char *) arg)); + return 0; + } + +private: + int count_; +}; + +int +main () +{ + Timeout_Handler handler; + + // Register a 2 second timer. + ACE_Time_Value foo_tv (2); + ACE_Service_Config::reactorEx ()->schedule_timer (&handler, + (void *) "Foo", + ACE_Time_Value::zero, + foo_tv); + // Register a 3 second timer. + ACE_Time_Value bar_tv (3); + ACE_Service_Config::reactorEx ()->schedule_timer (&handler, + (void *) "Bar", + ACE_Time_Value::zero, + bar_tv); + + // Handle events for 12 seconds. + ACE_Time_Value run_time (12); + if (ACE_Service_Config::run_reactorEx_event_loop (run_time) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); + + return 0; +} diff --git a/examples/Reactor/WFMO_Reactor/test_timeout.cpp b/examples/Reactor/WFMO_Reactor/test_timeout.cpp new file mode 100644 index 00000000000..44871a2db2d --- /dev/null +++ b/examples/Reactor/WFMO_Reactor/test_timeout.cpp @@ -0,0 +1,72 @@ +// ============================================================================ +// $Id: test_timeout.cpp + +// +// = LIBRARY +// examples +// +// = FILENAME +// test_timeout.cpp +// +// = DESCRIPTION +// This example application shows how to write ReactorEx and +// Proactor event loops that handle events for some fixed amount of +// time. +// +// = AUTHOR +// Tim Harrison +// +// ============================================================================ + +#include "ace/ReactorEx.h" +#include "ace/Proactor.h" +#include "ace/Time_Value.h" +#include "ace/Service_Config.h" +#include "ace/OS.h" + +class Timeout_Handler : public ACE_Event_Handler +// = TITLE +// Generic timeout handler. +{ +public: + Timeout_Handler (void) : count_ (0) {;} + + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg) + // Print out when timeouts occur. + { + ACE_DEBUG ((LM_DEBUG, "%d timeout occurred for %s.\n", + ++count_, + (char *) arg)); + return 0; + } + +private: + int count_; +}; + +int +main () +{ + Timeout_Handler handler; + + // Register a 2 second timer. + ACE_Time_Value foo_tv (2); + ACE_Service_Config::reactorEx ()->schedule_timer (&handler, + (void *) "Foo", + ACE_Time_Value::zero, + foo_tv); + // Register a 3 second timer. + ACE_Time_Value bar_tv (3); + ACE_Service_Config::reactorEx ()->schedule_timer (&handler, + (void *) "Bar", + ACE_Time_Value::zero, + bar_tv); + + // Handle events for 12 seconds. + ACE_Time_Value run_time (12); + if (ACE_Service_Config::run_reactorEx_event_loop (run_time) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); + + return 0; +} |