diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-11-27 06:04:10 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-11-27 06:04:10 +0000 |
commit | c08f68e92f2454a46ec91db97d776ad6304328bb (patch) | |
tree | a53c24ee44d6b4fb4c6bb2d8e3168b987eb9f08b /examples | |
parent | 8d87d701900caa1f26567a5c639aa2c244fa1eeb (diff) | |
download | ATCD-c08f68e92f2454a46ec91db97d776ad6304328bb.tar.gz |
foo
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Logger/simple-server/server_loggerd.cpp | 8 | ||||
-rw-r--r-- | examples/Mem_Map/IO-tests/test_io.cpp | 35 | ||||
-rw-r--r-- | examples/Reactor/Misc/test_signals_2.cpp | 4 | ||||
-rw-r--r-- | examples/Reactor/Ntalker/ntalker.cpp | 5 | ||||
-rw-r--r-- | examples/Reactor/ReactorEx/test_reactorEx.cpp | 1 | ||||
-rw-r--r-- | examples/Reactor/WFMO_Reactor/test_reactorEx.cpp | 1 | ||||
-rw-r--r-- | examples/Service_Configurator/IPC-tests/server/server_test.cpp | 27 | ||||
-rw-r--r-- | examples/Shared_Malloc/test_malloc.cpp | 7 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Message_Queues/MQ_Server.cpp | 13 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Message_Queues/TMQ_Server.cpp | 11 | ||||
-rw-r--r-- | examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp | 13 | ||||
-rw-r--r-- | examples/Threads/test_process_mutex.cpp | 15 | ||||
-rw-r--r-- | examples/Threads/test_process_semaphore.cpp | 8 | ||||
-rw-r--r-- | examples/Threads/test_task_three.cpp | 11 | ||||
-rw-r--r-- | examples/Threads/test_thread_manager.cpp | 9 | ||||
-rw-r--r-- | examples/Threads/test_thread_specific.cpp | 10 |
16 files changed, 94 insertions, 84 deletions
diff --git a/examples/Logger/simple-server/server_loggerd.cpp b/examples/Logger/simple-server/server_loggerd.cpp index 7397fc501e2..a94aef775b0 100644 --- a/examples/Logger/simple-server/server_loggerd.cpp +++ b/examples/Logger/simple-server/server_loggerd.cpp @@ -14,7 +14,7 @@ static sig_atomic_t finished = 0; -static void +extern "C" void handler (int) { finished = 1; @@ -26,11 +26,13 @@ static const u_short PORT = ACE_DEFAULT_SERVER_PORT; int main (int argc, char *argv[]) { + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); + Logging_Acceptor peer_acceptor; ACE_INET_Addr addr (PORT); - ACE_Get_Opt get_opt (argc, argv, "p:"); - ACE_Sig_Action sig ((ACE_SignalHandler) handler, SIGINT); + ACE_Get_Opt get_opt (argc, argv, "p:"); for (int c; (c = get_opt ()) != -1; ) switch (c) diff --git a/examples/Mem_Map/IO-tests/test_io.cpp b/examples/Mem_Map/IO-tests/test_io.cpp index 4615eec60e2..e209534929e 100644 --- a/examples/Mem_Map/IO-tests/test_io.cpp +++ b/examples/Mem_Map/IO-tests/test_io.cpp @@ -1,6 +1,6 @@ -/* Test program for different methods of copying files. */ // $Id$ +// Test program for different methods of copying files. #include "ace/OS.h" #include "ace/Profile_Timer.h" @@ -8,25 +8,25 @@ #include "ace/Signal.h" #include "IO_Test.h" -/* Name of program. */ +// Name of program. static char *program_name; -/* Name of default input file. */ +// Name of default input file. static char *input_filename = "/usr/dict/words"; -/* Name of default output file. */ +// Name of default output file. static char *output_filename = "/tmp/foo"; -/* Check if removing output file upon completion... */ +// Check if removing output file upon completion... static int remove_output = 1; -/* Count of the number of iterations to run the tests. */ +// Count of the number of iterations to run the tests. static int iteration_count = 100; -/* Profiler used to keep track of file I/O time. */ +// Profiler used to keep track of file I/O time. static ACE_Profile_Timer tm; -/* Explain usage and exit. */ +// Explain usage and exit. static void print_usage_and_die (void) @@ -37,17 +37,17 @@ print_usage_and_die (void) ACE_OS::exit (1); } -/* Clean up the output file on exit from a signal. */ +// Clean up the output file on exit from a signal. -static void -clean_up (int = 0) +extern "C" void +cleanup (int = 0) { if (remove_output) ACE_OS::unlink (output_filename); ACE_OS::exit (0); } -/* Set up the program name used in error messages. */ +// Set up the program name used in error messages. static void set_program_name (char name[]) @@ -58,7 +58,7 @@ set_program_name (char name[]) program_name = name + 1; } -/* Parse the command-line arguments and set options. */ +// Parse the command-line arguments and set options. static void parse_args (int argc, char *argv[]) @@ -86,7 +86,7 @@ parse_args (int argc, char *argv[]) } } -/* Vector of pointers to derived classes that inherit from IO_Test base class. */ +// Vector of pointers to derived classes that inherit from IO_Test base class. static IO_Test *test_vector[100]; @@ -99,7 +99,7 @@ run_tests (int iterations, FILE *input_fp, FILE *output_fp) test_vector[2] = new Block_Read_Write_Test ("Block_Read_Write_Test", tm); test_vector[3] = new Mmap1_Test ("Mmap1_Test", tm); test_vector[4] = new Mmap2_Test ("Mmap2_Test", tm); - /* test_vector[5] = new Slow_Read_Write_Test ("Slow"Read_Write_Test", tm) */ + // test_vector[5] = new Slow_Read_Write_Test ("Slow"Read_Write_Test", tm) test_vector[5] = (IO_Test *) 0; for (int i = 0; test_vector[i] != 0; i++) @@ -135,7 +135,8 @@ main (int argc, char *argv[]) set_program_name (argv[0]); parse_args (argc, argv); - ACE_Sig_Action sig ((ACE_SignalHandler) clean_up, SIGINT); + + ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT); if ((input_fp = ACE_OS::fopen (input_filename, "r")) == 0) ACE_OS::perror (input_filename), ACE_OS::exit (1); @@ -150,6 +151,6 @@ main (int argc, char *argv[]) if (ACE_OS::fclose (input_fp) == -1 || ACE_OS::fclose (output_fp) == -1) ACE_OS::perror ("fclose"), ACE_OS::exit (1); - clean_up (); + cleanup (); return 0; } diff --git a/examples/Reactor/Misc/test_signals_2.cpp b/examples/Reactor/Misc/test_signals_2.cpp index 7a446e05aac..8054ef7d410 100644 --- a/examples/Reactor/Misc/test_signals_2.cpp +++ b/examples/Reactor/Misc/test_signals_2.cpp @@ -173,8 +173,7 @@ public: ACE_DEBUG ((LM_DEBUG, "\nshutting down SIGQUIT in Sig_Handler_2 (%s, %d, %d)", this->msg_, this->int_sigkey_, this->quit_sigkey_)); } - else - return 0; + return 0; } }; @@ -198,6 +197,7 @@ main (int argc, char *argv) { // Register an "external" signal handler so that the // ACE_Sig_Handlers code will have something to incorporate! + ACE_SignalHandler eh = ACE_SignalHandler (external_handler); ACE_Sig_Action sa (eh); diff --git a/examples/Reactor/Ntalker/ntalker.cpp b/examples/Reactor/Ntalker/ntalker.cpp index e49c94eedf0..5c0bc4f395d 100644 --- a/examples/Reactor/Ntalker/ntalker.cpp +++ b/examples/Reactor/Ntalker/ntalker.cpp @@ -152,7 +152,7 @@ static sig_atomic_t done = 0; // Signal handler. -static void +extern "C" void handler (int) { done = 1; @@ -161,7 +161,8 @@ handler (int) int main (int argc, char *argv[]) { - ACE_Sig_Action sig ((ACE_SignalHandler) handler, SIGINT); + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); + parse_args (argc, argv); ACE_Reactor reactor; diff --git a/examples/Reactor/ReactorEx/test_reactorEx.cpp b/examples/Reactor/ReactorEx/test_reactorEx.cpp index 62143956f9c..170e0f69e4b 100644 --- a/examples/Reactor/ReactorEx/test_reactorEx.cpp +++ b/examples/Reactor/ReactorEx/test_reactorEx.cpp @@ -324,6 +324,7 @@ STDIN_Handler::STDIN_Handler (MT_TASK &ph) // exception so that the kernel doesn't kill our process. // Registering this signal handler just tells the kernel that we // know what we're doing; to leave us alone. + ACE_OS::signal (SIGINT, ACE_SignalHandler (STDIN_Handler::handler)); }; diff --git a/examples/Reactor/WFMO_Reactor/test_reactorEx.cpp b/examples/Reactor/WFMO_Reactor/test_reactorEx.cpp index 62143956f9c..170e0f69e4b 100644 --- a/examples/Reactor/WFMO_Reactor/test_reactorEx.cpp +++ b/examples/Reactor/WFMO_Reactor/test_reactorEx.cpp @@ -324,6 +324,7 @@ STDIN_Handler::STDIN_Handler (MT_TASK &ph) // exception so that the kernel doesn't kill our process. // Registering this signal handler just tells the kernel that we // know what we're doing; to leave us alone. + ACE_OS::signal (SIGINT, ACE_SignalHandler (STDIN_Handler::handler)); }; diff --git a/examples/Service_Configurator/IPC-tests/server/server_test.cpp b/examples/Service_Configurator/IPC-tests/server/server_test.cpp index f65523d956d..451f178e256 100644 --- a/examples/Service_Configurator/IPC-tests/server/server_test.cpp +++ b/examples/Service_Configurator/IPC-tests/server/server_test.cpp @@ -1,31 +1,28 @@ -/* The main test driver for the dynamically configured server. */ // $Id$ +// The main test driver for the dynamically configured server. #include "ace/Service_Config.h" -sig_atomic_t finished = 0; - -static void -handler (int) -{ - finished = 1; -} - int main (int argc, char *argv[]) { ACE_Service_Config server_test; - ACE_Sig_Action sig ((ACE_SignalHandler) handler, SIGINT); - if (server_test.open (argc, argv) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server_test.open"), -1); - for (;;) - if (server_test.run_reactor_event_loop () == -1 && finished) - break; + // Create an adapter to end the event loop. + ACE_Sig_Adapter sa (ACE_Sig_Handler_Ex (ACE_Service_Config::end_reactor_event_loop)); + + // Register a signal handler. + ACE_Service_Config::reactor ()->register_handler (SIGINT, sa); + + // Run forever, performing the configured services until we are shut + // down by a SIGINT/SIGQUIT signal. + + while (server_test.reactor_event_loop_done () == 0) + server_test.run_reactor_event_loop (); - /* NOTREACHED */ return 0; } diff --git a/examples/Shared_Malloc/test_malloc.cpp b/examples/Shared_Malloc/test_malloc.cpp index 508644adb48..694e534251b 100644 --- a/examples/Shared_Malloc/test_malloc.cpp +++ b/examples/Shared_Malloc/test_malloc.cpp @@ -1,6 +1,6 @@ -// This program tests out all the various ACE_Malloc combinations and // $Id$ +// This program tests out all the various ACE_Malloc combinations and // the ACE_Allocator_Adapter. #include "ace/Thread.h" @@ -157,7 +157,7 @@ wait_for_children (void) #endif /* ACE_WIN32 */ } -static void +extern "C" void handler (int) { Malloc::instance ()->remove (); @@ -167,7 +167,8 @@ handler (int) int main (int argc, char *argv[]) { - signal (SIGINT, ACE_SignalHandler (handler)); + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); Options::instance ()->parse_args (argc, argv); diff --git a/examples/System_V_IPC/SV_Message_Queues/MQ_Server.cpp b/examples/System_V_IPC/SV_Message_Queues/MQ_Server.cpp index 39680dd91bc..ee5f39f7efb 100644 --- a/examples/System_V_IPC/SV_Message_Queues/MQ_Server.cpp +++ b/examples/System_V_IPC/SV_Message_Queues/MQ_Server.cpp @@ -1,14 +1,14 @@ -#include "ace/Signal.h" // $Id$ +#include "ace/Signal.h" #include "ace/SV_Message_Queue.h" #include "test.h" -/* Must be global for signal Message... */ -ACE_SV_Message_Queue msgque (SRV_KEY, ACE_SV_Message_Queue::ACE_CREATE); +// Must be global for signal Message... +static ACE_SV_Message_Queue msgque (SRV_KEY, ACE_SV_Message_Queue::ACE_CREATE); -void -SIGNAL_handler (int) +extern "C" void +handler (int) { if (msgque.remove () < 0) ACE_OS::perror ("msgque.close"), ACE_OS::exit (1); @@ -23,7 +23,8 @@ main (void) ACE_Message_Block send_msg (0, pid, ACE_OS::cuserid (0), "I received your message."); - ACE_Sig_Action sig ((ACE_SignalHandler) SIGNAL_handler, SIGINT); + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); for (;;) { diff --git a/examples/System_V_IPC/SV_Message_Queues/TMQ_Server.cpp b/examples/System_V_IPC/SV_Message_Queues/TMQ_Server.cpp index 185c630ad4a..210ffe199c3 100644 --- a/examples/System_V_IPC/SV_Message_Queues/TMQ_Server.cpp +++ b/examples/System_V_IPC/SV_Message_Queues/TMQ_Server.cpp @@ -1,16 +1,16 @@ -#include "ace/Signal.h" // $Id$ +#include "ace/Signal.h" #include "ace/Typed_SV_Message_Queue.h" #include "ace/Log_Msg.h" #include "test.h" // Must be global for signal Message... -ACE_Typed_SV_Message_Queue<Message_Data> msgque +static ACE_Typed_SV_Message_Queue<Message_Data> msgque (SRV_KEY, ACE_Typed_SV_Message_Queue<Message_Data>::ACE_CREATE); -void -SIGNAL_handler (int) +extern "C" void +handler (int) { if (msgque.remove () < 0) ACE_ERROR ((LM_ERROR, "%p\n%a", "msgque.recv", 1)); @@ -25,7 +25,8 @@ main (void) ACE_Typed_SV_Message<Message_Data> send_msg (msg_data, 0, msg_data.length ()); ACE_Typed_SV_Message<Message_Data> recv_msg (SRV_ID); - ACE_Sig_Action sig2 ((ACE_SignalHandler) SIGNAL_handler, SIGINT); + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); for (;;) { diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp index 3dec989ec52..eda16178483 100644 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp +++ b/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp @@ -1,16 +1,16 @@ -#include "ace/Log_Msg.h" // $Id$ +#include "ace/Log_Msg.h" #include "ace/SV_Shared_Memory.h" #include "ace/SV_Semaphore_Simple.h" #include "ace/Signal.h" #include "Semaphore_Test.h" -ACE_SV_Shared_Memory shm_server (SHM_KEY, SHMSZ, ACE_SV_Shared_Memory::ACE_CREATE); -ACE_SV_Semaphore_Simple sem (SEM_KEY_1, ACE_SV_Semaphore_Simple::ACE_CREATE, 0, 2); +static ACE_SV_Shared_Memory shm_server (SHM_KEY, SHMSZ, ACE_SV_Shared_Memory::ACE_CREATE); +static ACE_SV_Semaphore_Simple sem (SEM_KEY_1, ACE_SV_Semaphore_Simple::ACE_CREATE, 0, 2); -static void -cleanup (int = 0) +extern "C" void +cleanup (int) { if (shm_server.remove () < 0 || sem.remove () < 0) ACE_ERROR ((LM_ERROR, "%p\n%a", "remove", 1)); @@ -20,7 +20,8 @@ cleanup (int = 0) int main (void) { - ACE_Sig_Action sig ((ACE_SignalHandler) cleanup, SIGINT); + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT); char *s = (char *) shm_server.get_segment_ptr (); diff --git a/examples/Threads/test_process_mutex.cpp b/examples/Threads/test_process_mutex.cpp index 35e5d26ad54..8f7442e36e8 100644 --- a/examples/Threads/test_process_mutex.cpp +++ b/examples/Threads/test_process_mutex.cpp @@ -1,7 +1,7 @@ -// This program tests ACE_Process_Mutexes. To run it, open 3 // $Id$ -// or 4 windows and run this program in each window... +// This program tests ACE_Process_Mutexes. To run it, open 3 or 4 +// windows and run this program in each window... #include "ace/Log_Msg.h" #include "ace/Synch.h" @@ -11,7 +11,7 @@ static sig_atomic_t done; -static void +extern "C" void handler (int) { done = 1; @@ -20,12 +20,15 @@ handler (int) int main (int argc, char *argv[]) { - char *name = argc == 1 ? "hello" : argv[1]; + char *name = argc > 1 ? argv[1] : "hello"; + int iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : 100; ACE_Process_Mutex pm (name); - ACE_Sig_Action handle ((ACE_SignalHandler) handler, SIGINT); - for (int i = 0; i < 100 && !done; i++) + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); + + for (int i = 0; i < iterations && !done; i++) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquiring\n")); if (pm.acquire () == -1) diff --git a/examples/Threads/test_process_semaphore.cpp b/examples/Threads/test_process_semaphore.cpp index e96513e5707..b1309400d29 100644 --- a/examples/Threads/test_process_semaphore.cpp +++ b/examples/Threads/test_process_semaphore.cpp @@ -1,7 +1,7 @@ -// This program tests ACE_Process_Semaphore. To run it, open 3 // $Id$ -// or 4 windows and run this program in each window... +// This program tests ACE_Process_Semaphore. To run it, open 3 or 4 +// windows and run this program in each window... #include "ace/Log_Msg.h" #include "ace/Synch.h" @@ -9,7 +9,7 @@ static sig_atomic_t done; -static void +extern "C" void handler (int) { done = 1; @@ -22,7 +22,7 @@ main (int argc, char *argv[]) ACE_Process_Semaphore pm (1, name); - ACE_Sig_Action handle ((ACE_SignalHandler) handler, SIGINT); + ACE_Sig_Action sa (ACE_SignalHandler (handler), SIGINT); for (int i = 0; i < 100 && !done; i++) { diff --git a/examples/Threads/test_task_three.cpp b/examples/Threads/test_task_three.cpp index a49094525c4..78e9a006321 100644 --- a/examples/Threads/test_task_three.cpp +++ b/examples/Threads/test_task_three.cpp @@ -92,7 +92,6 @@ Test_Task::put (ACE_Message_Block *, ACE_Time_Value *) return 0; } -int Test_Task::svc (void) { // Every thread must register the same stream to write to file. @@ -104,7 +103,7 @@ Test_Task::svc (void) for (int index = 0; index < NUM_INVOCATIONS; index++) { - ACE_OS::thr_yield (); + ACE_OS::thr_extern "C" yield (); if (r_->notify (this, ACE_Event_Handler::READ_MASK)) { @@ -162,8 +161,8 @@ dispatch (void *arg) return 0; } -static void -handler (int signum) +extern "C" void +handler (int) { *out_stream << flush; out_stream->close (); @@ -179,9 +178,11 @@ main (int argc, char **argv) out_stream = new ofstream ("test_task_three.out", ios::trunc|ios::out); ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); ACE_LOG_MSG->msg_ostream (out_stream); - signal (SIGINT, ACE_SignalHandler (handler)); } + // Register a signal handler. + ACE_Sig_Action sa (ACE_Sig_Handler_Ex (handler), SIGINT); + ACE_Reactor *reactor1 = ACE_Service_Config::reactor (); ACE_Reactor *reactor2 = new ACE_Reactor (); diff --git a/examples/Threads/test_thread_manager.cpp b/examples/Threads/test_thread_manager.cpp index 25db53b27a3..a09db55dd51 100644 --- a/examples/Threads/test_thread_manager.cpp +++ b/examples/Threads/test_thread_manager.cpp @@ -1,6 +1,6 @@ -// Test out the group management mechanisms provided by the // $Id$ +// Test out the group management mechanisms provided by the // ACE_Thread_Manager, including the group signal handling, group // suspension and resumption, and cooperative thread cancellation // mechanisms. @@ -10,7 +10,7 @@ #if defined (ACE_HAS_THREADS) -static void +extern "C" void handler (int signum) { ACE_DEBUG ((LM_DEBUG, "(%t) received signal %d\n", signum)); @@ -53,9 +53,8 @@ main (int argc, char *argv[]) daemon.open (argv[0]); - // Register a signal handler - ACE_SignalHandler sh (handler); - ACE_Sig_Action sa (sh, SIGINT); + // Register a signal handler. + ACE_Sig_Action sa (ACE_Sig_Handler_Ex (handler), SIGINT); int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_THREADS; int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_ITERATIONS; diff --git a/examples/Threads/test_thread_specific.cpp b/examples/Threads/test_thread_specific.cpp index 74bedad70d7..41b70c8c012 100644 --- a/examples/Threads/test_thread_specific.cpp +++ b/examples/Threads/test_thread_specific.cpp @@ -170,7 +170,7 @@ worker (void *c) return 0; } -static void +extern "C" void handler (int signum) { ACE_DEBUG ((LM_DEBUG, "signal = %S\n", signum)); @@ -180,15 +180,15 @@ handler (int signum) int main (int argc, char *argv[]) { - // The Service_Config must *always* be the first object defined in - // main... + // The Service_Config must be the first object defined in main... ACE_Service_Config daemon (argv[0]); ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); int threads = argc > 1 ? ACE_OS::atoi (argv[1]) : 4; int count = argc > 2 ? ACE_OS::atoi (argv[2]) : 10000; - signal (SIGINT, ACE_SignalHandler (handler)); - + // Register a signal handler. + ACE_Sig_Action sa ((ACE_SignalHandler) (handler), SIGINT); + #if defined (ACE_HAS_THREADS) if (ACE_Service_Config::thr_mgr ()->spawn_n (threads, ACE_THR_FUNC (&worker), |