diff options
20 files changed, 470 insertions, 312 deletions
diff --git a/ChangeLog b/ChangeLog index 688cc2699bc..1adcae54933 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Tue Mar 13 20:56:10 2001 Irfan Pyarali <irfan@cs.wustl.edu> + + * ace/WFMO_Reactor.cpp (remove_to_be_added_handler_i): + * ace/WFMO_Reactor.cpp (remove_suspended_handler_i): + * ace/WFMO_Reactor.cpp (remove_handler_i): + + If a user tried to (a) remove a "to be suspended handle" from + either the current info set or the to be added set, the handle + was correctly removed but the "to be suspended handle" count was + not reduced; (b) remove a "to be resumed handle" from the + suspended set, the handle was correctly removed but the "to be + resumed handle" count was not reduced. Since the "to be resumed + handle" and the "to be suspended handle" were not adjusted + properly, the reactor kept waking up thinking that changes were + required. Thanks to Lu Yunhai <luyunhai@huawei.com> for + reporting this problem. + + * examples/Reactor/WFMO_Reactor/test_suspended_removals.cpp: Added + an extensive example for regression testing the above use cases. + Tue Mar 13 15:23:04 2001 Nanbor Wang <nanbor@cs.wustl.edu> * ace/Service_Manager.cpp (list_services): Fixed Unicode bugs. diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 688cc2699bc..1adcae54933 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,23 @@ +Tue Mar 13 20:56:10 2001 Irfan Pyarali <irfan@cs.wustl.edu> + + * ace/WFMO_Reactor.cpp (remove_to_be_added_handler_i): + * ace/WFMO_Reactor.cpp (remove_suspended_handler_i): + * ace/WFMO_Reactor.cpp (remove_handler_i): + + If a user tried to (a) remove a "to be suspended handle" from + either the current info set or the to be added set, the handle + was correctly removed but the "to be suspended handle" count was + not reduced; (b) remove a "to be resumed handle" from the + suspended set, the handle was correctly removed but the "to be + resumed handle" count was not reduced. Since the "to be resumed + handle" and the "to be suspended handle" were not adjusted + properly, the reactor kept waking up thinking that changes were + required. Thanks to Lu Yunhai <luyunhai@huawei.com> for + reporting this problem. + + * examples/Reactor/WFMO_Reactor/test_suspended_removals.cpp: Added + an extensive example for regression testing the above use cases. + Tue Mar 13 15:23:04 2001 Nanbor Wang <nanbor@cs.wustl.edu> * ace/Service_Manager.cpp (list_services): Fixed Unicode bugs. diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 688cc2699bc..1adcae54933 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,23 @@ +Tue Mar 13 20:56:10 2001 Irfan Pyarali <irfan@cs.wustl.edu> + + * ace/WFMO_Reactor.cpp (remove_to_be_added_handler_i): + * ace/WFMO_Reactor.cpp (remove_suspended_handler_i): + * ace/WFMO_Reactor.cpp (remove_handler_i): + + If a user tried to (a) remove a "to be suspended handle" from + either the current info set or the to be added set, the handle + was correctly removed but the "to be suspended handle" count was + not reduced; (b) remove a "to be resumed handle" from the + suspended set, the handle was correctly removed but the "to be + resumed handle" count was not reduced. Since the "to be resumed + handle" and the "to be suspended handle" were not adjusted + properly, the reactor kept waking up thinking that changes were + required. Thanks to Lu Yunhai <luyunhai@huawei.com> for + reporting this problem. + + * examples/Reactor/WFMO_Reactor/test_suspended_removals.cpp: Added + an extensive example for regression testing the above use cases. + Tue Mar 13 15:23:04 2001 Nanbor Wang <nanbor@cs.wustl.edu> * ace/Service_Manager.cpp (list_services): Fixed Unicode bugs. diff --git a/ace/WFMO_Reactor.cpp b/ace/WFMO_Reactor.cpp index 363194a123a..54f96b9d70c 100644 --- a/ace/WFMO_Reactor.cpp +++ b/ace/WFMO_Reactor.cpp @@ -283,6 +283,16 @@ ACE_WFMO_Reactor_Handler_Repository::remove_handler_i (size_t slot, // Make sure that the <to_be_removed_masks> is the NULL_MASK to_be_removed_masks = ACE_Event_Handler::NULL_MASK; + // If this event was marked for suspension, undo the suspension flag + // and reduce the to be suspended count. + if (this->current_info_[slot].suspend_entry_) + { + // Undo suspension + this->current_info_[slot].suspend_entry_ = 0; + // Decrement the handle count + this->handles_to_be_suspended_--; + } + // If there are no more events that the <Event_Handler> is // interested in, or this is a non-I/O entry, schedule the // <Event_Handler> for removal @@ -341,6 +351,16 @@ ACE_WFMO_Reactor_Handler_Repository::remove_suspended_handler_i (size_t slot, // Make sure that the <to_be_removed_masks> is the NULL_MASK to_be_removed_masks = ACE_Event_Handler::NULL_MASK; + // If this event was marked for resumption, undo the resumption flag + // and reduce the to be resumed count. + if (this->current_suspended_info_[slot].resume_entry_) + { + // Undo resumption + this->current_suspended_info_[slot].resume_entry_ = 0; + // Decrement the handle count + this->handles_to_be_resumed_--; + } + // If there are no more events that the <Event_Handler> is // interested in, or this is a non-I/O entry, schedule the // <Event_Handler> for removal @@ -398,6 +418,16 @@ ACE_WFMO_Reactor_Handler_Repository::remove_to_be_added_handler_i (size_t slot, // Make sure that the <to_be_removed_masks> is the NULL_MASK to_be_removed_masks = ACE_Event_Handler::NULL_MASK; + // If this event was marked for suspension, undo the suspension flag + // and reduce the to be suspended count. + if (this->to_be_added_info_[slot].suspend_entry_) + { + // Undo suspension + this->to_be_added_info_[slot].suspend_entry_ = 0; + // Decrement the handle count + this->handles_to_be_suspended_--; + } + // If there are no more events that the <Event_Handler> is // interested in, or this is a non-I/O entry, schedule the // <Event_Handler> for removal diff --git a/ace/WFMO_Reactor.h b/ace/WFMO_Reactor.h index 09cec5cf7b5..d98bdd4612b 100644 --- a/ace/WFMO_Reactor.h +++ b/ace/WFMO_Reactor.h @@ -97,6 +97,7 @@ class ACE_Export ACE_WFMO_Reactor_Handler_Repository { public: friend class ACE_WFMO_Reactor; + friend class ACE_WFMO_Reactor_Test; /** * @class Common_Info diff --git a/examples/Reactor/WFMO_Reactor/Suspended_Removals.dsp b/examples/Reactor/WFMO_Reactor/Suspended_Removals.dsp new file mode 100644 index 00000000000..ecad1880f11 --- /dev/null +++ b/examples/Reactor/WFMO_Reactor/Suspended_Removals.dsp @@ -0,0 +1,58 @@ +# Microsoft Developer Studio Project File - Name="Suspended_Removals" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Suspended_Removals - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Suspended_Removals.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Suspended_Removals.mak" CFG="Suspended_Removals - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Suspended_Removals - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Suspended_Removal0"
+# PROP BASE Intermediate_Dir "Suspended_Removal0"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 aced.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\ace"
+# Begin Target
+
+# Name "Suspended_Removals - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\test_suspended_removals.cpp
+# End Source File
+# End Target
+# End Project
diff --git a/examples/Reactor/WFMO_Reactor/WFMO_Reactor.dsw b/examples/Reactor/WFMO_Reactor/WFMO_Reactor.dsw index 81f8e0d8760..0e0f4c6988b 100644 --- a/examples/Reactor/WFMO_Reactor/WFMO_Reactor.dsw +++ b/examples/Reactor/WFMO_Reactor/WFMO_Reactor.dsw @@ -1,4 +1,4 @@ -Microsoft Developer Studio Workspace File, Format Version 5.00
+Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
@@ -147,6 +147,18 @@ Package=<4> ###############################################################################
+Project: "Suspended_Removals"=.\Suspended_Removals.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
Project: "Talker"=.\Talker.dsp - Package Owner=<4>
Package=<5>
diff --git a/examples/Reactor/WFMO_Reactor/test_apc.cpp b/examples/Reactor/WFMO_Reactor/test_apc.cpp index f9cf0ac4d64..b16c5cdee1f 100644 --- a/examples/Reactor/WFMO_Reactor/test_apc.cpp +++ b/examples/Reactor/WFMO_Reactor/test_apc.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_apc.cpp // @@ -12,23 +12,23 @@ // // Tests the WFMO_Reactor's ability to handle regular APC // notifications. -// +// // = AUTHOR -// +// // Irfan Pyarali <irfan@cs.wustl.edu> -// +// // ============================================================================ #include "ace/Reactor.h" -ACE_RCSID(ReactorEx, test_apc, "$Id$") +ACE_RCSID(WFMO_Reactor, test_apc, "$Id$") class Event_Handler : public ACE_Event_Handler { public: int handle_signal (int signum, siginfo_t * = 0, - ucontext_t * = 0); + ucontext_t * = 0); int handle_timeout (const ACE_Time_Value &tv, const void *arg = 0); @@ -38,27 +38,27 @@ public: }; static Event_Handler event_handler; - + static void WINAPI apc_callback (DWORD) { ACE_DEBUG ((LM_DEBUG, - "(%t) apc occured @ %T\n")); + "(%t) apc occured @ %T\n")); event_handler.handle_.signal (); } -void +void queue_apc (void) { - DWORD result = ::QueueUserAPC (&apc_callback, // pointer to APC function - ::GetCurrentThread (), // handle to the thread + DWORD result = ::QueueUserAPC (&apc_callback, // pointer to APC function + ::GetCurrentThread (), // handle to the thread 0); // argument for the APC function if (result == FALSE) ACE_OS::exit (-1); } -int +int Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) @@ -66,38 +66,37 @@ Event_Handler::handle_signal (int signum, --this->iterations_; if (this->iterations_ == 0) - ACE_Reactor::end_event_loop (); + ACE_Reactor::end_event_loop (); return 0; } -int +int Event_Handler::handle_timeout (const ACE_Time_Value &tv, const void *arg) { ACE_DEBUG ((LM_DEBUG, - "(%t) timeout occured @ %T\n")); + "(%t) timeout occured @ %T\n")); queue_apc (); return 0; } -int +int main (int argc, char *argv[]) { event_handler.iterations_ = 5; - int result = ACE_Reactor::instance ()->register_handler (&event_handler, + int result = ACE_Reactor::instance ()->register_handler (&event_handler, event_handler.handle_.handle ()); ACE_ASSERT (result == 0); - + ACE_Time_Value timeout (2); - result = ACE_Reactor::instance ()->schedule_timer (&event_handler, + result = ACE_Reactor::instance ()->schedule_timer (&event_handler, 0, timeout, timeout); ACE_ASSERT (result != -1); - + ACE_Reactor::run_alertable_event_loop (); return 0; } - diff --git a/examples/Reactor/WFMO_Reactor/test_console_input.cpp b/examples/Reactor/WFMO_Reactor/test_console_input.cpp index bb8c1d5a7b6..adc9915b0a2 100644 --- a/examples/Reactor/WFMO_Reactor/test_console_input.cpp +++ b/examples/Reactor/WFMO_Reactor/test_console_input.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_console_input.cpp // @@ -20,15 +20,15 @@ #include "ace/Reactor.h" -ACE_RCSID(ReactorEx, test_console_input, "$Id$") +ACE_RCSID(WFMO_Reactor, test_console_input, "$Id$") class Event_Handler : public ACE_Event_Handler { public: Event_Handler (ACE_Reactor &reactor); - int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); + int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); }; Event_Handler::Event_Handler (ACE_Reactor &reactor) @@ -36,12 +36,12 @@ Event_Handler::Event_Handler (ACE_Reactor &reactor) this->reactor (&reactor); if (this->reactor ()->register_handler (this, - ACE_STDIN) != 0) + ACE_STDIN) != 0) ACE_ERROR ((LM_ERROR, - "Registration with Reactor could not be done\n")); + "Registration with Reactor could not be done\n")); } -int +int Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) { ACE_TCHAR buffer[BUFSIZ]; @@ -58,13 +58,13 @@ Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) this->reactor ()->close (); ACE_DEBUG ((LM_DEBUG, "User input: %s", buffer)); - + return 0; } -int +int Event_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Event_Handler removed from Reactor\n")); return 0; diff --git a/examples/Reactor/WFMO_Reactor/test_directory_changes.cpp b/examples/Reactor/WFMO_Reactor/test_directory_changes.cpp index 86c02dc2154..fbcc5367a4d 100644 --- a/examples/Reactor/WFMO_Reactor/test_directory_changes.cpp +++ b/examples/Reactor/WFMO_Reactor/test_directory_changes.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_directory_changes.cpp // @@ -15,12 +15,12 @@ // // = AUTHOR // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" -ACE_RCSID(ReactorEx, test_directory_changes, "$Id$") +ACE_RCSID(WFMO_Reactor, test_directory_changes, "$Id$") static int stop_test = 0; static const ACE_TCHAR *directory = ACE_TEXT ("."); @@ -31,9 +31,9 @@ class Event_Handler : public ACE_Event_Handler public: Event_Handler (ACE_Reactor &reactor); ~Event_Handler (void); - int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); + int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); private: ACE_HANDLE handle_; @@ -44,25 +44,25 @@ Event_Handler::Event_Handler (ACE_Reactor &reactor) { this->reactor (&reactor); - int change_notification_flags = FILE_NOTIFY_CHANGE_FILE_NAME; + int change_notification_flags = FILE_NOTIFY_CHANGE_FILE_NAME; - this->handle_ = ::FindFirstChangeNotification (directory, // pointer to name of directory to watch - FALSE, // flag for monitoring directory or directory tree - change_notification_flags // filter conditions to watch for - ); + this->handle_ = ::FindFirstChangeNotification (directory, // pointer to name of directory to watch + FALSE, // flag for monitoring directory or directory tree + change_notification_flags // filter conditions to watch for + ); if (this->handle_ == ACE_INVALID_HANDLE) ACE_ERROR ((LM_ERROR, "FindFirstChangeNotification could not be setup\n")); - + if (this->reactor ()->register_handler (this, - this->handle_) != 0) - ACE_ERROR ((LM_ERROR, "Registration with Reactor could not be done\n")); + this->handle_) != 0) + ACE_ERROR ((LM_ERROR, "Registration with Reactor could not be done\n")); } Event_Handler::~Event_Handler (void) { } -int +int Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) { ::FindNextChangeNotification (this->handle_); @@ -71,23 +71,23 @@ Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) return 0; } -int +int Event_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Event_Handler removed from Reactor\n")); ::FindCloseChangeNotification (this->handle_); return 0; } -void +void worker (void) { ACE_DEBUG ((LM_DEBUG, "(%t) Thread creation\n")); ACE_DEBUG ((LM_DEBUG, "(%t) Thread creating temporary file\n")); ACE_HANDLE file = ACE_OS::open (temp_file, _O_CREAT | _O_EXCL); if (file == ACE_INVALID_HANDLE) - ACE_ERROR ((LM_ERROR, "Error in creating %s: %p\n", temp_file, "ACE_OS::open")); + ACE_ERROR ((LM_ERROR, "Error in creating %s: %p\n", temp_file, "ACE_OS::open")); else { ACE_OS::close (file); diff --git a/examples/Reactor/WFMO_Reactor/test_exceptions.cpp b/examples/Reactor/WFMO_Reactor/test_exceptions.cpp index 5ab6d00cb4e..951959f39e1 100644 --- a/examples/Reactor/WFMO_Reactor/test_exceptions.cpp +++ b/examples/Reactor/WFMO_Reactor/test_exceptions.cpp @@ -4,14 +4,14 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_exceptions.cpp // // = DESCRIPTION // // This test application tests the state of WFMO_Reactor when -// exceptions occurs when executing user callbacks. +// exceptions occurs when executing user callbacks. // // The thread count in WFMO_Reactor is used to ensure that state of // WFMO_Reactor is not fouled up when exceptions occur in user code. @@ -20,12 +20,12 @@ // // = AUTHOR // Irfan Pyarali -// +// // ============================================================================ #include "ace/WFMO_Reactor.h" -ACE_RCSID(ReactorEx, test_exceptions, "$Id$") +ACE_RCSID(WFMO_Reactor, test_exceptions, "$Id$") class Event_Handler : public ACE_Event_Handler { @@ -65,21 +65,21 @@ public: { for (int i = 1; i <= 10; i++) { - ACE_DEBUG ((LM_DEBUG, - "Active threads in WFMO_Reactor (before handle_events) = %d\n", - wfmo_reactor.active_threads_)); - ACE_SEH_TRY - { - wfmo_reactor.handle_events (); - } - ACE_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) - { - ACE_DEBUG ((LM_DEBUG, + ACE_DEBUG ((LM_DEBUG, + "Active threads in WFMO_Reactor (before handle_events) = %d\n", + wfmo_reactor.active_threads_)); + ACE_SEH_TRY + { + wfmo_reactor.handle_events (); + } + ACE_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) + { + ACE_DEBUG ((LM_DEBUG, "Exception occurred\n")); - } - ACE_DEBUG ((LM_DEBUG, - "Active threads in WFMO_Reactor (after handle_events) = %d\n", - wfmo_reactor.active_threads_)); + } + ACE_DEBUG ((LM_DEBUG, + "Active threads in WFMO_Reactor (after handle_events) = %d\n", + wfmo_reactor.active_threads_)); } } }; @@ -95,4 +95,3 @@ main (int, char *[]) return 0; } - diff --git a/examples/Reactor/WFMO_Reactor/test_multithreading.cpp b/examples/Reactor/WFMO_Reactor/test_multithreading.cpp index 8e59adffe5b..b2988c18b96 100644 --- a/examples/Reactor/WFMO_Reactor/test_multithreading.cpp +++ b/examples/Reactor/WFMO_Reactor/test_multithreading.cpp @@ -27,7 +27,7 @@ #include "ace/WFMO_Reactor.h" #include "ace/Get_Opt.h" -ACE_RCSID(ReactorEx, test_multithreading, "$Id$") +ACE_RCSID(WFMO_Reactor, test_multithreading, "$Id$") static int concurrent_threads = 1; static int number_of_handles = ACE_Reactor::instance ()->size (); @@ -40,9 +40,9 @@ static void print_usage_and_die (void) { ACE_DEBUG ((LM_DEBUG, - "usage: \n\t" - "[-t (# of threads - default 1)] \n\t" - "[-h (# of handlers) - default 62] \n\t" + "usage: \n\t" + "[-t (# of threads - default 1)] \n\t" + "[-h (# of handlers) - default 62] \n\t" "[-i (# time interval between signals) - default 2] \n\t" "[-s (# of handles to signal) - default 1] \n\t" "[-e (# of iterations) - default 10] \n\t")); @@ -60,23 +60,23 @@ parse_args (int argc, char **argv) switch (c) { case 't': - concurrent_threads = atoi (get_opt.optarg); - break; + concurrent_threads = atoi (get_opt.optarg); + break; case 'e': - iterations = atoi (get_opt.optarg); - break; + iterations = atoi (get_opt.optarg); + break; case 'h': - number_of_handles = atoi (get_opt.optarg); - break; + number_of_handles = atoi (get_opt.optarg); + break; case 'i': - interval = atoi (get_opt.optarg); - break; + interval = atoi (get_opt.optarg); + break; case 's': - number_of_handles_to_signal = atoi (get_opt.optarg); - break; + number_of_handles_to_signal = atoi (get_opt.optarg); + break; default: - print_usage_and_die (); - break; + print_usage_and_die (); + break; } } @@ -84,21 +84,21 @@ class Task_Handler : public ACE_Task<ACE_NULL_SYNCH> { public: Task_Handler (size_t number_of_handles, - size_t concurrent_threads); + size_t concurrent_threads); // Constructor. ~Task_Handler (void); // Destructor. virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); // Called when object is removed from the ACE_Reactor int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); // Handle events being signaled by the main thread. virtual int handle_timeout (const ACE_Time_Value &tv, - const void *arg = 0); + const void *arg = 0); // Called when timer expires. int svc (void); @@ -122,7 +122,7 @@ Task_Handler::svc (void) } Task_Handler::Task_Handler (size_t number_of_handles, - size_t concurrent_threads) + size_t concurrent_threads) { ACE_NEW (this->events_, ACE_Auto_Event [number_of_handles]); @@ -136,9 +136,9 @@ Task_Handler::Task_Handler (size_t number_of_handles, // Make us an active object. if (this->activate (THR_NEW_LWP, - concurrent_threads) == -1) + concurrent_threads) == -1) ACE_ERROR ((LM_ERROR, "%p\t cannot activate task\n", - "activate")); + "activate")); } Task_Handler::~Task_Handler (void) @@ -154,38 +154,38 @@ Task_Handler::handle_signal (int signum, siginfo_t *siginfo, ucontext_t *) // This will force Reactor to update its internal handle tables if (ACE_Reactor::instance ()->remove_handler (siginfo->si_handle_, - ACE_Event_Handler::DONT_CALL) == -1) + ACE_Event_Handler::DONT_CALL) == -1) return -1; // ACE_ERROR_RETURN ((LM_ERROR, - // "(%t) %p\tTask cannot be unregistered from Reactor: handle value = %d\n", - // "Task_Handler::handle_signal", - // siginfo->si_handle_), -1); + // "(%t) %p\tTask cannot be unregistered from Reactor: handle value = %d\n", + // "Task_Handler::handle_signal", + // siginfo->si_handle_), -1); if (ACE_Reactor::instance ()->register_handler (this, - siginfo->si_handle_) == -1) + siginfo->si_handle_) == -1) return -1; // ACE_ERROR_RETURN ((LM_ERROR, - // "(%t) %p\tTask cannot be registered with Reactor: handle value = %d\n", - // "Task_Handler::handle_signal", - // siginfo->si_handle_), -1); + // "(%t) %p\tTask cannot be registered with Reactor: handle value = %d\n", + // "Task_Handler::handle_signal", + // siginfo->si_handle_), -1); return 0; } int Task_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "(%t) handle_close() called: handle value = %d\n", - handle)); + handle)); return 0; } int Task_Handler::handle_timeout (const ACE_Time_Value &tv, - const void *arg) + const void *arg) { ACE_DEBUG ((LM_DEBUG, "(%t) handle_timeout() called: iteration value = %d\n", - int (arg))); + int (arg))); return 0; } @@ -200,7 +200,7 @@ main (int argc, char **argv) { parse_args (argc, argv); Task_Handler task (number_of_handles, - concurrent_threads); + concurrent_threads); ACE_OS::srand (ACE_OS::time (0L)); @@ -212,19 +212,19 @@ main (int argc, char **argv) // Randomly generate events ACE_DEBUG ((LM_DEBUG, "********************************************************\n")); ACE_DEBUG ((LM_DEBUG, "(%t -- main thread) signaling %d events : iteration = %d\n", - number_of_handles_to_signal, - i)); + number_of_handles_to_signal, + i)); ACE_DEBUG ((LM_DEBUG, "********************************************************\n")); // Setup a timer for the task if (ACE_Reactor::instance ()->schedule_timer (&task, - (void *) i, - 0) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1); + (void *) i, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1); for (int i = 0; i < number_of_handles_to_signal; i++) - // Randomly select a handle to signal. - task.signal (ACE_OS::rand() % number_of_handles); + // Randomly select a handle to signal. + task.signal (ACE_OS::rand() % number_of_handles); } // Sleep for a while diff --git a/examples/Reactor/WFMO_Reactor/test_network_events.cpp b/examples/Reactor/WFMO_Reactor/test_network_events.cpp index 69f733d9d70..3f3c7fdcd20 100644 --- a/examples/Reactor/WFMO_Reactor/test_network_events.cpp +++ b/examples/Reactor/WFMO_Reactor/test_network_events.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_network_events.cpp // @@ -20,15 +20,15 @@ // the remote side shuts down. Multiple clients can connect at the // same time. // -// Events tested in this example includes ACCEPT, READ, and CLOSE masks. +// Events tested in this example includes ACCEPT, READ, and CLOSE masks. // // To run this example, start an instance of this example and // connect to it using telnet (to port -// ACE_DEFAULT_SERVER_PORT(10002)). +// ACE_DEFAULT_SERVER_PORT(10002)). // // = AUTHOR // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" @@ -37,7 +37,7 @@ #include "ace/SOCK_Stream.h" #include "ace/SOCK_Acceptor.h" -ACE_RCSID(ReactorEx, test_network_events, "$Id$") +ACE_RCSID(WFMO_Reactor, test_network_events, "$Id$") class Network_Handler : public ACE_Event_Handler { @@ -47,7 +47,7 @@ public: virtual int handle_input (ACE_HANDLE handle); virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); virtual ACE_HANDLE get_handle (void) const; ACE_SOCK_Stream stream_; @@ -63,7 +63,7 @@ Network_Handler::Network_Handler (ACE_SOCK_Stream &s) ACE_ASSERT (result == 0); } -ACE_HANDLE +ACE_HANDLE Network_Handler::get_handle (void) const { return this->stream_.get_handle (); @@ -102,11 +102,11 @@ Network_Handler::handle_input (ACE_HANDLE handle) int Network_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Network_Handler::handle_close handle = %d\n", handle)); - this->stream_.close (); + this->stream_.close (); delete this; return 0; } @@ -121,7 +121,7 @@ public: virtual int handle_input (ACE_HANDLE handle); virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); ACE_HANDLE get_handle (void) const; ACE_INET_Addr local_address_; @@ -133,7 +133,7 @@ Network_Listener::Network_Listener (void) acceptor_ (local_address_, 1) { this->reactor (ACE_Reactor::instance ()); - int result = this->reactor ()->register_handler (this, + int result = this->reactor ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK); ACE_ASSERT (result == 0); } @@ -145,7 +145,7 @@ Network_Listener::~Network_Listener (void) this->handle_close (this->get_handle (), ACE_Event_Handler::ALL_EVENTS_MASK); } -ACE_HANDLE +ACE_HANDLE Network_Listener::get_handle (void) const { return this->acceptor_.get_handle (); @@ -178,13 +178,13 @@ Network_Listener::handle_input (ACE_HANDLE handle) Network_Handler *handler; ACE_NEW_RETURN (handler, Network_Handler (stream), -1); - + return 0; } int Network_Listener::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Network_Listener::handle_close handle = %d\n", handle)); @@ -192,9 +192,9 @@ Network_Listener::handle_close (ACE_HANDLE handle, return 0; } -int +int main (int, char *[]) -{ +{ Network_Listener listener; ACE_Reactor::run_event_loop (); diff --git a/examples/Reactor/WFMO_Reactor/test_prerun_state_changes.cpp b/examples/Reactor/WFMO_Reactor/test_prerun_state_changes.cpp index 7438869a844..fb880b8c8ee 100644 --- a/examples/Reactor/WFMO_Reactor/test_prerun_state_changes.cpp +++ b/examples/Reactor/WFMO_Reactor/test_prerun_state_changes.cpp @@ -21,7 +21,7 @@ #include "ace/Reactor.h" -ACE_RCSID(ReactorEx, test_prerun_state_changes, "$Id$") +ACE_RCSID(WFMO_Reactor, test_prerun_state_changes, "$Id$") class Event_Handler : public ACE_Event_Handler // = TITLE diff --git a/examples/Reactor/WFMO_Reactor/test_registration.cpp b/examples/Reactor/WFMO_Reactor/test_registration.cpp index c6c5f5d9e5d..6409efc2749 100644 --- a/examples/Reactor/WFMO_Reactor/test_registration.cpp +++ b/examples/Reactor/WFMO_Reactor/test_registration.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_registration.cpp // @@ -30,12 +30,12 @@ // // = AUTHOR // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" -ACE_RCSID(ReactorEx, test_registration, "$Id$") +ACE_RCSID(WFMO_Reactor, test_registration, "$Id$") // Globals for this test int stop_test = 0; @@ -50,7 +50,7 @@ public: virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); virtual int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); ACE_Auto_Event event1_; ACE_Auto_Event event2_; @@ -64,7 +64,7 @@ Simple_Handler::Simple_Handler (void) { } -int +int Simple_Handler::handle_signal (int signum, siginfo_t *s, ucontext_t *) { ACE_HANDLE handle = s->si_handle_; @@ -90,12 +90,12 @@ Simple_Handler::handle_signal (int signum, siginfo_t *s, ucontext_t *) int Simple_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Simple_Handler::handle_close handle = %d\n", handle)); this->handle_close_count_++; - if (this->handle_close_count_ == 1) + if (this->handle_close_count_ == 1) stop_test = 0; else if (this->handle_close_count_ == 2) stop_test = 1; @@ -106,7 +106,7 @@ Simple_Handler::handle_close (ACE_HANDLE handle, // Globals for this test Simple_Handler simple_handler; -void +void worker (void) { ACE_DEBUG ((LM_DEBUG, "(%t) Thread creation\n")); @@ -132,20 +132,20 @@ worker (void) ACE_DEBUG ((LM_DEBUG, "(%t) Thread death\n")); } -int +int main (int, char *[]) { - int result = reactor.register_handler (&simple_handler, + int result = reactor.register_handler (&simple_handler, simple_handler.event1_.handle ()); ACE_ASSERT (result == 0); - result = reactor.register_handler (&simple_handler, + result = reactor.register_handler (&simple_handler, simple_handler.event2_.handle ()); ACE_ASSERT (result == 0); result = ACE_OS::thr_create ((ACE_THR_FUNC) worker, 0, 0, 0); ACE_ASSERT (result == 0); - + result = 0; while (!stop_test && result != -1) { diff --git a/examples/Reactor/WFMO_Reactor/test_registry_changes.cpp b/examples/Reactor/WFMO_Reactor/test_registry_changes.cpp index e7339e73c19..1dd25680a1f 100644 --- a/examples/Reactor/WFMO_Reactor/test_registry_changes.cpp +++ b/examples/Reactor/WFMO_Reactor/test_registry_changes.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_registry_changes.cpp // @@ -15,13 +15,13 @@ // // = AUTHOR // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" #include "ace/Registry.h" -ACE_RCSID(ReactorEx, test_registry_changes, "$Id$") +ACE_RCSID(WFMO_Reactor, test_registry_changes, "$Id$") static int stop_test = 0; static HKEY context_to_monitor = HKEY_CURRENT_USER; @@ -32,11 +32,11 @@ class Event_Handler : public ACE_Event_Handler public: Event_Handler (ACE_Reactor &reactor); ~Event_Handler (void); - int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); + int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); + ACE_Reactor_Mask close_mask); ACE_Registry::Naming_Context &context (void); - + private: ACE_Auto_Event event_; ACE_Registry::Naming_Context context_; @@ -46,43 +46,43 @@ Event_Handler::Event_Handler (ACE_Reactor &reactor) : context_ (context_to_monitor) { this->reactor (&reactor); - - if (::RegNotifyChangeKeyValue (this->context_.key (), // handle of key to watch - FALSE, // flag for subkey notification - REG_NOTIFY_CHANGE_NAME, // changes to be reported - this->event_.handle (), // handle of signaled event - TRUE // flag for asynchronous reporting - ) != ERROR_SUCCESS) + + if (::RegNotifyChangeKeyValue (this->context_.key (), // handle of key to watch + FALSE, // flag for subkey notification + REG_NOTIFY_CHANGE_NAME, // changes to be reported + this->event_.handle (), // handle of signaled event + TRUE // flag for asynchronous reporting + ) != ERROR_SUCCESS) ACE_ERROR ((LM_ERROR, "RegNotifyChangeKeyValue could not be setup\n")); - + if (this->reactor ()->register_handler (this, - this->event_.handle ()) != 0) - ACE_ERROR ((LM_ERROR, "Registration with Reactor could not be done\n")); + this->event_.handle ()) != 0) + ACE_ERROR ((LM_ERROR, "Registration with Reactor could not be done\n")); } Event_Handler::~Event_Handler (void) { } -int +int Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) { if (stop_test) this->reactor ()->close (); - else if (::RegNotifyChangeKeyValue (this->context_.key (), // handle of key to watch - FALSE, // flag for subkey notification - REG_NOTIFY_CHANGE_NAME, // changes to be reported - this->event_.handle (), // handle of signaled event - TRUE // flag for asynchronous reporting - ) != ERROR_SUCCESS) + else if (::RegNotifyChangeKeyValue (this->context_.key (), // handle of key to watch + FALSE, // flag for subkey notification + REG_NOTIFY_CHANGE_NAME, // changes to be reported + this->event_.handle (), // handle of signaled event + TRUE // flag for asynchronous reporting + ) != ERROR_SUCCESS) ACE_ERROR ((LM_ERROR, "RegNotifyChangeKeyValue could not be setup\n")); return 0; } -int +int Event_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask) + ACE_Reactor_Mask close_mask) { ACE_DEBUG ((LM_DEBUG, "Event_Handler removed from Reactor\n")); return 0; @@ -94,7 +94,7 @@ Event_Handler::context (void) return this->context_; } -void +void worker (Event_Handler *event_handler) { ACE_DEBUG ((LM_DEBUG, "(%t) Thread creation\n")); @@ -102,15 +102,15 @@ worker (Event_Handler *event_handler) ACE_Registry::Naming_Context temp_context; int result = event_handler->context ().bind_new_context (temp_context_name, - temp_context); - + temp_context); + if (result == -1) - ACE_ERROR ((LM_ERROR, "Error in creating %s: %p\n", temp_context_name, "bind_new_context")); + ACE_ERROR ((LM_ERROR, "Error in creating %s: %p\n", temp_context_name, "bind_new_context")); else { ACE_DEBUG ((LM_DEBUG, "(%t) Thread sleeping\n")); ACE_OS::sleep (3); - + ACE_DEBUG ((LM_DEBUG, "(%t) Thread removing registry entry\n")); stop_test = 1; event_handler->context ().unbind_context (temp_context_name); diff --git a/examples/Reactor/WFMO_Reactor/test_removals.cpp b/examples/Reactor/WFMO_Reactor/test_removals.cpp index 2a826fb7d3f..1c4b4acf687 100644 --- a/examples/Reactor/WFMO_Reactor/test_removals.cpp +++ b/examples/Reactor/WFMO_Reactor/test_removals.cpp @@ -24,7 +24,7 @@ #include "ace/Service_Config.h" #include "ace/Synch.h" -ACE_RCSID(ReactorEx, test_removals, "$Id$") +ACE_RCSID(WFMO_Reactor, test_removals, "$Id$") class Event_Handler : public ACE_Event_Handler // = TITLE @@ -37,22 +37,22 @@ class Event_Handler : public ACE_Event_Handler { public: Event_Handler (int event_number, - int close_down) + int close_down) : event_number_ (event_number), close_down_ (close_down) { if (ACE_Reactor::instance ()->register_handler (this, - this->event_.handle ()) == -1) - ACE_ERROR ((LM_ERROR, "%p\tevent handler %d cannot be added to Reactor\n", "", event_number_)); + this->event_.handle ()) == -1) + ACE_ERROR ((LM_ERROR, "%p\tevent handler %d cannot be added to Reactor\n", "", event_number_)); this->event_.signal (); } virtual int handle_signal (int index, siginfo_t *, ucontext_t *) { if (this->close_down_) - return -1; + return -1; else - return 0; + return 0; } virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) @@ -92,12 +92,12 @@ main (int argc, char *argv[]) { result = ACE_Reactor::instance ()->handle_events (time); if (result == 0 && errno == ETIME) - { - ACE_DEBUG ((LM_DEBUG, "No more work left: timing out\n")); - break; - } + { + ACE_DEBUG ((LM_DEBUG, "No more work left: timing out\n")); + break; + } if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); + ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); } return 0; } diff --git a/examples/Reactor/WFMO_Reactor/test_talker.cpp b/examples/Reactor/WFMO_Reactor/test_talker.cpp index 83eedf58c97..0a52bf3ea9e 100644 --- a/examples/Reactor/WFMO_Reactor/test_talker.cpp +++ b/examples/Reactor/WFMO_Reactor/test_talker.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_talker.cpp // @@ -15,13 +15,13 @@ // ^C events, reading from STDIN, vanilla Win32 events, thread // exits, Reactor notifications, proactive reads, and proactive // writes. -// +// // The proactive I/O events are demultiplexed by the ACE_Proactor. // The thread exits, notications, and vanilla Win32 events are // demultiplexed by the ACE_Reactor. To enable a single thread // to run all these events, the Proactor is integrated with the // Reactor. -// +// // The test application prototypes a simple talk program. Two // instances of the application connect. Input from either console // is displayed on the others console also. Because of the evils @@ -29,46 +29,46 @@ // To test the Proactor and Reactor, I/O between the remote // processes is performed proactively and interactions between the // STDIN thread and the main thread are performed reactively. -// +// // The following description of the test application is in two // parts. The participants section explains the main components // involved in the application. The collaboration section // describes how the partipants interact in response to the // multiple event types which occur. -// +// // The Reactor test application has the following participants: -// +// // . Reactor -- The Reactor demultiplexes Win32 "waitable" // events using WaitForMultipleObjects. -// +// // . Proactor -- The proactor initiates and demultiplexes // overlapped I/O operations. The Proactor registers with the // Reactor so that a single-thread can demultiplex all // application events. -// +// // . STDIN_Handler -- STDIN_Handler is an Active Object which reads // from STDIN and forwards the input to the Peer_Handler. This // runs in a separate thread to make the test more interesting. // However, STDIN is "waitable", so in general it can be waited on // by the ACE Reactor, thanks MicroSlush! -// +// // . Peer_Handler -- The Peer_Handler connects to another instance // of test_reactor. It Proactively reads and writes data to the // peer. When the STDIN_Handler gives it messages, it fowards them // to the remote peer. When it receives messages from the remote // peer, it prints the output to the console. -// +// // The collaborations of the participants are as follows: -// +// // . Initialization -// +// // Peer_Handler -- connects to the remote peer. It then begins // proactively reading from the remote connection. Note that it // will be notified by the Proactor when a read completes. It // also registers a notification strategy with message queue so // that it is notified when the STDIN_Handler posts a message // onto the queue. -// +// // STDIN_Handler -- STDIN_Handler registers a signal handler for // SIGINT. This just captures the exception so that the kernel // doesn't kill our process; We want to exit gracefully. It also @@ -76,29 +76,29 @@ // STDIN_Handler's thread handle with the Reactor. The // Exit_Hook will get called back when the STDIN_Handler thread // exits. After registering these, it blocks reading from STDIN. -// +// // Proactor -- is registered with the Reactor. -// +// // The main thread of control waits in the Reactor. -// +// // . STDIN events -- When the STDIN_Handler thread reads from // STDIN, it puts the message on Peer_Handler's message queue. It // then returns to reading from STDIN. -// +// // . Message enqueue -- The Reactor thread wakes up and calls // Peer_Handler::handle_output. The Peer_Handler then tries to // dequeue a message from its message queue. If it can, the // message is Proactively sent to the remote peer. Note that the // Peer_Handler will be notified with this operation is complete. // The Peer_Handler then falls back into the Reactor event loop. -// +// // . Send complete event -- When a proactive send is complete, the // Proactor is notified by the Reactor. The Proactor, in turn, // notifies the Peer_Handler. The Peer_Handler then checks for // more messages from the message queue. If there are any, it // tries to send them. If there are not, it returns to the -// Reactor event loop. -// +// Reactor event loop. +// // . Read complete event -- When a proactive read is complete (the // Peer_Handler initiated a proactive read when it connected to the // remote peer), the Proactor is notified by the Reactor. The @@ -108,18 +108,18 @@ // connection. If the read failed (i.e. the remote peer exited), // the Peer_Handler sets a flag to end the event loop and returns. // This will cause the application to exit. -// +// // . ^C events -- When the user types ^C at the console, the // STDIN_Handler's signal handler will be called. It does nothing, // but as a result of the signal, the STDIN_Handler thread will // exit. -// +// // . STDIN_Handler thread exits -- The Exit_Hook will get called // back from the Reactor. Exit_Hook::handle_signal sets a flag // to end the event loop and returns. This will cause the // application to exit. -// -// +// +// // To run example, start an instance of the test with an optional // local port argument (as the acceptor). Start the other instance // with -h <hostname> and -p <server port>. Type in either the @@ -127,9 +127,9 @@ // other window. Control C to exit. // // = AUTHOR -// Tim Harrison +// Tim Harrison // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" @@ -142,13 +142,13 @@ #include "ace/Synch.h" #include "ace/Task.h" -ACE_RCSID(ReactorEx, test_talker, "$Id$") +ACE_RCSID(WFMO_Reactor, test_talker, "$Id$") typedef ACE_Task<ACE_MT_SYNCH> MT_TASK; class Peer_Handler : public MT_TASK, public ACE_Handler // = TITLE -// Connect to a server. Receive messages from STDIN_Handler +// Connect to a server. Receive messages from STDIN_Handler // and forward them to the server using proactive I/O. { public: @@ -162,13 +162,13 @@ public: // hostname was specified from the command line. virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result); - // This method will be called when an asynchronous read completes on a stream. + // This method will be called when an asynchronous read completes on a stream. // The remote peer has sent us something. If it succeeded, print // out the message and reinitiate a read. Otherwise, fail. In both // cases, delete the message sent. virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result); - // This method will be called when an asynchronous write completes on a strea_m. + // This method will be called when an asynchronous write completes on a strea_m. // One of our asynchronous writes to the remote peer has completed. // Make sure it succeeded and then delete the message. @@ -250,9 +250,9 @@ private: Peer_Handler::Peer_Handler (int argc, char *argv[]) : host_ (0), port_ (ACE_DEFAULT_SERVER_PORT), - strategy_ (ACE_Reactor::instance (), - this, - ACE_Event_Handler::WRITE_MASK), + strategy_ (ACE_Reactor::instance (), + this, + ACE_Event_Handler::WRITE_MASK), mb_ (BUFSIZ) { // This code sets up the message to notify us when a new message is @@ -266,14 +266,14 @@ Peer_Handler::Peer_Handler (int argc, char *argv[]) while ((c = get_opt ()) != EOF) { switch (c) - { - case 'h': - host_ = get_opt.optarg; - break; - case 'p': - port_ = ACE_OS::atoi (get_opt.optarg); - break; - } + { + case 'h': + host_ = get_opt.optarg; + break; + case 'p': + port_ = ACE_OS::atoi (get_opt.optarg); + break; + } } } @@ -285,7 +285,7 @@ Peer_Handler::~Peer_Handler (void) // does blocking connects and accepts depending on whether a hostname // was specified from the command line. -int +int Peer_Handler::open (void *) { if (host_ != 0) // Connector @@ -295,7 +295,7 @@ Peer_Handler::open (void *) // Establish connection with server. if (connector.connect (stream_, addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connect"), -1); + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connect"), -1); ACE_DEBUG ((LM_DEBUG, "(%t) connected.\n")); } @@ -305,8 +305,8 @@ Peer_Handler::open (void *) ACE_INET_Addr local_addr (port_); if ((acceptor.open (local_addr) == -1) || - (acceptor.accept (this->stream_) == -1)) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "accept failed"), -1); + (acceptor.accept (this->stream_) == -1)) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "accept failed"), -1); ACE_DEBUG ((LM_DEBUG, "(%t) accepted.\n")); } @@ -314,26 +314,26 @@ Peer_Handler::open (void *) int result = this->rd_stream_.open (*this); if (result != 0) return result; - + result = this->wr_stream_.open (*this); if (result != 0) return result; result = this->rd_stream_.read (this->mb_, - this->mb_.size ()); - return result; + this->mb_.size ()); + return result; } // One of our asynchronous writes to the remote peer has completed. // Make sure it succeeded and then delete the message. -void +void Peer_Handler::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) { if (result.bytes_transferred () <= 0) ACE_DEBUG ((LM_DEBUG, "(%t) %p bytes = %d\n", "Message failed", - result.bytes_transferred ())); - + result.bytes_transferred ())); + // This was allocated by the STDIN_Handler, queued, dequeued, passed // to the proactor, and now passed back to us. result.message_block ().release (); @@ -343,11 +343,11 @@ Peer_Handler::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result // out the message and reinitiate a read. Otherwise, fail. In both // cases, delete the message sent. - -void + +void Peer_Handler::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) { - if (result.bytes_transferred () > 0 && + if (result.bytes_transferred () > 0 && this->mb_.length () > 0) { this->mb_.rd_ptr ()[result.bytes_transferred ()] = '\0'; @@ -363,24 +363,24 @@ Peer_Handler::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) return; } - // Reset pointers + // Reset pointers this->mb_.wr_ptr (this->mb_.wr_ptr () - result.bytes_transferred ()); // Start off another read if (this->rd_stream_.read (this->mb_, - this->mb_.size ()) == -1) + this->mb_.size ()) == -1) ACE_ERROR ((LM_ERROR, "%p Read initiate.\n", "Peer_Handler")); } // This is so the Proactor can get our handle. -ACE_HANDLE +ACE_HANDLE Peer_Handler::handle (void) const { return this->stream_.get_handle (); } // We've been removed from the Reactor. -int +int Peer_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) { ACE_DEBUG ((LM_DEBUG, "(%t) Peer_Handler closing down\n")); @@ -388,7 +388,7 @@ Peer_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) } // New stuff added to the message queue. Try to dequeue a message. -int +int Peer_Handler::handle_output (ACE_HANDLE fd) { ACE_Message_Block *mb; @@ -399,13 +399,13 @@ Peer_Handler::handle_output (ACE_HANDLE fd) if (this->getq (mb, &tv) != -1) { if (this->wr_stream_.write (*mb, - mb->length ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p Write initiate.\n", "Peer_Handler"), -1); + mb->length ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p Write initiate.\n", "Peer_Handler"), -1); } return 0; } -void +void STDIN_Handler::handler (int signum) { ACE_DEBUG ((LM_DEBUG, "(%t) signal = %S\n", signum)); @@ -435,7 +435,7 @@ STDIN_Handler::open (void *) // Shut down. -int +int STDIN_Handler::close (u_long) { ACE_DEBUG ((LM_DEBUG, "(%t) thread is exiting.\n")); @@ -444,38 +444,38 @@ STDIN_Handler::close (u_long) // Thread runs here. -int +int STDIN_Handler::svc (void) { this->register_thread_exit_hook (); - + for (;;) { ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ); // Read from stdin into mb. - int read_result = ACE_OS::read (ACE_STDIN, - mb->rd_ptr (), - mb->size ()); + int read_result = ACE_OS::read (ACE_STDIN, + mb->rd_ptr (), + mb->size ()); // If read succeeds, put mb to peer handler, else end the loop. if (read_result > 0) - { - mb->wr_ptr (read_result); - // Note that this call will first enqueue mb onto the peer - // handler's message queue, which will then turn around and - // notify the Reactor via the Notification_Strategy. This - // will subsequently signal the Peer_Handler, which will - // react by calling back to its handle_output() method, - // which dequeues the message and sends it to the peer - // across the network. - this->ph_.putq (mb); - } - else - { - mb->release (); - break; - } + { + mb->wr_ptr (read_result); + // Note that this call will first enqueue mb onto the peer + // handler's message queue, which will then turn around and + // notify the Reactor via the Notification_Strategy. This + // will subsequently signal the Peer_Handler, which will + // react by calling back to its handle_output() method, + // which dequeues the message and sends it to the peer + // across the network. + this->ph_.putq (mb); + } + else + { + mb->release (); + break; + } } // handle_signal will get called on the main proactor thread since @@ -483,7 +483,7 @@ STDIN_Handler::svc (void) return 0; } -// Register an exit hook with the reactor. +// Register an exit hook with the reactor. void STDIN_Handler::register_thread_exit_hook (void) @@ -501,7 +501,7 @@ STDIN_Handler::register_thread_exit_hook (void) // The STDIN thread has exited. This means the user hit ^C. We can // end the event loop and delete ourself. -int +int STDIN_Handler::handle_signal (int, siginfo_t *si, ucontext_t *) { ACE_ASSERT (this->thr_handle_ == si->si_handle_); @@ -525,34 +525,34 @@ main (int argc, char *argv[]) Peer_Handler peer_handler (argc, argv); if (peer_handler.open () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p open failed, errno = %d.\n", - "peer_handler", errno), 0); + ACE_ERROR_RETURN ((LM_ERROR, + "%p open failed, errno = %d.\n", + "peer_handler", errno), 0); // Open active object for reading from stdin. STDIN_Handler stdin_handler (peer_handler); // Spawn thread. if (stdin_handler.open () == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p open failed, errno = %d.\n", - "stdin_handler", errno), 0); + ACE_ERROR_RETURN ((LM_ERROR, + "%p open failed, errno = %d.\n", + "stdin_handler", errno), 0); // Register proactor with Reactor so that we can demultiplex // "waitable" events and I/O operations from a single thread. - if (ACE_Reactor::instance ()->register_handler + if (ACE_Reactor::instance ()->register_handler (ACE_Proactor::instance ()->implementation ()) != 0) ACE_ERROR_RETURN ((LM_ERROR, "%p failed to register Proactor.\n", - argv[0]), -1); + argv[0]), -1); // Run main event demultiplexor. ACE_Reactor::run_event_loop (); // Remove proactor with Reactor. - if (ACE_Reactor::instance ()->remove_handler + if (ACE_Reactor::instance ()->remove_handler (ACE_Proactor::instance (), ACE_Event_Handler::DONT_CALL) != 0) ACE_ERROR_RETURN ((LM_ERROR, "%p failed to register Proactor.\n", - argv[0]), -1); + argv[0]), -1); return 0; } diff --git a/examples/Reactor/WFMO_Reactor/test_timeouts.cpp b/examples/Reactor/WFMO_Reactor/test_timeouts.cpp index d23a55aa089..8fa41f46a66 100644 --- a/examples/Reactor/WFMO_Reactor/test_timeouts.cpp +++ b/examples/Reactor/WFMO_Reactor/test_timeouts.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_timeouts.cpp // @@ -14,21 +14,21 @@ // loops that handle events for some fixed amount of time. // // Run this example (without arguments) to see the timers -// expire. The order should be: -// +// expire. The order should be: +// // foo, bar, foo, bar, foo, foo, bar, foo, bar, foo // // = AUTHOR // Tim Harrison // Irfan Pyarali -// +// // ============================================================================ #include "ace/Reactor.h" #include "ace/Service_Config.h" #include "ace/OS.h" -ACE_RCSID(ReactorEx, test_timeouts, "$Id$") +ACE_RCSID(WFMO_Reactor, test_timeouts, "$Id$") class Timeout_Handler : public ACE_Event_Handler // = TITLE @@ -39,13 +39,13 @@ public: : count_ (0) {} virtual int handle_timeout (const ACE_Time_Value &tv, - const void *arg) + const void *arg) // Print out when timeouts occur. { - ACE_DEBUG ((LM_DEBUG, - "%d timeout occurred for %s.\n", - ++count_, - (char *) arg)); + ACE_DEBUG ((LM_DEBUG, + "%d timeout occurred for %s.\n", + ++count_, + (char *) arg)); return 0; } @@ -61,20 +61,20 @@ main (int, char *[]) // Register a 3 second timer. ACE_Time_Value bar_tv (3); ACE_Reactor::instance ()->schedule_timer (&handler, - (void *) "Bar", - bar_tv, - bar_tv); + (void *) "Bar", + bar_tv, + bar_tv); // Register a 2 second timer. ACE_Time_Value foo_tv (2); ACE_Reactor::instance ()->schedule_timer (&handler, - (void *) "Foo", - foo_tv, - foo_tv); + (void *) "Foo", + foo_tv, + foo_tv); // Handle events for 12 seconds. ACE_Time_Value run_time (12); if (ACE_Reactor::run_event_loop(run_time) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); - + return 0; } diff --git a/examples/Reactor/WFMO_Reactor/test_window_messages.cpp b/examples/Reactor/WFMO_Reactor/test_window_messages.cpp index c911f0bed87..97adf78b460 100644 --- a/examples/Reactor/WFMO_Reactor/test_window_messages.cpp +++ b/examples/Reactor/WFMO_Reactor/test_window_messages.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_window_messages.cpp // @@ -12,40 +12,40 @@ // // Tests the Msg_WFMO_Reactor's ability to handle regular events // and window messages. -// +// // = AUTHOR -// +// // Irfan Pyarali -// +// // ============================================================================ #include "ace/Msg_WFMO_Reactor.h" #include "ace/Auto_Ptr.h" -ACE_RCSID(ReactorEx, test_window_messages, "$Id$") +ACE_RCSID(WFMO_Reactor, test_window_messages, "$Id$") class Event_Handler : public ACE_Event_Handler { public: - int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); + int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); ACE_Auto_Event handle_; int iterations_; }; -int +int Event_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) { --this->iterations_; if (this->iterations_ == 0) - ACE_Reactor::end_event_loop (); + ACE_Reactor::end_event_loop (); return 0; } Event_Handler event_handler; - + void WINAPI timer_callback (HWND hwnd, UINT uMsg, @@ -57,7 +57,7 @@ timer_callback (HWND hwnd, event_handler.handle_.signal (); } -int +int main (int argc, char** argv) { // Manage memory automagically. @@ -68,20 +68,19 @@ main (int argc, char** argv) auto_ptr<ACE_Reactor_Impl> delete_impl (impl); event_handler.iterations_ = 5; - int result = ACE_Reactor::instance ()->register_handler (&event_handler, + int result = ACE_Reactor::instance ()->register_handler (&event_handler, event_handler.handle_.handle ()); ACE_ASSERT (result == 0); - + ACE_Time_Value timeout (1); - result = ::SetTimer (NULL, // handle of window for timer messages - NULL, // timer identifier - timeout.msec (), // time-out value - (TIMERPROC) &timer_callback // address of timer procedure + result = ::SetTimer (NULL, // handle of window for timer messages + NULL, // timer identifier + timeout.msec (), // time-out value + (TIMERPROC) &timer_callback // address of timer procedure ); ACE_ASSERT (result != 0); - + ACE_Reactor::run_event_loop (); return 0; } - |