2 //=============================================================================
4 * @file test_timeout_st.cpp
6 * This example application shows how to write event loops that
7 * handle events for some fixed amount of time. This is the single
8 * threaded version of the test_timeout.cpp application.
10 * @author Irfan Pyarali and Alexander Babu Arulanthu
12 //=============================================================================
15 #include "ace/Proactor.h"
16 #include "ace/OS_main.h"
19 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
20 // This only works on Win32 platforms and on Unix platforms supporting
24 * @class Timeout_Handler
26 * @brief Generic timeout handler.
28 class Timeout_Handler
: public ACE_Handler
33 start_time_ (ACE_OS::gettimeofday ())
37 virtual void handle_time_out (const ACE_Time_Value
&tv
,
40 // Print out when timeouts occur.
41 ACE_DEBUG ((LM_DEBUG
, "(%t) %d timeout occurred for %s @ %d.\n",
44 (tv
- this->start_time_
).sec ()));
48 /// Sequence number for the timeouts.
51 /// Starting time of the test.
52 ACE_Time_Value start_time_
;
57 ACE_TMAIN (int, ACE_TCHAR
*[])
59 Timeout_Handler handler
;
61 // Register a 2 second timer.
62 ACE_Time_Value
foo_tv (2);
63 if (ACE_Proactor::instance ()->schedule_timer (handler
,
67 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "schedule_timer"), -1);
69 // Register a 3 second timer.
70 ACE_Time_Value
bar_tv (3);
71 if (ACE_Proactor::instance ()->schedule_timer (handler
,
75 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "schedule_timer"), -1);
77 // Handle events for 13 seconds.
78 ACE_Time_Value
run_time (13);
80 ACE_DEBUG ((LM_DEBUG
, "Starting event loop\n"));
82 // Run the event loop.
83 if (ACE_Proactor::run_event_loop(run_time
) == -1)
84 ACE_ERROR_RETURN ((LM_ERROR
,
85 "(%t):%p.\n", "Worker::svc"),
88 ACE_DEBUG ((LM_DEBUG
, "Ending event loop\n"));
93 #endif /* ACE_HAS_WIN32_OVERLAPPED_IO || ACE_HAS_AIO_CALLS */