2 //=============================================================================
4 * @file Sig_Handlers_Test.cpp
6 * This is a simple program that tests whether the ACE_Sig_Handlers
7 * class works properly. To run this test, start the application
8 * and then type ^C. If everything is working properly the test
9 * will shutdown gracefully.
11 * @author Douglas C. Schmidt <schmidt@dre.vanderbilt.edu> and Andreas Drescher <ace at anticat dot ch>
13 //=============================================================================
16 #include "test_config.h"
17 #include "ace/Reactor.h"
18 #include "ace/WFMO_Reactor.h"
19 #include "ace/Select_Reactor.h"
20 #include "ace/Log_Msg.h"
21 #include "ace/Signal.h"
22 #include "ace/Assert.h"
23 #include "ace/SString.h"
26 class Test_SIGINT_Handler
: public ACE_Event_Handler
29 Test_SIGINT_Handler (ACE_Reactor
*reactor
, const char *message
)
32 int result
= reactor
->register_handler (SIGINT
, this);
34 ACE_TEXT("Main::Test_SIGINT_Handler (%u) - Result %i\n"),
37 Test_SIGINT_Handler::registration_count_
++;
40 ~Test_SIGINT_Handler() override
42 ACE_TEST_ASSERT (Test_SIGINT_Handler::handle_signal_count_
== Test_SIGINT_Handler::registration_count_
);
45 int handle_signal (int signal
, siginfo_t
*, ucontext_t
*) override
47 ACE_TEST_ASSERT (signal
== SIGINT
);
49 ACE_TEXT("Main::Test_SIGINT_Handler (%u) - %s\n"),
51 this->message_
.c_str()));
52 Test_SIGINT_Handler::handle_signal_count_
++;
59 static int handle_signal_count_
;
61 static int registration_count_
;
64 int Test_SIGINT_Handler::handle_signal_count_
= 0;
65 int Test_SIGINT_Handler::registration_count_
= 0;
67 class Test_SIGINT_Shutdown_Handler
: public ACE_Event_Handler
70 Test_SIGINT_Shutdown_Handler (ACE_Reactor
*reactor
)
72 int result
= reactor
->register_handler (SIGINT
, this);
74 ACE_TEXT("Main::Test_SIGINT_Shutdown_Handler (%u) - Result %i\n"),
79 int handle_signal (int signal
, siginfo_t
*, ucontext_t
*) override
81 ACE_TEST_ASSERT (signal
== SIGINT
);
83 ACE_TEXT("Main::Test_SIGINT_Shutdown_Handler (%u)\n"),
85 ACE_Reactor::instance ()->end_reactor_event_loop ();
91 run_main (int, ACE_TCHAR
*[])
93 ACE_START_TEST (ACE_TEXT ("Sig_Handlers_Test"));
95 ACE_Sig_Handlers multi_handlers
;
96 ACE_Select_Reactor
reactor_impl (&multi_handlers
);
97 ACE_Reactor
reactor (&reactor_impl
);
98 ACE_Reactor::instance (&reactor
);
100 // Create a bevy of handlers.
102 Test_SIGINT_Handler
h1 (ACE_Reactor::instance (), "h1");
103 Test_SIGINT_Handler
h2 (ACE_Reactor::instance (), "h2");
104 Test_SIGINT_Handler
h3 (ACE_Reactor::instance (), "h3");
105 Test_SIGINT_Handler
h4 (ACE_Reactor::instance (), "h4");
106 Test_SIGINT_Handler
h5 (ACE_Reactor::instance (), "h5");
107 Test_SIGINT_Handler
h6 (ACE_Reactor::instance (), "h6");
108 Test_SIGINT_Handler
h7 (ACE_Reactor::instance (), "h7");
109 Test_SIGINT_Handler
h8 (ACE_Reactor::instance (), "h8");
111 Test_SIGINT_Shutdown_Handler
h0 (ACE_Reactor::instance ());
113 // Wait for user to type SIGINT.
114 while (!ACE_Reactor::instance ()->reactor_event_loop_done ())
116 ACE_DEBUG ((LM_DEBUG
,"\nwaiting for SIGINT\n"));
117 if (ACE_Reactor::instance ()->handle_events () == -1)
118 ACE_ERROR ((LM_ERROR
,"%p\n","handle_events"));