From 1b9bf25ac6d0a926a880b6d4dbf65eafeb80e880 Mon Sep 17 00:00:00 2001 From: irfan Date: Sun, 23 Nov 1997 02:09:14 +0000 Subject: *** empty log message *** --- ace/Acceptor.cpp | 8 ++- ace/Priority_Reactor.cpp | 8 +-- ace/Strategies_T.cpp | 1 + tests/Priority_Reactor_Test.cpp | 5 +- tests/Process_Strategy_Test.cpp | 93 +++++++++++++++++----------------- tests/Process_Strategy_Test.h | 19 +++++-- tests/tests.mdp | Bin 18946 -> 18681 bytes tests/version_tests/version_tests.mdp | Bin 164864 -> 164864 bytes 8 files changed, 71 insertions(+), 63 deletions(-) diff --git a/ace/Acceptor.cpp b/ace/Acceptor.cpp index 3f93a231775..53297383d74 100644 --- a/ace/Acceptor.cpp +++ b/ace/Acceptor.cpp @@ -257,14 +257,13 @@ template int ACE_Acceptor::activate_svc_handler (SVC_HANDLER *svc_handler) { - ACE_Trace::start_tracing (); ACE_TRACE ("ACE_Acceptor::activate_svc_handler"); int result = 0; // See if we should enable non-blocking I/O on the 's // peer. - if (ACE_BIT_ENABLED (this->flags_, ACE_NONBLOCK) != 0) + if (ACE_BIT_ENABLED (this->flags_, ACE_NONBLOCK)) { if (svc_handler->peer ().enable (ACE_NONBLOCK) == -1) result = -1; @@ -273,13 +272,12 @@ ACE_Acceptor::activate_svc_handler else if (svc_handler->peer ().disable (ACE_NONBLOCK) == -1) result = -1; - if (svc_handler->open ((void *) this) == -1) + if (result == 0 && svc_handler->open ((void *) this) == -1) result = -1; - + if (result == -1) svc_handler->close (0); - ACE_Trace::stop_tracing (); return result; } diff --git a/ace/Priority_Reactor.cpp b/ace/Priority_Reactor.cpp index 29ec6a9550f..bd9d48ab12e 100644 --- a/ace/Priority_Reactor.cpp +++ b/ace/Priority_Reactor.cpp @@ -23,8 +23,8 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Priority_Reactor) const int npriorities = ACE_Event_Handler::HI_PRIORITY - ACE_Event_Handler::LO_PRIORITY + 1; -ACE_INLINE -void ACE_Priority_Reactor::init_bucket (void) +ACE_INLINE void +ACE_Priority_Reactor::init_bucket (void) { // Allocate enough space for all the handles. // TODO: This can be wrong, maybe we should use other kind of @@ -36,10 +36,6 @@ void ACE_Priority_Reactor::init_bucket (void) ACE_NEW (this->bucket_, QUEUE*[npriorities]); // This loops "ensures" exception safety. int i; - for (i = 0; i < npriorities; ++i) - { - this->bucket_[i] = 0; - } for (i = 0; i < npriorities; ++i) { ACE_NEW (this->bucket_[i], QUEUE (this->tuple_allocator_)); diff --git a/ace/Strategies_T.cpp b/ace/Strategies_T.cpp index db904cc0552..cde17d72709 100644 --- a/ace/Strategies_T.cpp +++ b/ace/Strategies_T.cpp @@ -361,6 +361,7 @@ ACE_Reactive_Strategy::activate_svc_handler (SVC_HANDLER *svc_handl if (result == -1) svc_handler->close (0); + return result; } diff --git a/tests/Priority_Reactor_Test.cpp b/tests/Priority_Reactor_Test.cpp index 9e2a3692a36..bb1cf5a4614 100644 --- a/tests/Priority_Reactor_Test.cpp +++ b/tests/Priority_Reactor_Test.cpp @@ -253,8 +253,9 @@ main (int argc, char *argv[]) } // Manage memory automagically. - auto_ptr impl; + // Note: This ordering is very subtle... auto_ptr reactor; + auto_ptr impl; if (opt_priority_reactor) { @@ -332,7 +333,7 @@ main (int argc, char *argv[]) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) running out of time, " - "probably due to failed connections.")); + "probably due to failed connections.\n")); } ACE_DEBUG ((LM_DEBUG, "(%P|%t) waiting for the children...\n")); diff --git a/tests/Process_Strategy_Test.cpp b/tests/Process_Strategy_Test.cpp index 3944dbadb44..3c111b8b2a1 100644 --- a/tests/Process_Strategy_Test.cpp +++ b/tests/Process_Strategy_Test.cpp @@ -51,8 +51,7 @@ // Define a that's parameterized by the // . -typedef ACE_Strategy_Acceptor - ACCEPTOR; +typedef ACE_Strategy_Acceptor ACCEPTOR; // Create an Options Singleton. typedef ACE_Singleton OPTIONS; @@ -61,14 +60,47 @@ typedef ACE_Singleton OPTIONS; static int connections = 0; // Use this to show down the process gracefully. +static void +connection_completed () +{ + // Increment connection counter + connections++; + + // If all connections have been serviced + if (connections == ACE_MAX_ITERATIONS + 1) + // Make sure that the event loop is interrupted + ACE_Reactor::instance()->wakeup_all_threads (); +} +// Have all connections been serviced? static int done (void) { - if (OPTIONS::instance ()->concurrency_type () == Options::PROCESS) - return connections == 1; - else - return connections == ACE_MAX_ITERATIONS + 1; + return connections == ACE_MAX_ITERATIONS + 1; +} + +// Constructor +Process_Strategy::Process_Strategy (size_t n_processes, + ACE_Event_Handler *acceptor, + ACE_Reactor *r, + int flags) + : ACE_Process_Strategy (n_processes, acceptor, r, flags) +{ +} + +// Overwrite the process creation method to include connection +// counting +int +Process_Strategy::activate_svc_handler (Counting_Service *svc_handler, + void *arg) +{ + // Call down to the base class + int result = ACE_Process_Strategy::activate_svc_handler (svc_handler, arg); + + // Connection is now complete + connection_completed (); + + return result; } ACE_File_Lock & @@ -93,11 +125,11 @@ Options::Options (void) : // Choose to use processes by default. #if !defined (ACE_LACKS_FORK) - concurrency_type_ (PROCESS) + concurrency_type_ (PROCESS) #elif defined (ACE_HAS_THREADS) - concurrency_type_ (THREAD) + concurrency_type_ (THREAD) #else - concurrency_type_ (REACTIVE) + concurrency_type_ (REACTIVE) #endif /* !ACE_LACKS_FORK */ { } @@ -164,8 +196,7 @@ Options::parse_args (int argc, char *argv[]) case Options::PROCESS: #if !defined (ACE_LACKS_FORK) ACE_NEW_RETURN (this->concurrency_strategy_, - ACE_Process_Strategy - (1, this, ACE_Reactor::instance()), + Process_Strategy (1, this, ACE_Reactor::instance()), -1); break; #else @@ -175,7 +206,7 @@ Options::parse_args (int argc, char *argv[]) #if defined (ACE_HAS_THREADS) ACE_NEW_RETURN (this->concurrency_strategy_, ACE_Thread_Strategy - (ACE_Thread_Manager::instance (), + (ACE_Thread_Manager::instance (), THR_NEW_LWP, 1), -1); break; @@ -191,13 +222,6 @@ Options::parse_args (int argc, char *argv[]) break; } -#if !defined (ACE_WIN32) && !defined (VXWORKS) - // Register to handle when a child exits. - if (ACE_Reactor::instance ()->register_handler (SIGCHLD, this) == -1) - return -1; -#endif /* !defined (ACE_WIN32) && !defined (VXWORKS) */ - if (ACE_Reactor::instance ()->register_handler (SIGINT, this) == -1) - return -1; return 0; } @@ -213,28 +237,6 @@ Options::concurrency_type (Options::Concurrency_Type cs) this->concurrency_type_ = cs; } -// Reap child processes. - -int -Options::handle_signal (int signum, siginfo_t *, ucontext_t *) -{ - switch (signum) - { - case SIGCHLD: - pid_t pid; - - while ((pid = ACE_OS::waitpid (-1, 0, WNOHANG)) > 0) - continue; - break; - - case SIGINT: - ACE_Reactor::end_event_loop(); - break; - } - - return 0; -} - Counting_Service::Counting_Service (ACE_Thread_Manager *) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) creating the Counting_Service\n")); @@ -361,7 +363,7 @@ Counting_Service::handle_close (ACE_HANDLE, ACE_Reactor_Mask) { // Done with another connection. - connections++; + connection_completed (); // Call down to base class return ACE_Svc_Handler::handle_close (); @@ -532,15 +534,12 @@ main (int argc, char *argv[]) exit (-1); /* NOTREACHED */ case 0: - signal (SIGCHLD, SIG_IGN); + ACE_OS::signal (SIGCHLD, SIG_IGN); server (0); break; /* NOTREACHED */ default: client (&server_addr); - // Shutdown the server process. - if (ACE_OS::kill (pid, SIGINT) == 0) - ACE_OS::wait (); break; /* NOTREACHED */ } @@ -558,7 +557,7 @@ main (int argc, char *argv[]) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "thread create failed")); // Wait for the threads to exit. - ACE_Thread_Manager::instance ()->wait (); + ACE_Thread_Manager::instance ()->wait (); #else ACE_ERROR ((LM_ERROR, "(%P|%t) only one thread may be run in a process on this platform\n%a", diff --git a/tests/Process_Strategy_Test.h b/tests/Process_Strategy_Test.h index 7556af9566d..7f8c9dcfcf7 100644 --- a/tests/Process_Strategy_Test.h +++ b/tests/Process_Strategy_Test.h @@ -65,6 +65,22 @@ protected: // Closing down }; +class Process_Strategy : public ACE_Process_Strategy +{ +public: + + // Constructor + Process_Strategy (size_t n_processes = 1, + ACE_Event_Handler *acceptor = 0, + ACE_Reactor * = 0, + int flags = 0); + + // Overwrite the process creation method to include connection + // counting + virtual int activate_svc_handler (Counting_Service *svc_handler, + void *arg = 0); +}; + class Options : public ACE_Event_Handler // = TITLE // Maintains the options for this program. @@ -99,9 +115,6 @@ public: ACE_Concurrency_Strategy *concurrency_strategy (void); // Returns the concurrency strategy. - virtual int handle_signal (int, siginfo_t *, ucontext_t *); - // Catch the SIGCHLD signal and reap the exiting child processes. - private: Concurrency_Type concurrency_type_; // Concurrency strategy that we're running. diff --git a/tests/tests.mdp b/tests/tests.mdp index 6413afe375e..04c8793eedd 100644 Binary files a/tests/tests.mdp and b/tests/tests.mdp differ diff --git a/tests/version_tests/version_tests.mdp b/tests/version_tests/version_tests.mdp index d7b2c9f922d..094f98e6fe6 100644 Binary files a/tests/version_tests/version_tests.mdp and b/tests/version_tests/version_tests.mdp differ -- cgit v1.2.1