diff options
author | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-27 23:50:50 +0000 |
---|---|---|
committer | nobody <nobody@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-27 23:50:50 +0000 |
commit | 06077ebe682cd629408ecd3ba99ba86a1079b741 (patch) | |
tree | 282621b3af2a1cab8ac518c0e37c7d4f7785ab8a | |
parent | 4724472890257ce375ebbf51bc57548face5d8a9 (diff) | |
download | ATCD-06077ebe682cd629408ecd3ba99ba86a1079b741.tar.gz |
This commit was manufactured by cvs2svn to create branch 'ACE-4_2'.
164 files changed, 1409 insertions, 13037 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a index d0bdd281964..50e89471d5d 100644 --- a/ChangeLog-97a +++ b/ChangeLog-97a @@ -1,277 +1,3 @@ -Tue May 27 18:26:51 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> - - * ace/config-hpux-10.x-decthreads.h: Added support for HP/UX 10.10 - with DCE threads. Thanks to Shankar Krishnamoorthy - <kshankar@lucent.com> for these fixes. - - * ace/Local_Tokens_T.h: #if def'd out all of this file since it - doesn't seem to be used anymore. Thanks to Shankar - Krishnamoorthy <kshankar@lucent.com> for reporting this. - - * ace/Makefile (TEMPLATE_FILES): Removed Local_Tokens_T since it - doesn't appear to be used anywhere. - -Tue May 27 18:47:34 1997 James C Hu <jxh@lambada.cs.wustl.edu> - - * tests/*.cpp: Various changes for EBCIDIC compatibility. - Thanks to Chuck Gehr for pointing out the need for this! - - * tests/test_config.h: Added ACE_ALPHABET to aid a-z sending and - comparing. - -Tue May 27 15:03:25 1997 David L. Levine <levine@cs.wustl.edu> - - * tests/Future_Test.cpp: added ACE_Future{_Rep}<int> template - specializations. - -Tue May 27 07:49:03 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> - - * ace/Future.cpp: Made a few minor reformatting changes to Per's - new Future enhancements. - -Tue May 27 14:19:14 1997 Per Andersson <Per.Andersson@hfera.ericsson.se> - - * ace/Future: Fixed self assignment bug in ACE_Future<>::operator=(). - Fixed bug in ACE_Future<>::set(). It is now possible to do a - ACE_Future<>::set() followed by a ACE_Future<>::get() without - hanging forever. - - Moved all handling of the ACE_Future_Rep<> reference count - into three new static ACE_Future_Rep<> member functions, - create, attach, assign and detach. - - Removed one mutex from ACE_Future_Rep<> by changing the - reference count from an ACE_Atomic_Op<int> into a plain - int. The ACE_Future_Rep<>::value_ready_mutex_ mutex is - instead used for serializing changes to the reference count. - (ACE_Future_Rep<>::attach, ACE_Future_Rep<>::detach()) - - Removed mutex from ACE_Future<> the serialization is - performed by the ACE_Future_Rep<>::attach, - ACE_Future_Rep<>::detach() and ACE_Future_Rep<>::assign() - functions. - - Changed the ACE_Future<> default constructor to always - create a ACE_Future_Rep<> - - * tests/Future_Test.cpp: Added test case for - ACE_Future<>::set() followed by ACE_Future<>::get(). Added - test for working ACE_Future::operator=(). The test is not - fool proof but it crashes or hangs the test process with the - old ACE_Future<> implementation. - -Mon May 26 14:19:14 1997 James C Hu <jxh@polka.cs.wustl.edu> - - * ace/OS.{h,i}: Fixed difftime implementation for cases where - systems implement it as a macro. Fixed tempnam by adding - ACE_LACKS_TEMPNAM. - -Sun May 25 11:36:22 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> - - * examples/Reactor/Misc: Removed test_handle_set.cpp since it - is now completed subsumed by tests/Handle_Set_Test.cpp. - - * tests/Handle_Set_Test.cpp: Updated the test of - the ACE_Handle_Set so that it shows how fast the iterator works. - - * ace/Reactor.cpp: Updated the Reactor to use the new - ACE_Handle_Set_Iterator (whic no longer requires calling - operator++ to advance the iterator). - - * ace/Handle_Set: Rewrote the ACE_Handle_Set_Iterator to speed it up. - The result seems to be about 15% faster than the original. - - * ace/OS.h: Changed the MSB_MASK static constant into a macro and - moved it from Handle_Set.cpp into OS.h, changing its name to - ACE_MSB_MASK. - - * ace/Sched_Params.cpp (priority_max): Added another #ifdef for - Chorus. Thanks to Wei Chiang for reporting this. - - * include/makeinclude/platform_sunos5_sunc++_orbix.GNU: added -l - in front of orbixmt. Thanks to Wei Chiang for pointing this - out. - - * ace/ACE.cpp: Changed the default port for NT so that it starts - at 65279 rather than 65535. Hopefully, this will fix that - annoying bug that has been plaguing us on NT 4.0 for months. - Thanks to Goran Lowkrantz <Goran.Lowkrantz@Infologigruppen.se> - for reporting this. - -Sat May 24 23:42:32 1997 David L. Levine <levine@cs.wustl.edu> - - * performance-tests/Misc/test_naming.cpp (do_testing): replaced - strlen () calls in character array size with constant expression. - -Sat May 24 12:07:48 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> - - * Released version 4.2.1 for testing. - - * ace/Reactor.cpp (bind): Fixed a stupid typo where I was using - the ACE_REACTOR_EVENT_HANDLER macro instead of the - ACE_REACTOR_HANDLE macro. Thanks to Detlef for reporting this. - - * ace/OS.i: Added a new macro called ACE_HAS_THR_MINSTACK to deal - with weirdo mangling of names by Tandem. Thanks to Jan Perman - <uabjjpp@osd.ericsson.se> for reporting this. - - * ace/OS.h: Added a new macro ACE_LACKS_PRI_T for those platforms - using STHREADS (e.g., Tandem NonStop OS) that don't have pri_t - defined. Thanks to Jan Perman <uabjjpp@osd.ericsson.se> for - reporting this. - - * ace/Connector.cpp (connect): Make sure to save/restore errno - since svc_handler->close() may change it. Thanks to Michael - Hartman <c62nt57@ibx.com> for reporting this. - - * include/makeinclude/platform_chorus.GNU: Added a new platform - macros file for Chorus. Thanks to Wei Chang for this. - - * ace/OS.cpp (sched_params): Reordered the #ifdefs so that Chorus - comes first. - - * ace/OS.i (sleep): If the platform defines ACE_HAS_CLOCK_GETTIME - then we'll use the nanosleep() method rather than sleep(). - - * ace/OS.h: disabled THR_NEW_LWP for Chorus. Thanks to Wei Chang - for reporting this. - - * ace/Sched_Params.cpp: ACE_SCHED_OTHER and ACE_SCHED_RR have the - same value on Chorus. Thanks to Wei Chang for reporting this. - -Sat May 24 09:21:08 1997 David L. Levine <levine@cs.wustl.edu> - - * netsvcs/lib/Server_Logging_Handler.cpp: protected second - ACE_Svc_Handler specialization for case that ACE_HAS_THREADS, - when ACE_HAS_TLI. It had gotten lost in the last pass of - that module. Thanks to Sandro Doro <doros@aureus.sublink.org> - for reporting this problem. - -Sat May 24 03:19:38 1997 Nanbor Wang <nw1@dingo.wolfpack.cs.wustl.edu> - - * ace/OS.i (sigaddset, sigdelset, sigemptyset, sigfillset, - sigismember): Modified the implementation of these function so - as to conform with POSIX standard. Basically all functions do - the same things they did but more conservative protections are - added. The modified semantic becomes, - - sigemptyset, sigfillset, sigaddset, sigdelset: return 0 if - succeed, -1 otherwise. - sigismember: returns 0 if signum is not in the set, 1 if signum - is in the set, and -1 if error occurs. - - If error occured, errno will be set to one of the following - value: - EFAULT: sigset is not a valid address. - EINVAL: signum is not a valid signal number. - - Notice that, so far, this is for NT only. - -Sat May 24 01:53:22 1997 James C Hu <jxh@polka.cs.wustl.edu> - - * performance-tests/Misc/test_naming.cpp (do_testing): Thanks to - Sandro Doro, squashed a bug where we were trying to concatenate - onto a string constant. - -Fri May 23 01:01:01 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> - - * ace/config-hpux-9.x.h: Added - - #define ACE_HAS_BROKEN_ENUMS - #define ACE_HAS_IP_MULTICAST - #define ACE_LACKS_GETPGID - - Thanks to Neil Cohen for reporting these. - - * ace/Thread_Manager.h: Made the private methods and data members - protected so that subclasses can extend it. Thanks to Hamutal - Yanay for this suggestion. - -Fri May 23 21:27:05 1997 David L. Levine <levine@cs.wustl.edu> - - * ace/Process.{h,cpp} (env_argv): added "const" to char * type in - return type, for argument compatibility in call to ACE_OS::execve (). - - * ace/Process.cpp (spawn): removed unreachable return statement at - end of function. - - Thanks to Dave Mayerhoefer <mayerhoefer@svappl36.mdc.com> for - reporting the above two problems. - - * ace/{IOStream*,Makefile}: Split out templates into - ace/IOStream_T.{h,cpp} files. This way, automatic template - instantiation systems that require templates to be in separate - files, such as on Irix 6.2, will be able to build IOStream_Test - and the ACE_IOStream examples without warnings. (The - ACE_IOSTREAM_BUILDING_TEMPLATE macro that did this only worked - if ACE_TEMPLATES_REQUIRE_SOURCE was defined. It's no longer - needed with the separate template files.) - - * tests/IOStream_Test.cpp, - examples/IOStream/client/iostream_client.cpp, - examples/IOStream/server/iostream_server.cpp: - swapped ACE_Streambuf and ACE_Streambuf_T class names so that - the template class has the "_T". And renamed ACE_IOStream_T - for consistency. - - * ace/{IOStream.*,README}, - tests/IOStream_Test.cpp, - examples/IOStream/client/iostream_client.cpp, - examples/IOStream/server/iostream_server.cpp, - config-hpux-9.x*.h: - Added ACE_LACKS_ACE_IOSTREAM protection - so that these can easily be built on platforms that have - trouble with ACE_IOStream. - - * Priority_Task_Test.cpp: removed close () because it didn't really - close the Task, and added printout to main () after all tasks have - been spawned to help debug non-termination. - - * ace/OS.cpp: (thr_create, with STHREADS only): *thr_handle was - used but *thr_id had been set by ::thr_create, so threads never - got activated. Fixed by using *thr_id instead of *thr_handle - in the calls to ACE_OS::thr_setprio and ACE_OS::continue. - Thanks to Jan Perman <uabjjpp@osd.ericsson.se> for reporting - this problem. - -Fri May 23 20:12:33 1997 James C Hu <jxh@polka.cs.wustl.edu> - - * tests/SV_Shared_Memory_Test.cpp: Thanks to Chuck Gehr, fixed - ASCII dependent code in the parent and child routines. - -Fri May 23 02:58:28 1997 Nanbor Wang <nw1@siesta.cs.wustl.edu> - - * ace/OS.i (dlsym): Added ACE_USES_ASM_SYMBOL_IN_DLSYM, support - for platforms (FreeBSD) which use assembly symbols instead of C - symbols in dlsym (). - - * ace/config-freebsd[-pthread].h: Added flag ACE_HAS_CHARPTR_DL - and ACE_USES_ASM_SYMBOL_IN_DLSYM. - -Thu May 22 08:14:21 1997 David L. Levine <levine@cs.wustl.edu> - - * tests/Tokens_Test.cpp: added deletes to avoid memory leaks. - -Wed May 21 16:15:48 1997 David L. Levine <levine@cs.wustl.edu> - - * ace/{config-irix6.2*.h,README}: removed ACE_LACKS_IOSTREAM_SETGET - because tests won't build with it. Also, added - ACE_LACKS_SIGNED_CHAR. - - * ace/IOStream.h: removed "const" from PUT_PROT of - u_char * and void *. This should allow the IOStream test - and examples to build and run on Irix platforms. Thanks - to Torbjorn Lindgren <tl@funcom.com> and Amos Shapira - <amos@dsi.co.il> for reporting this, and to James Hu for - helping fix it. - - * ace/{OS.cpp,Sched_Params.cp} (Solaris only): use 0 min priority - again, with workaround in ACE_OS::thr_create to not use - ::pthread_attr_setschedparam () if the priority is 0. Instead, - the priority of the newly created thread is set to 0 (if it - wasn't created with 0) after the thread is created, with - ::pthread_setschedparam (). - Wed May 21 15:23:37 1997 Chris Cleeland <cleeland@cs.wustl.edu> * ace/Strategies_T.* (ACE_Hash_Addr): Eliminated the ADDR_T @@ -490,6 +490,7 @@ Scott Halstead <scott.halstead@gs.com> Jean-Marc Strauss <strauss@club-internet.fr> Adam Porter <aporter@cs.umd.edu> Hakan Kallberg <hk@simulina.se> +Carlos O'Ryan <coryan@mat.puc.cl> Eric Dean Russell <edrusse@somnet.sandia.gov> Daniel Montalibet <daniel_montalibet@stortek.com> Norbert Rapp <norbert.rapp@nexus-informatics.de> @@ -514,8 +515,6 @@ Satoshi Ueno <satoshi.ueno@gs.com> Eugene R. Somdahl <gene@endo.com> Robert Head <rhead@mail.virtc.com> Ivan Murphy <Ivan.Murphy@med.siemens.de> -Jan Perman <uabjjpp@osd.ericsson.se> -Shankar Krishnamoorthy <kshankar@lucent.com> I would particularly like to thank Paul Stephenson, who worked with me at Ericsson and is now at ObjectSpace. Paul devised the recursive diff --git a/STL/ACE_Changes b/STL/ACE_Changes deleted file mode 100644 index 902fb94c94c..00000000000 --- a/STL/ACE_Changes +++ /dev/null @@ -1,53 +0,0 @@ -This version of STL was obtained from -http://www.rahul.net/terris/. This is a modified version of the -implementation that comes with VC++4.0. Please see readme2.stl for -details. - -The following modification have been made for compilation with VC++4.x - -________________________________________ - -vector.h (line 85) -________________________________________ - - - /* - * This is cause the VC++ compiler sucks - * and does not recognize nested classes properly - * - */ -#if !defined (VC_PLUS_PLUS_NESTED_CLASS_PROBLEM) - vector(size_type n, const T& value = T()) { - start = static_allocator.allocate(n); - uninitialized_fill_n(start, n, value); - finish = start + n; - end_of_storage = finish; - } -#endif /* VC_PLUS_PLUS_NESTED_CLASS_PROBLEM */ - - -________________________________________ - -bstring.h (line 1102) -________________________________________ - - - /* - * This should be correctly scoped - * - * if (cap == ::reserve) - */ - - if (cap == std::reserve) - { - len = 0; - res = size; - ptr = new charT [res]; - } - /* - * This should be correctly scoped - * - * else if ((cap == ::default_size) && (size != NPOS)) - */ - - else if ((cap == std::default_size) && (size != NPOS)) diff --git a/STL/readme2.stl b/STL/readme2.stl deleted file mode 100644 index 5132bc1189b..00000000000 --- a/STL/readme2.stl +++ /dev/null @@ -1,272 +0,0 @@ -STL2.ZIP - -Standard Template Library for Visual C++ 4.0 -and Related Classes - -Revised 10/15/96 - Bug fixes and change to bit_vector. - -This version supports DLLs and threading. You must use critical -sections around code that uses the same container in different -threads. These features come at a price -- since memory -usage is not optimal, this code may use more memory and -may be slower. - -+ General strategy: Remove all statics except the - static allocator objects. -+ Vectors were not affected. -+ Major changes made to tree.h -+ Stability: Very stable. - -This code should be considered for experimental use only. There -are still statics lurking in some functions; these functions -are not thread-safe. - -------------------------- -Fix for bit_vector -------------------------- -This version also has a fix for bit_vector, which doesn't really -work with VC++ 4.x. Please include bvector.cpp in your -project if you use bit_vector. This fixes the linker errors -that occur if you use bector.h in multiple .cpp files. - -------------------------- -Disclaimer -------------------------- -Code is provided without warranty, liability, or technical support. - -STL.H and PTR.H are freely distributable and can be -modified in any way. - --------------------------------- -STRING.H does not compile. --------------------------------- - -"D. Pirzadeh" <ddp@crl.com> Explains how to fix: - -First, I got compile errors in "bstring.h" -and changed it as follows to correct: - line 1104 "::reserve" -> "std::reserve" - line 1110 "::default_size" -> "std::default_size" - -Also, I got an INTERNAL COMPILER ERROR with Visual C++ v4.0 when I did the fol- -lowing: - class xyz : public std::string { } - -I fixed it with: - typedef std::string XyzString; - class xyz : public XyzString { } - --------------------------------- -Changes made to STL distribution --------------------------------- - -These files were modified from the STL distribution shipped with -Microsoft Visual C++ 4.0. The files here are a complete, -working version of the STL. These files have been tested with -MFC applications. - -Changes were made to practically all header files. Look for -comments like: - -*Added by... -*Changed by... - ------------------- -Usage Instructions ------------------- - -Set the preprocessor variable NOMINMAX. - -As Microsoft recommends, the STL is compiled in the std namespace. - -When including these files, do **not** do this: - - namespace std - { - #include <vector.h> - } - -Instead, do this: - - #include <vector.h> - -Recommended usage: - - First, include: - - #include <afxwin.h> - #include <afxext.h> - #include <afxtempl.h> - - Then include the STL header files. - -------------------- -Support for CString -------------------- -The stl.h file contains code written by me. The file contains -operators that will allow you to use CString objects with STL -containers and functions. - -!!!! CString will not work with STL unless you include <stl.h> !!!! - -------------------------------------------- -Helper functions for pointers-in-containers -------------------------------------------- -There is a file called stl.h which contains two functions: - SequenceDelete - MapDelete -These functions send "delete" to all of the objects in a container. - -If you don't like this approach, you can use a supplied "pointer -wrapper" class. - -There is a file called ptr.h which contains a class called Ptr -that can be used exactly like a pointer. The object has a pointer -inside it that points to an object of any class. When a Ptr object -is deleted, "delete" is sent to its underlying pointer. Ptr can be -used with any STL container, as it has a copy constructor and -assignment operator, which transfers "ownership" of the pointer from -the source object to the destination object. Ptr is from the book -Design Patterns by Gamma et al -- see the Proxy pattern. - -The Ptr class makes memory leaks impossible, because it deletes -objects automatically when the container is deleted, or when -functions like "delete" are used. - -Example: - - This is a vector of CStrings: - - std::vector< Ptr<CString> > StringVector; - - StringVector.push_back( Ptr( new CString( "hello" ) ) ); - StringVector.push_back( Ptr( new CString( "This is another string" ) ) ); - ------------------------- -Common Problems with STL ------------------------- - -1) Compiler error: != is ambiguous - - Solution: put the following line at the beginning of the method - that caused the error: - - using namespace std; - -2) When using maps, the debugger crashes. - - This is because symbols for maps (actually, for the "pair") - get truncated to 255 characters. Solution: Turn off the - variables window in the debugger. Don't try to look at - a symbol that has been truncated. This is not an STL-specific - bug -- It's a bug in the debugger. - -3) All sorts of compile errors in STL header files - - Make sure the preprocessor variable NOMINMAX is defined - - -4) Compiler errors about "operator < is not available", etc. - The class involved has global comparison operators. - - Solution: - Write "routers" in the std namespace to the global namespace. - Example (see also stl.h - this is how CString is able - to work with STL): - - namespace std - { - BOOL operator < ( const MyClass & rLhs, - const AnotherClass & rRhs ) - { - return ::operator < ( rLhs, rRhs ); - } - } - - See also 5. - -5) When you use find() or another algorithm, the compiler - complains that it cannot find the == or < operators. - -If your code compiles without any error messages, then disregard -this section. However, if you get errors like "cannot convert -first argument from const class X" then read on. - -I am assuming that your code is calling an STL algorithm like -std::sort() or std::find(). If you're not, I can't help -you. - -There is apparently a bug in the Microsoft compiler regarding -namespaces. Namespaces cannot locate global -functions that reside in the global namespace. For example, -the binary == operator. - -Maybe this is a bug, maybe it isn't. This is not clear -to me. However, I do know what works and have tried many other -approaches that do not work. If you have a better solution I -would appreciate it if you could let me know about it. - -So, if you declare your own class and want to use algorithms -like find() on an STL container, you have two choices: - -(1) Declare == as a member function. -(2) Declare global operators == and !=. - -(1) simply works. There will come a time, however, when (1) -won't satisfy your needs. If A == B, then B == A. You can't -do this using member functions if A and B are from different -classes. - -If you choose (2), you must add the != operator to the std -namespace. There are two ways to do this. First, you can do -this: - namespace std - { - inline operator != ( const MyClass &rLhs, const MyClass &rRhs ) - { - return ::operator != ( rLhs, rRhs ); - } - } -This "routes" != from the std namespace to the global namespace. - -Note that ( lhs != rhs ) can be derived from the == operator -as !( lhs == rhs ). There is a macro in STL.H, -STL_DECLARE_GLOBAL_NE, that does this derivation. -This derivation will not work when for whatever reason, !(lhs == rhs) -is not the same as ( lhs != rhs ). - -The following example shows what you have to do for find(). Other -algorithms require you to declare <, <=, and >= too. See the -macros STL_DECLARE_GLOBAL_GE, STL_DECLARE_GLOBAL_LT, and -STL_GLOBAL_LE. These macros derive new comparison operators -from "operator <( const T&, const T& )". - -class MyClass -{ - public: - - int units; - CString description; -}; - -// We want to be able to test two MyClass objects against each other -// in STL. Need to create a global operator for this purpose. -// Since we use find(), we need to declare not-equal too. -bool operator == ( const MyClass &, const MyClass & ); -STL_DECLARE_GLOBAL_NE( MyClass, MyClass ) - -// These operators test for a matching description. -// We do A == B and B == A to be consistent. -bool operator == ( const MyClass&, const CString & ); -bool operator == ( const CString&, const MyClass & ); -STL_DECLARE_GLOBAL_NE( MyClass, CString ) -STL_DECLARE_GLOBAL_NE( CString, MyClass ) - -6. Errors when creating vectors that have vectors and deques - that have deques. - - Solution: Provide atruments to the constructor. - - std::vector< std::vector<int> > - TwoDimensional( 0, std::vector<int>() ); - diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c index be704168457..24de03dbd1f 100644 --- a/TAO/ChangeLog-98c +++ b/TAO/ChangeLog-98c @@ -1,61 +1,3 @@ -Wed May 23 14:39:01 1997 Brian Mendel <bmendel@mdc.com> - - * IIOP/lib/objtable.{h,cpp}: Added template specialization of - ACE_Hash_Map_Manager for char*'s. - - * IIOP/test/cubitS.cpp: Fixed type_id to be of type CORBA_String_var. - Also, added a debug msg to print the object address to show the - object for which the request is made. - - * IIOP/test/svr.cpp: Added capability to create multiple Cubit - objects via command line options. Added -n for number of objects and - -k for specifying a base name. For instance, -k Beevis -n 2 creates - Beevis1 and Beevis2 objects. The clnt can then specify a specific - object for the request as usual. - -Wed May 22 12:28:45 1997 Brian Mendel <bmendel@mdc.com> - - * IIOP/test/clnt.cpp: Deleted VxWorks specific sections. Command - line is now working for VxWorks. - * IIOP/test/svr.cpp: Deleted VxWOrks specific sections. Command line - is now working for VxWorks. - -Wed May 22 11:31:42 1997 Chris Cleeland <cleeland@cs.wustl.edu> - - * IIOP/test/svr.cpp: Added better error checking and messages, and - performed general re-formatting. - - * IIOP/test/method_db.i (initialize_method_db): Changed arg type - to use a pointer to the abstract class TAO_Operation_Table. - - * IIOP/test/cubitS.cpp (_skel_Cubit::_skel_Cubit): Added better - error checking and messages. Also defaulted to use the linear - object table implementation rather than the hashed to simplify - debugging. - - * IIOP/test/clnt.cpp: Moved some code around so that more of the - code is common is less is specific to VxWorks and other platforms. - Also did general re-formatting. - - * IIOP/lib/optable.cpp (TAO_Linear_OpTable::find): Initialization - of the loop variable makes the loop work properly. - - * IIOP/lib/objtable.cpp (TAO_Dynamic_Hash_ObjTable::find): - Explicitly specified length of object key in CTOR for ACE_CString - because object keys are not zero-terminated. - - * IIOP/lib/giop.cpp: Added newlines to the end of all ACE_DEBUG() - messages. - - * IIOP/lib/factories.cpp: Added template specializations for - ACE_Hash_Addr<ACE_INET_Addr, TAO_Client_Connection_Handler>. - -Tue May 22 09:32:41 1997 Brian Mendel <bmendel@mdc.com> - - * IIOP/lib/cdr.h: Deleted #define old_value ACE_INLINE and - #define ACE_INLINE old_value lines. Added #undefs for ACE_INLINE - prior to redefines. Changes required to compile on Windows NT. - Tue May 20 14:47:46 1997 Chris Cleeland <cleeland@cs.wustl.edu> * IIOP/test/cubitS.h: Removed forward decl of diff --git a/TAO/IIOP/lib/cdr.h b/TAO/IIOP/lib/cdr.h index 1b48b18f2be..00cf5597d4d 100644 --- a/TAO/IIOP/lib/cdr.h +++ b/TAO/IIOP/lib/cdr.h @@ -275,6 +275,7 @@ struct ACE_Svc_Export CDR // at creating typecode interpreters as well as to the ACE convention // of placing inline functions into separate files. # if !defined(__ACE_INLINE__) +# define old_value ACE_INLINE # undef ACE_INLINE # define ACE_INLINE inline # define do_undef_on_ACE_INLINE @@ -285,7 +286,9 @@ struct ACE_Svc_Export CDR # if defined(do_undef_on_ACE_INLINE) # undef do_undef_on_ACE_INLINE # undef ACE_INLINE -# define ACE_INLINE +# define ACE_INLINE old_value +# undef old_value +# undef do_undef_on_ACE_INLINE # endif #endif /* TAO_CDR_H */ diff --git a/TAO/IIOP/lib/factories.cpp b/TAO/IIOP/lib/factories.cpp index 93b46e84fe0..98795912434 100644 --- a/TAO/IIOP/lib/factories.cpp +++ b/TAO/IIOP/lib/factories.cpp @@ -4,22 +4,6 @@ # include "factories.i" #endif -// Template specializations which allow the cached connection manager -// to work better. - -size_t -ACE_Hash_Addr<ACE_INET_Addr, TAO_Client_Connection_Handler>::hash_i (const ACE_INET_Addr &addr) const -{ - return addr.get_ip_address () + addr.get_port_number (); -} - -int -ACE_Hash_Addr<ACE_INET_Addr, TAO_Client_Connection_Handler>::compare_i (const ACE_INET_Addr &a1, - const ACE_INET_Addr &a2) const -{ - return a1 != a2; -} - int TAO_Client_Connection_Handler::open(void *) { diff --git a/TAO/IIOP/lib/giop.cpp b/TAO/IIOP/lib/giop.cpp index 3d37e3a19f0..536c9ae023e 100644 --- a/TAO/IIOP/lib/giop.cpp +++ b/TAO/IIOP/lib/giop.cpp @@ -115,7 +115,7 @@ dump_msg (const char *label, (ptr[7] <= GIOP::MessageError) ? names [ptr[7]] : "UNKNOWN TYPE")); if (TAO_debug_level >= 4) - ACE_HEX_DUMP ((LM_DEBUG, (const char*)ptr, len, "(%P|%t) data bytes\n")); + ACE_HEX_DUMP ((LM_DEBUG, (const char*)ptr, len, "(%P|%t) data bytes")); } } @@ -188,15 +188,15 @@ GIOP::send_message (CDR &stream, if (writelen == -1) { - ACE_DEBUG ((LM_ERROR, "(%P|%t) OutgoingMessage::writebuf() $p\n")); - ACE_DEBUG ((LM_DEBUG, "(%P|%t) closing conn %d after fault\n", connection)); + ACE_DEBUG ((LM_ERROR, "(%P|%t) OutgoingMessage::writebuf() $p")); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) closing conn %d after fault", connection)); ACE_OS::closesocket (connection); connection = ACE_INVALID_HANDLE; return CORBA_B_FALSE; } else if (writelen == 0) { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) OutgoingMessage::writebuf () ... EOF, closing conn %d\n", connection)); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) OutgoingMessage::writebuf () ... EOF, closing conn %d", connection)); ACE_OS::closesocket (connection); connection = ACE_INVALID_HANDLE; return CORBA_B_FALSE; @@ -265,7 +265,7 @@ GIOP::close_connection (ACE_HANDLE &handle, (void) ACE::send (handle, close_message, TAO_GIOP_HEADER_LEN); (void) ACE_OS::shutdown (handle, 2); (void) ACE_OS::closesocket (handle); - ACE_DEBUG ((LM_DEBUG, "(%P|%t) shut down socket %d\n", handle)); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) shut down socket %d", handle)); handle = ACE_INVALID_HANDLE; } @@ -293,7 +293,7 @@ send_error (ACE_HANDLE &handle) (void) ACE::send (handle, error_message, TAO_GIOP_HEADER_LEN); (void) ACE_OS::shutdown (handle, 2); (void) ACE_OS::closesocket (handle); - ACE_DEBUG ((LM_DEBUG, "(%P|%t) aborted socket %d\n", handle)); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) aborted socket %d", handle)); handle = ACE_INVALID_HANDLE; } @@ -400,7 +400,7 @@ GIOP::read_message (ACE_SOCK_Stream &connection, { if (len == 0) { // EOF - ACE_DEBUG ((LM_DEBUG, "(%P|%t) Header EOF ... peer probably aborted connection %d\n", + ACE_DEBUG ((LM_DEBUG, "(%P|%t) Header EOF ... peer probably aborted connection %d", connection.get_handle())); return EndOfFile; // XXX should probably find some way to report this without @@ -409,9 +409,9 @@ GIOP::read_message (ACE_SOCK_Stream &connection, // } else if (len < 0) // error - ACE_DEBUG ((LM_ERROR, "(%P|%t) GIOP::read_message header socket error %p\n")); + ACE_DEBUG ((LM_ERROR, "(%P|%t) GIOP::read_message header socket error %p")); else // short read ... - ACE_DEBUG ((LM_ERROR, "(%P|%t) GIOP::read_message header failed (short)\n")); + ACE_DEBUG ((LM_ERROR, "(%P|%t) read message header failed (short)")); env.exception (new CORBA_COMM_FAILURE (COMPLETED_MAYBE)); return MessageError; @@ -429,7 +429,7 @@ GIOP::read_message (ACE_SOCK_Stream &connection, && msg.buffer [3] == 'P')) { env.exception (new CORBA_MARSHAL (COMPLETED_MAYBE)); // header - ACE_DEBUG((LM_DEBUG, "bad header, magic word\n")); + ACE_DEBUG((LM_DEBUG, "bad header, magic word")); return MessageError; } @@ -439,7 +439,7 @@ GIOP::read_message (ACE_SOCK_Stream &connection, if (!(msg.buffer [4] == MY_MAJOR && msg.buffer [5] <= MY_MINOR)) { env.exception (new CORBA_MARSHAL (COMPLETED_MAYBE)); // header - ACE_DEBUG((LM_DEBUG, "bad header, version\n")); + ACE_DEBUG((LM_DEBUG, "bad header, version")); return MessageError; } @@ -476,15 +476,15 @@ GIOP::read_message (ACE_SOCK_Stream &connection, if (len != (int) message_size) { if (len == 0) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) GIOP::read_message body, EOF on handle %d\n", connection.get_handle())); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) read message body, EOF on handle %d", connection.get_handle())); else if (len < 0) - ACE_DEBUG ((LM_ERROR, "(%P|%t) GIOP::read_message () body %p\n")); + ACE_DEBUG ((LM_ERROR, "(%P|%t) GIOP::read_message () body %p")); else - ACE_DEBUG ((LM_ERROR, "(%P|%t) short read, only %d of %d bytes\n", len, message_size)); + ACE_DEBUG ((LM_ERROR, "(%P|%t) short read, only %d of %d bytes", len, message_size)); // clean up, and ... env.exception (new CORBA_COMM_FAILURE (COMPLETED_MAYBE)); // body - ACE_DEBUG ((LM_DEBUG, "couldn't read rest of message\n")); + ACE_DEBUG ((LM_DEBUG, "couldn't read rest of message")); return MessageError; } @@ -880,7 +880,7 @@ GIOP::Invocation::invoke (CORBA_ExceptionList &exceptions, // be indicative of client bugs (lost track of input stream) or // server bugs; maybe the request was acted on, maybe not, we // can't tell. - ACE_DEBUG((LM_DEBUG, "(%P|%t) illegal message in response to my Request!\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) illegal message in response to my Request!")); env.exception (new CORBA_COMM_FAILURE (COMPLETED_MAYBE)); // FALLTHROUGH ... @@ -935,7 +935,7 @@ GIOP::Invocation::invoke (CORBA_ExceptionList &exceptions, { send_error (handler_->peer()); env.exception (new CORBA_COMM_FAILURE (COMPLETED_MAYBE)); - ACE_DEBUG((LM_DEBUG, "(%P|%t) bad Response header\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) bad Response header")); return SYSTEM_EXCEPTION; } @@ -1038,7 +1038,7 @@ GIOP::Invocation::invoke (CORBA_ExceptionList &exceptions, != CORBA_TypeCode::TRAVERSE_CONTINUE) { delete exception; - ACE_DEBUG((LM_ERROR, "(%P|%t) invoke, unmarshal %s exception %s\n", + ACE_DEBUG((LM_ERROR, "(%P|%t) invoke, unmarshal %s exception %s", (reply_status == USER_EXCEPTION) ? "user" : "system", exception_id)); send_error (handler_->peer()); @@ -1163,7 +1163,7 @@ GIOP::incoming_message (ACE_SOCK_Stream &peer, case LocateReply: case CloseConnection: default: // Unknown message - ACE_DEBUG((LM_DEBUG, "(%P|%t) Illegal message received by server\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) Illegal message received by server")); env.exception (new CORBA_COMM_FAILURE (COMPLETED_NO)); // FALLTHROUGH @@ -1229,20 +1229,20 @@ GIOP::incoming_message (ACE_SOCK_Stream &peer, #ifdef DEBUG if (TAO_debug_level >= 3) { - ACE_DEBUG((LM_DEBUG, "(%P|%t) %sRequest ID %#lx from FD %d\n", + ACE_DEBUG((LM_DEBUG, "(%P|%t) %sRequest ID %#lx from FD %d", req.response_expected ? "" : "Oneway ", req.request_id, peer.get_handle ())); if (TAO_debug_level >= 4) { ACE_HEX_DUMP((LM_DEBUG, (char*)req.object_key.buffer, - req.object_key.length, "(%P|%t) object key\n")); - ACE_DEBUG((LM_DEBUG, "(%P|%t) opname '%s'\n", req.operation)); + req.object_key.length, "(%P|%t) object key")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) opname '%s'", req.operation)); if (req.requesting_principal) ACE_HEX_DUMP((LM_DEBUG, (char*)req.requesting_principal->id.buffer, req.requesting_principal->id.length, - "(%P|%t) client principal\n")); + "(%P|%t) client principal")); else - ACE_DEBUG((LM_DEBUG, "(%P|%t) client principal (EMPTY)\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) client principal (EMPTY)")); } // NOTE: describe any service context, and how many bytes @@ -1287,7 +1287,7 @@ GIOP::incoming_message (ACE_SOCK_Stream &peer, } else if (status == OBJECT_FORWARD) { - ACE_DEBUG((LM_DEBUG, "(%P|%t) forwarding Request message\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) forwarding Request message")); response.put_ulong (LOCATION_FORWARD); CDR::encoder (_tc_CORBA_Object, &fwd_ref, @@ -1375,7 +1375,7 @@ GIOP::incoming_message (ACE_SOCK_Stream &peer, if (check_forward == 0) { response.put_ulong (OBJECT_HERE); - ACE_DEBUG((LM_DEBUG, "(%P|%t) LocateRequest response: object is (always) here!\n")); + ACE_DEBUG((LM_DEBUG, "(%P|%t) LocateRequest response: object is (always) here!")); } else { @@ -1386,14 +1386,14 @@ GIOP::incoming_message (ACE_SOCK_Stream &peer, if (status == OBJECT_FORWARD) { - ACE_DEBUG((LM_DEBUG, "LocateRequest response: forward requests\n")); + ACE_DEBUG((LM_DEBUG, "LocateRequest response: forward requests")); CDR::encoder (_tc_CORBA_Object, &fwd_ref, 0, &response, env); } else if (status == OBJECT_HERE) - ACE_DEBUG((LM_DEBUG, "LocateRequest response: object is here!\n")); + ACE_DEBUG((LM_DEBUG, "LocateRequest response: object is here!")); else - ACE_DEBUG((LM_DEBUG, "LocateRequest response: no such object\n")); + ACE_DEBUG((LM_DEBUG, "LocateRequest response: no such object")); } (void) send_message (response, peer); } diff --git a/TAO/IIOP/lib/objtable.cpp b/TAO/IIOP/lib/objtable.cpp index c1d4a805cf2..132c3032bf1 100644 --- a/TAO/IIOP/lib/objtable.cpp +++ b/TAO/IIOP/lib/objtable.cpp @@ -1,18 +1,5 @@ #include "objtable.h" -// Template Specialization for char* -int ACE_Hash_Map_Manager<const char*, CORBA_Object_ptr,ACE_SYNCH_RW_MUTEX>::equal(const char* const&id1, - const char* const&id2) -{ - return strcmp(id1, id2) == 0; -} - -// Template Specialization for char* -size_t ACE_Hash_Map_Manager<const char*, CORBA_Object_ptr,ACE_SYNCH_RW_MUTEX>::hash(const char* const&ext_id) -{ - return ACE::hash_pjw (ext_id); -} - TAO_Dynamic_Hash_ObjTable::TAO_Dynamic_Hash_ObjTable (CORBA_ULong size) { if (size > 0) @@ -29,17 +16,16 @@ int TAO_Dynamic_Hash_ObjTable::bind (const CORBA_OctetSeq &key, CORBA_Object_ptr obj) { - ACE_CString objkey ((char *) key.buffer, key.length); - - return this->hash_.bind (objkey.rep(), obj); + ACE_CString objkey ((char *) key.buffer); + return this->hash_.bind (objkey, obj); } int TAO_Dynamic_Hash_ObjTable::find (const CORBA_OctetSeq &key, CORBA_Object_ptr &obj) { - ACE_CString objkey ((char *) key.buffer, key.length); - return this->hash_.find (objkey.rep(), obj); + ACE_CString objkey ((char *) key.buffer); + return this->hash_.find (objkey, obj); } // Linear search strategy. diff --git a/TAO/IIOP/lib/objtable.h b/TAO/IIOP/lib/objtable.h index d3a7902bcf5..0b22086a8f2 100644 --- a/TAO/IIOP/lib/objtable.h +++ b/TAO/IIOP/lib/objtable.h @@ -26,8 +26,7 @@ # include "orb.h" // Dynamic Hashing scheme. -//typedef ACE_Hash_Map_Manager<ACE_CString, CORBA_Object_ptr, ACE_SYNCH_RW_MUTEX> OBJ_MAP_MANAGER; -typedef ACE_Hash_Map_Manager<const char*, CORBA_Object_ptr, ACE_SYNCH_RW_MUTEX> OBJ_MAP_MANAGER; +typedef ACE_Hash_Map_Manager<ACE_CString, CORBA_Object_ptr, ACE_SYNCH_RW_MUTEX> OBJ_MAP_MANAGER; class TAO_Object_Table // = TITLE diff --git a/TAO/IIOP/lib/optable.cpp b/TAO/IIOP/lib/optable.cpp index d78817b8a47..3766fbcf578 100644 --- a/TAO/IIOP/lib/optable.cpp +++ b/TAO/IIOP/lib/optable.cpp @@ -70,7 +70,9 @@ TAO_Linear_OpTable::find (const CORBA_String &opname, { ACE_ASSERT (this->next_ <= this->tablesize_); - for (CORBA_ULong i = 0; i < this->next_; i++) + for (CORBA_ULong i; + i < this->next_; + i++) if (!ACE_OS::strncmp (opname, this->tbl_[i].opname, ACE_OS::strlen (opname))) { skel_ptr = this->tbl_[i].skel_ptr; diff --git a/TAO/IIOP/test/clnt.cpp b/TAO/IIOP/test/clnt.cpp index f0249489889..7a4211d4521 100644 --- a/TAO/IIOP/test/clnt.cpp +++ b/TAO/IIOP/test/clnt.cpp @@ -47,8 +47,10 @@ static void cube_union_dii(unsigned &, unsigned &, CORBA_Object_ptr, CORBA_Environment &); // Global variables -const char* TAO_arg_ior = 0; +CORBA_ORB_ptr orb_ptr; unsigned loop_count = 1; +CORBA_Object_ptr objref = CORBA_Object::_nil(); +CORBA_Environment env; int exit_later = 0; // = TITLE @@ -74,7 +76,12 @@ int parse_args(int argc, char *argv[]) case 'O': // stringified objref { - TAO_arg_ior = ACE_OS::strdup(opts.optarg); + objref = orb_ptr->string_to_object ( + (CORBA_String)opts.optarg, env); + if (env.exception () != 0) { + print_exception (env.exception (), "string2object"); + return 1; + } } continue; @@ -99,269 +106,258 @@ int parse_args(int argc, char *argv[]) int main (int argc, char *argv[]) -{ - CORBA_ORB_ptr orb_ptr; - CORBA_Object_ptr objref = CORBA_Object::_nil(); - CORBA_Environment env; + { + +#if defined (VXWORKS) + // Work around VxWorks' lack of command line - orb_ptr = CORBA_ORB_init(argc, argv, "internet", env); - if (env.exception() != 0) + loop_count = 50; + int dummy = 1; + orb_ptr = CORBA_ORB_init (dummy, (char **)0, "internet", env); + if (env.exception() != 0) { - print_exception(env.exception(), "ORB initialization"); - return 1; + print_exception(env.exception(), "ORB initialization"); + return 1; } - // - // Parse command line and verify parameters. - // - parse_args(argc, argv); - - if (TAO_arg_ior == 0) - ACE_ERROR_RETURN((LM_ERROR, "%s: must specify an object reference using -O <ior>\n", argv[0]), 1); - - objref = orb_ptr->string_to_object ((CORBA_String)TAO_arg_ior, env); + hostAdd( "mv2604d", "130.38.183.132" ); - ACE_OS::free((void*)TAO_arg_ior); - TAO_arg_ior = 0; + objref = orb_ptr->string_to_object ( + (CORBA_String)"iiop:1.0//mv2604d:1000/key0", env); +#else - if (env.exception () != 0) + orb_ptr = CORBA_ORB_init(argc, argv, "internet", env); + if (env.exception() != 0) { - print_exception (env.exception (), "string2object"); - return 1; + print_exception(env.exception(), "ORB initialization"); + return 1; } - if (CORBA_is_nil (objref) == CORBA_B_TRUE) - ACE_ERROR_RETURN((LM_ERROR, "%s: must identify non-null target objref\n", argv [0]), 1); + // + // Parse command line and verify parameters. + // + parse_args(argc, argv); + +#endif + + if (CORBA_is_nil (objref) == CORBA_B_TRUE) { + ACE_OS::fprintf (stderr, "%s: must identify non-null target objref\n", + argv [0]); + return 1; + } - // Narrow the CORBA_Object reference to the stub object, checking - // the type along the way using _is_a - Cubit_ptr aCubit = Cubit::_narrow(objref); - if (aCubit == 0) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to narrow object reference to a Cubit_ptr.\n"), 1); + // Narrow the CORBA_Object reference to the stub object, checking + // the type along the way using _is_a + Cubit_ptr aCubit = Cubit::_narrow(objref); - // - // Make the calls in a loop. - // - unsigned i; - unsigned call_count, error_count; + // + // Make the calls in a loop. + // + unsigned i; + unsigned call_count, error_count; - call_count = 0; - error_count = 0; + call_count = 0; + error_count = 0; - ACE_Time_Value before, after; + ACE_Time_Value before, after; - before = ACE_OS::gettimeofday(); + before = ACE_OS::gettimeofday(); - for (i = 0; i < loop_count; i++) - { - // - // Cube an octet. - // - CORBA_Octet arg_octet, ret_octet; + for (i = 0; i < loop_count; i++) { + // + // Cube an octet. + // + CORBA_Octet arg_octet, ret_octet; - call_count++; - ret_octet = aCubit->Cubit_cube_octet (arg_octet = func (i), env); - if (env.exception () != 0) - { + call_count++; + ret_octet = aCubit->Cubit_cube_octet (arg_octet = func (i), env); + if (env.exception () != 0) { print_exception (env.exception (), "from cube_octet"); error_count++; - } - else - { + } else { dmsg2 ("cube octet: %d --> %d\n", arg_octet, ret_octet); arg_octet = arg_octet * arg_octet * arg_octet; if (arg_octet != ret_octet) { - ACE_OS::printf ("** cube_octet(%d) ERROR (--> %d)\n", - (CORBA_Octet) func (i), ret_octet); - error_count++; + ACE_OS::printf ("** cube_octet(%d) ERROR (--> %d)\n", + (CORBA_Octet) func (i), ret_octet); + error_count++; } - } + } - // - // Cube a short. - // - CORBA_Short arg_short, ret_short; + // + // Cube a short. + // + CORBA_Short arg_short, ret_short; - call_count++; - ret_short = aCubit->Cubit_cube_short (arg_short = func (i), env); - if (env.exception () != 0) - { + call_count++; + ret_short = aCubit->Cubit_cube_short (arg_short = func (i), env); + if (env.exception () != 0) { print_exception (env.exception (), "from cube_short"); error_count++; - } - else - { + } else { dmsg2 ("cube short: %d --> %d\n", arg_short, ret_short); arg_short = arg_short * arg_short * arg_short; - if (arg_short != ret_short) - { - ACE_OS::printf ("** cube_short(%d) ERROR (--> %d)\n", - (CORBA_Short) func (i), ret_short); - error_count++; - } - } + if (arg_short != ret_short) { + ACE_OS::printf ("** cube_short(%d) ERROR (--> %d)\n", + (CORBA_Short) func (i), ret_short); + error_count++; + } + } - // - // Cube a long. - // - CORBA_Long arg_long, ret_long; + // + // Cube a long. + // + CORBA_Long arg_long, ret_long; - call_count++; - ret_long = aCubit->Cubit_cube_long (arg_long = func (i), env); - if (env.exception () != 0) - { + call_count++; + ret_long = aCubit->Cubit_cube_long (arg_long = func (i), env); + if (env.exception () != 0) { print_exception (env.exception (), "from cube_long"); error_count++; - } - else - { + } else { dmsg2 ("cube long: %d --> %d\n", arg_long, ret_long); arg_long = arg_long * arg_long * arg_long; if (arg_long != ret_long) { - ACE_OS::printf ("** cube_long(%ld) ERROR (--> %ld)\n", - (CORBA_Long) func (i), ret_long); - error_count++; + ACE_OS::printf ("** cube_long(%ld) ERROR (--> %ld)\n", + (CORBA_Long) func (i), ret_long); + error_count++; } - } + } - // - // Cube a "struct" ... - // - Cubit_Many arg_struct, *ret_struct; + // + // Cube a "struct" ... + // + Cubit_Many arg_struct, *ret_struct; - call_count++; + call_count++; - arg_struct.l = func (i); - arg_struct.s = func (i); - arg_struct.o = func (i); + arg_struct.l = func (i); + arg_struct.s = func (i); + arg_struct.o = func (i); - ret_struct = aCubit->Cubit_cube_struct (arg_struct, env); - if (env.exception () != 0) - { + ret_struct = aCubit->Cubit_cube_struct (arg_struct, env); + if (env.exception () != 0) { print_exception (env.exception (), "from cube_struct"); error_count++; - } - else - { + } else { dmsg ("cube struct ..."); arg_struct.l = arg_struct.l * arg_struct.l * arg_struct.l; arg_struct.s = arg_struct.s * arg_struct.s * arg_struct.s; arg_struct.o = arg_struct.o * arg_struct.o * arg_struct.o; if (arg_struct.l != ret_struct->l - || arg_struct.s != ret_struct->s - || arg_struct.o != ret_struct->o) - { - ACE_OS::printf ("** cube_struct ERROR\n"); - error_count++; - } + || arg_struct.s != ret_struct->s + || arg_struct.o != ret_struct->o) { + ACE_OS::printf ("** cube_struct ERROR\n"); + error_count++; + } delete ret_struct; - } + } } - after = ACE_OS::gettimeofday(); + after = ACE_OS::gettimeofday(); - if (call_count > 0) + if (call_count > 0) { - if (error_count == 0) - { + if (error_count == 0) + { ACE_Time_Value diff = after - before; unsigned long us = diff.sec() * 1000 * 1000 + diff.usec(); us /= call_count; if (us > 0) - ACE_OS::printf ("cube average call ACE_OS::time\t= %ld.%.03ldms, \t" - "%ld calls/second\n", - us / 1000, us % 1000, - 1000000L / us); - } + ACE_OS::printf ("cube average call ACE_OS::time\t= %ld.%.03ldms, \t" + "%ld calls/second\n", + us / 1000, us % 1000, + 1000000L / us); + } - ACE_OS::printf ("%d calls, %d errors\n", call_count, error_count); + ACE_OS::printf ("%d calls, %d errors\n", call_count, error_count); } - // - // Simple test for DII: call "cube_struct". (It's not timed - // since the copious mallocation of DII would bias numbers against - // typical stub-based calls.) - // - do { // - // Create the request ... + // Simple test for DII: call "cube_struct". (It's not timed + // since the copious mallocation of DII would bias numbers against + // typical stub-based calls.) // - CORBA_Request_ptr req; + do { + // + // Create the request ... + // + CORBA_Request_ptr req; - req = objref->_request ((const CORBA_String) "cube_struct", env); - if (env.exception () != 0) { - print_exception (env.exception (), "DII request create"); - break; - } - - // - // ... initialise the argument list and result ... - // - Cubit_Many arg, *result; + req = objref->_request ((const CORBA_String) "cube_struct", env); + if (env.exception () != 0) { + print_exception (env.exception (), "DII request create"); + break; + } + + // + // ... initialise the argument list and result ... + // + Cubit_Many arg, *result; - arg.o = 3; arg.l = 5; arg.s = -7; + arg.o = 3; arg.l = 5; arg.s = -7; - CORBA_Any tmp_arg (TC_Cubit_Many, &arg, CORBA_B_FALSE); + CORBA_Any tmp_arg (TC_Cubit_Many, &arg, CORBA_B_FALSE); - req->arguments ()->add_value (0, tmp_arg, CORBA_ARG_IN, env); - if (env.exception () != 0) { - print_exception (env.exception (), "DII request arg add"); - CORBA_release (req); - break; - } + req->arguments ()->add_value (0, tmp_arg, CORBA_ARG_IN, env); + if (env.exception () != 0) { + print_exception (env.exception (), "DII request arg add"); + CORBA_release (req); + break; + } - req->result ()->value () - ->replace (TC_Cubit_Many, 0, CORBA_B_TRUE, env); - if (env.exception () != 0) { - print_exception (env.exception (), "DII request result type"); - CORBA_release (req); - break; - } - - // - // Make the invocation, verify the result - // - req->invoke (); - if (req->env ()->exception () != 0) { - print_exception (req->env ()->exception (), "DII invoke"); - CORBA_release (req); - break; - } + req->result ()->value () + ->replace (TC_Cubit_Many, 0, CORBA_B_TRUE, env); + if (env.exception () != 0) { + print_exception (env.exception (), "DII request result type"); + CORBA_release (req); + break; + } + + // + // Make the invocation, verify the result + // + req->invoke (); + if (req->env ()->exception () != 0) { + print_exception (req->env ()->exception (), "DII invoke"); + CORBA_release (req); + break; + } - result = (Cubit_Many *) req->result ()->value ()->value (); + result = (Cubit_Many *) req->result ()->value ()->value (); - if (result->o != 27 || result->l != 125 || result->s != -343) - ACE_OS::fprintf (stderr, "DII cube_struct -- bad results\n"); - else - dmsg ("DII cube_struct ... success!!"); + if (result->o != 27 || result->l != 125 || result->s != -343) + ACE_OS::fprintf (stderr, "DII cube_struct -- bad results\n"); + else + dmsg ("DII cube_struct ... success!!"); - CORBA_release (req); + CORBA_release (req); - } while (0); - - // - // Two more tests, using the "cube_union" function - // - cube_union_dii(call_count, error_count, objref, env); - if (env.exception () != 0) - error_count++; + } while (0); + + // + // Two more tests, using the "cube_union" function + // + cube_union_dii(call_count, error_count, objref, env); + if (env.exception () != 0) + error_count++; - cube_union_stub(i, call_count, error_count, objref, env); - if (env.exception () != 0) - error_count++; + cube_union_stub(i, call_count, error_count, objref, env); + if (env.exception () != 0) + error_count++; - if (exit_later) { - aCubit->Cubit_please_exit (env); - dexc (env, "server, please ACE_OS::exit"); - } + if (exit_later) { + aCubit->Cubit_please_exit (env); + dexc (env, "server, please ACE_OS::exit"); + } - CORBA_release (objref); + CORBA_release (objref); - return (error_count == 0) ? 0 : 1; + return (error_count == 0) ? 0 : 1; } diff --git a/TAO/IIOP/test/cubitS.cpp b/TAO/IIOP/test/cubitS.cpp index b153b71db1b..8e3e9864be9 100644 --- a/TAO/IIOP/test/cubitS.cpp +++ b/TAO/IIOP/test/cubitS.cpp @@ -16,16 +16,10 @@ #include "method_db.i" #include "iiopobj.h" -#if defined(CUBIT_USE_DYNAMIC_HASH) TAO_Dynamic_Hash_OpTable tao_cubit_optable(7); // Dynamic Operation Table -#else -TAO_Linear_OpTable tao_cubit_optable(7); -#endif _skel_Cubit::_skel_Cubit(const char* obj_name) { - const char* mn = "_skel_Cubit::_skel_Cubit()"; - // Initialize Method Database initialize_method_db (&tao_cubit_optable); @@ -34,14 +28,6 @@ _skel_Cubit::_skel_Cubit(const char* obj_name) IIOP_Object *data; CORBA_BOA_ptr oa = TAO_OA_PARAMS::instance()->oa(); - if (oa == 0) - { - // We just have to assume that oa will be good, or we have to - // throw an exception. For now we "assume", but we'll - ACE_ERROR((LM_ERROR, "(%P|%t) %s Unable to locate a valid object adapter\n", mn)); - return; - } - this->optable_ = &tao_cubit_optable; data = new IIOP_Object(type_id); @@ -55,16 +41,14 @@ _skel_Cubit::_skel_Cubit(const char* obj_name) ACE_OS::memcpy (data->profile.object_key.buffer, obj_name, - data->profile.object_key.length+1); + data->profile.object_key.length); this->set_parent(data); this->sub_ = this; - if (oa->bind(data->profile.object_key, this) == -1) - { - ACE_ERROR((LM_ERROR, "(%P|%t) %s Unable to bind object to key '%s': %p\n", mn, data->profile.object_key.buffer)); - return; - } + if (oa) + oa->bind(data->profile.object_key, this); + } void diff --git a/TAO/IIOP/test/cubit_i.cpp b/TAO/IIOP/test/cubit_i.cpp index ae22b7cd12c..92cf5026fe1 100644 --- a/TAO/IIOP/test/cubit_i.cpp +++ b/TAO/IIOP/test/cubit_i.cpp @@ -18,6 +18,7 @@ Cubit_i::Cubit_i(const char* obj_name) : _skel_Cubit(obj_name) { + cout << "Cubit_i ident: " << this << endl; } Cubit_i::~Cubit_i() diff --git a/TAO/IIOP/test/method_db.i b/TAO/IIOP/test/method_db.i index 6b77cdf040a..b567d09b7af 100644 --- a/TAO/IIOP/test/method_db.i +++ b/TAO/IIOP/test/method_db.i @@ -58,7 +58,7 @@ static const method_db cubit_operations[] = { }; -void initialize_method_db (TAO_Operation_Table *the_optable) +void initialize_method_db (TAO_Dynamic_Hash_OpTable *the_optable) { for (int ndx = 0; ndx < 7; ndx++) the_optable->bind(cubit_operations[ndx].opname, diff --git a/TAO/IIOP/test/svr.cpp b/TAO/IIOP/test/svr.cpp index 0e537bc6206..4afe2c62cd8 100644 --- a/TAO/IIOP/test/svr.cpp +++ b/TAO/IIOP/test/svr.cpp @@ -10,61 +10,16 @@ // Modified version of Cubit Example written by Sun Microsystems Inc. // Modified by: Brian Mendel -#include "ace/Get_Opt.h" -#include "ace/Log_Msg.h" +#include "cubit_i.h" +#include <ace/Get_Opt.h> #include "corba/orb.h" -#include "corba/debug.h" -#include "connect.h" - -#include "cubit_i.h" +#include <corba/debug.h> +#include <connect.h> extern void print_exception (const CORBA_Exception *, const char *, FILE *f=stdout); -// Global Variables -CORBA_String key = (CORBA_String)"key0"; -int num_of_objs = 1; - -// = TITLE -// Parses the command line arguments and returns an error status -// -// = DESCRIPTION -// This method parses the command line arguments -int parse_args(int argc, char *argv[]) -{ - ACE_Get_Opt opts (argc, argv, "dk:n:"); - int c; - - while ((c = opts ()) != -1) - switch (c) { - - case 'd': // debug flag - TAO_debug_level++; - continue; - - case 'k': // key (str) - key = (CORBA_String) opts.optarg; - continue; - - case 'n': // idle seconds b4 exit - num_of_objs = ACE_OS::atoi(opts.optarg); - continue; - - case '?': - default: - ACE_OS::fprintf (stderr, "usage: %s" - " [-d]" - " [-k {object_key}]" - "\n", argv [0] - ); - return 1; - } - - return 0; // Indicates successful parsing of command line -} - - // // Standard command line parsing utilities used. // @@ -72,13 +27,27 @@ int main (int argc, char *argv[]) { CORBA_Environment env; - CORBA_Object_ptr obj = 0; + CORBA_Object_ptr obj; CORBA_ORB_ptr orb_ptr; CORBA_BOA_ptr oa_ptr; + CORBA_String key = (CORBA_String) "key0"; char *orb_name = "internet"; int idle = -1; + int debug_level = 1; + +#if defined (VXWORKS) + + char *oa_name = "mv2604d:1000"; + int dummy = 1; + + orb_ptr = CORBA_ORB_init (dummy, (char **)0, orb_name, env); + +#else orb_ptr = CORBA_ORB_init (argc, argv, orb_name, env); + +#endif + if (env.exception () != 0) { print_exception (env.exception (), "ORB init"); return 1; @@ -86,70 +55,22 @@ main (int argc, char *argv[]) // Initialize the Basic Object Adapter oa_ptr = orb_ptr->BOA_init(argc, argv, "ROA"); - if (oa_ptr == 0) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to initialize the BOA.\n"), 1); - - // - // Parse remaining command line and verify parameters. - // - parse_args(argc, argv); - // Create implementation object with user specified key - Cubit_i_ptr *my_cubit = new Cubit_i_ptr[num_of_objs]; - for (int ndx = 0; ndx < num_of_objs; ndx++) - { - CORBA_String obj_str = CORBA_string_alloc(ACE_OS::strlen ((char *)key)+2); - sprintf(obj_str, "%s%d", (char*)key, ndx); - my_cubit[ndx] = new Cubit_i(obj_str); - if (my_cubit[ndx] == 0) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to create implementation object&d\n", ndx), 2); - - if (TAO_debug_level >= 1) - { - // Why are we getting the BOA_ptr from here when we've already - // got it above? - CORBA_OctetSeq obj_key; - obj_key.buffer = (CORBA_Octet *) obj_str; - obj_key.length = obj_key.maximum = ACE_OS::strlen (obj_str); - - if (oa_ptr->find(obj_key, obj) == -1) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to locate object with key '%s', %p\n", key), 3); - - // - // Stringify the objref we'll be implementing, and - // print it to stdout. Someone will take that string - // and give it to some client. Then release the object. - // - CORBA_String str; - - str = orb_ptr->object_to_string (obj, env); - if (env.exception () != 0) { - print_exception (env.exception (), "object2string"); - return 1; - } - ACE_OS::puts ((char *)str); - ACE_OS::fflush (stdout); - dmsg1 ("Object Created at: '%ul'", obj); - dmsg1 ("listening as object '%s'", str); - - } - CORBA_string_free(obj_str); - } -// Cubit_i_ptr my_cubit = new Cubit_i(key); -// if (my_cubit1 == 0) -// ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to create implementation object\n"), 2); + Cubit_i_ptr my_cubit = new Cubit_i(key); -/* if (TAO_debug_level >= 1) + if (debug_level >= 1) { // Why are we getting the BOA_ptr from here when we've already // got it above? + CORBA_BOA_ptr oa = TAO_OA_PARAMS::instance()->oa(); CORBA_OctetSeq obj_key; obj_key.buffer = (CORBA_Octet *) key; obj_key.length = obj_key.maximum = ACE_OS::strlen ((char *)key); - if (oa_ptr->find(obj_key, obj) == -1) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to locate object with key '%s', %p\n", key), 3); + if (oa) + (void) oa->find(obj_key, obj); + // // Stringify the objref we'll be implementing, and @@ -166,27 +87,15 @@ main (int argc, char *argv[]) ACE_OS::puts ((char *)str); ACE_OS::fflush (stdout); dmsg1 ("listening as object '%s'", str); - - obj_key.buffer = (CORBA_Octet *)"key1"; - obj_key.length = obj_key.maximum = 4; - if (oa_ptr->find(obj_key, obj) == -1) - ACE_ERROR_RETURN((LM_ERROR, "(%P|%t) Unable to locate object with key '%s', %p\n", key), 3); - - str = orb_ptr->object_to_string (obj, env); - if (env.exception () != 0) { - print_exception (env.exception (), "object2string"); - return 1; - } - ACE_OS::puts ((char *)str); - ACE_OS::fflush (stdout); - dmsg1 ("listening as object '%s'", str); } -*/ + // Handle requests for this object until we're killed, or one of // the methods asks us to exit. // int terminationStatus = 0; + // Insert Object Key into context + // params->context(&obj_key); #if !defined(USE_HOMEBREW_EVENT_LOOP) ACE_Service_Config::run_reactor_event_loop(); @@ -1,4 +1,4 @@ -This is ACE version 4.2.3, released Tue May 27 14:40:34 CDT 1997. +This is ACE version 4.2, released Wed May 21 14:12:26 CDT 1997. If you have any problems with ACE, please send email to Douglas C. Schmidt (schmidt@cs.wustl.edu). diff --git a/ace/ACE.cpp b/ace/ACE.cpp index 4a26b74517c..2b49dffc42b 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -823,7 +823,8 @@ ACE::bind_port (ACE_HANDLE handle) sockaddr_in sin; // This should be a constant, so I hope they never change the number // of bits in a port number! - static u_short upper_limit = ACE_MAX_DEFAULT_PORT; + const u_short MAX_SHORT = 65535; + static u_short upper_limit = MAX_SHORT; int lower_limit = IPPORT_RESERVED; int round_trip = upper_limit; @@ -846,11 +847,11 @@ ACE::bind_port (ACE_HANDLE handle) { upper_limit--; - // Wrap back around when we reach the bottom. + /* Wrap back around when we reach the bottom. */ if (upper_limit <= lower_limit) - upper_limit = ACE_MAX_DEFAULT_PORT; + upper_limit = MAX_SHORT; - // See if we have already gone around once! + /* See if we have already gone around once! */ if (upper_limit == round_trip) { errno = EAGAIN; diff --git a/ace/Connector.cpp b/ace/Connector.cpp index a5f405de623..2ab0ec98708 100644 --- a/ace/Connector.cpp +++ b/ace/Connector.cpp @@ -361,16 +361,9 @@ ACE_Connector<SH, PR_CO_2>::connect (SH *&sh, this->create_AST (sh, synch_options); } else - { - // Make sure to save/restore the errno since <close> may - // change it. - - int error = errno; - // Make sure to close down the Channel to avoid descriptor - // leaks. - sh->close (0); - errno = error; - } + // Make sure to close down the Channel to avoid descriptor + // leaks. + sh->close (0); return -1; } else diff --git a/ace/Future.cpp b/ace/Future.cpp index eccf2ef6e0b..7c5fd9b29af 100644 --- a/ace/Future.cpp +++ b/ace/Future.cpp @@ -17,14 +17,13 @@ ACE_Future_Rep<T>::dump (void) const { ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, - "ref_count_ = %d\n", - (int) this->ref_count_)); + "ref_count_ = %d\n", + (int) this->ref_count_)); ACE_DEBUG ((LM_INFO,"value_: \n")); if (this->value_) ACE_DEBUG ((LM_DEBUG," (NON-NULL)\n")); else ACE_DEBUG ((LM_DEBUG," (NULL)\n")); - ACE_DEBUG ((LM_INFO,"value_ready_: \n")); this->value_ready_.dump (); ACE_DEBUG ((LM_INFO,"value_ready_mutex_: \n")); @@ -32,62 +31,6 @@ ACE_Future_Rep<T>::dump (void) const ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } -template <class T> ACE_Future_Rep<T> * -ACE_Future_Rep<T>::create (void) -{ - // Yes set ref count to zero. - return new ACE_Future_Rep<T>(); -} - -template <class T> ACE_Future_Rep<T> * -ACE_Future_Rep<T>::attach (ACE_Future_Rep<T>*& rep) -{ - ACE_ASSERT (rep != 0); - // Use value_ready_mutex_ for both condition and ref count management - ACE_MT (ACE_Guard<ACE_Thread_Mutex> r_mon(rep->value_ready_mutex_)); - ++rep->ref_count_; - return rep; -} - -template <class T> void -ACE_Future_Rep<T>::detach (ACE_Future_Rep<T>*& rep) -{ - ACE_ASSERT(rep != 0); - // Use value_ready_mutex_ for both condition and ref count management - ACE_MT (ACE_GUARD (ACE_Thread_Mutex, r_mon, rep->value_ready_mutex_)); - - if (rep->ref_count_-- == 0) - { - r_mon.release (); - // We do not need the lock when deleting the representation. - // There should be no side effects from deleting rep and we don - // not want to release a deleted mutex. - delete rep; - } -} - -template <class T> void -ACE_Future_Rep<T>::assign (ACE_Future_Rep<T>*& rep, ACE_Future_Rep<T>* new_rep) -{ - ACE_ASSERT(rep != 0); - ACE_ASSERT(new_rep != 0); - // Use value_ready_mutex_ for both condition and ref count management - ACE_MT (ACE_GUARD (ACE_Thread_Mutex, r_mon, rep->value_ready_mutex_)); - - ACE_Future_Rep<T>* old = rep; - rep = new_rep; - - // detached old last for exception safety - if (old->ref_count_-- == 0) - { - r_mon.release (); - // We do not need the lock when deleting the representation. - // There should be no side effects from deleting rep and we don - // not want to release a deleted mutex. - delete old; - } -} - template <class T> ACE_Future_Rep<T>::ACE_Future_Rep (void) : value_ (0), @@ -100,6 +43,7 @@ template <class T> ACE_Future_Rep<T>::~ACE_Future_Rep (void) { delete this->value_; + this->value_ = 0; } template <class T> int @@ -119,7 +63,7 @@ ACE_Future_Rep<T>::set (const T &r) // Double-checked locking pattern to avoid multiple allocations. if (this->value_ == 0) - ACE_NEW_RETURN (this->value_, T (r), -1); + ACE_NEW_RETURN (this->value_, T (r), -1); // Signal all the waiting threads. return this->value_ready_.broadcast (); @@ -130,8 +74,7 @@ ACE_Future_Rep<T>::set (const T &r) } template <class T> int -ACE_Future_Rep<T>::get (T &value, - ACE_Time_Value *tv) +ACE_Future_Rep<T>::get (T &value, ACE_Time_Value *tv) { // If the value is already produced, return it. if (this->value_ == 0) @@ -142,10 +85,11 @@ ACE_Future_Rep<T>::get (T &value, // producer writes to it. while (this->value_ == 0) - // Perform a timed wait. - if (this->value_ready_.wait (tv) == -1) - return -1; - + { + // Perform a timed wait. + if (this->value_ready_.wait (tv) == -1) + return -1; + } // Destructor releases the lock. } @@ -165,45 +109,82 @@ ACE_Future_Rep<T>::operator T () // If the value is not yet defined we must block until the // producer writes to it. - // Wait ``forever.'' - while (this->value_ == 0) - if (this->value_ready_.wait () == -1) - // What to do in this case since we've got to indicate - // failure somehow? Exceptions would be nice, but they're - // not portable... - return 0; + { + // wait forever + if (this->value_ready_.wait () == -1) + // What to do in this case since we've got to indicate + // failure somehow? Exceptions would be nice, but they're + // not portable... + return 0; + } // Destructor releases the mutex + } return *this->value_; } + template <class T> ACE_Future<T>::ACE_Future (void) - : future_rep_ (FUTURE_REP::create ()) + : future_rep_ (0) { } template <class T> ACE_Future<T>::ACE_Future (const ACE_Future<T> &r) - : future_rep_ (FUTURE_REP::attach (((ACE_Future<T> &) r).future_rep_)) { + + // copy constructor: + // + // bind <this> to the same <ACE_Future_Rep> as <r>. + + // @@ not really clear if this is needed... after all this + // ACE_Future is just being instantiated... + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->mutex_)); + + // acquire the mutex on <r>. We have to make sure + // that <r> does not delete its future_rep_... + + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, r_mon, (ACE_Thread_Mutex &) r.mutex_)); + + // Check if 'r' has already a ACE_Future_rep bound to it. + if (r.future_rep_ == 0) + this->future_rep_ = r.create_rep_i (); + else + // ACE_Future_rep exists already, we can just link to it. + this->future_rep_ = r.future_rep_; + + this->future_rep_->ref_count_++; + } template <class T> ACE_Future<T>::ACE_Future (const T &r) - : future_rep_ (FUTURE_REP::create ()) { ACE_DEBUG ((LM_DEBUG," (%t) funny constructor\n")); - this->future_rep_->set (r); + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->mutex_)); + this->create_rep_i ()->set (r); } template <class T> ACE_Future<T>::~ACE_Future (void) { - FUTURE_REP::detach (future_rep_); + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->mutex_)); + + if (this->future_rep_) + { + this->future_rep_->ref_count_--; + + if (this->future_rep_->ref_count_ == 0) + { + delete this->future_rep_; + this->future_rep_ = 0; + } + } + } template <class T> int @@ -221,35 +202,64 @@ ACE_Future<T>::operator!= (const ACE_Future<T> &r) const template <class T> int ACE_Future<T>::cancel (const T &r) { - this->cancel (); - return this->future_rep_->set (r); -} + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->mutex_, -1)); -template <class T> int -ACE_Future<T>::cancel (void) -{ // If this ACE_Future is already attached to a ACE_Future_Rep, // detach it (maybe delete the ACE_Future_Rep). - FUTURE_REP::assign (this->future_rep_, FUTURE_REP::create ()); - return 0; + if (this->future_rep_) + { + this->future_rep_->ref_count_--; + + if (this->future_rep_->ref_count_ == 0) + delete this->future_rep_; + } + + // Make a new ACE_Future_Rep and immediately assign + // the new value to it. + this->create_rep_i (); + return this->future_rep_->set (r); } template <class T> int ACE_Future<T>::set (const T &r) { - // Give the pointer to the result to the ACE_Future_Rep. - return this->future_rep_->set (r); + if (this->future_rep_) + // Give the pointer to the result to the ACE_Future_Rep. + return this->future_rep_->set (r); + else + // @@ Maybe this should return a special value to indicate that + // there's no <ACE_Future_Rep> yet? + return 0; +} + +template <class T> ACE_Future_Rep<T> * +ACE_Future<T>::create_rep_i (void) const +{ + // Should only be called internally with locks held. + ACE_NEW_RETURN (((ACE_Future<T> *) this)->future_rep_, ACE_Future_Rep<T>, 0); + this->future_rep_->ref_count_ = 1; + return this->future_rep_; } + template <class T> int ACE_Future<T>::ready (void) { // We're ready if the ACE_Future_rep is ready... - return this->future_rep_->ready (); + if (this->future_rep_) + return this->future_rep_->ready (); + else + return 0; } template <class T> int ACE_Future<T>::get (T &value, ACE_Time_Value *tv) { + ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->mutex_, -1)); + + if (this->future_rep_ == 0) + // Oops, we have to create a ACE_Future_Rep first. + this->create_rep_i (); + // We return the ACE_Future_rep. return this->future_rep_->get (value, tv); } @@ -273,16 +283,38 @@ ACE_Future<T>::operator T () } template <class T> void -ACE_Future<T>::operator = (const ACE_Future<T> &rhs) +ACE_Future<T>::operator = (const ACE_Future<T> &r) { // assignment: // // bind <this> to the same <ACE_Future_Rep> as <r>. - // This will work if &r == this, by first increasing the ref count - ACE_Future<T> &r = ( ACE_Future<T> &) rhs; - FUTURE_REP::assign (this->future_rep_, - FUTURE_REP::attach (r.future_rep_)); + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->mutex_)); + + // if there is already a <ACE_Future_Rep> we have + // to disconnect from it... + if (this->future_rep_) + { + // Disconnect from the <ACE_Future_Rep>. + this->future_rep_->ref_count_--; + + if (this->future_rep_->ref_count_ == 0) + delete this->future_rep_; + } + + // Acquire the mutex on <r>. We have to make sure + // that <r> does not delete it's future_rep_... + + ACE_MT (ACE_GUARD (ACE_Thread_Mutex, r_mon, (ACE_Thread_Mutex &) r.mutex_)); + + // Check if 'r' has already a ACE_Future_rep bound to it. + if (r.future_rep_ == 0) + this->future_rep_ = r.create_rep_i (); + else + // ACE_Future_rep exists already, we can just link to it. + this->future_rep_ = r.future_rep_; + + this->future_rep_->ref_count_++; } template <class T> void @@ -292,6 +324,8 @@ ACE_Future<T>::dump (void) const if (this->future_rep_) this->future_rep_->dump (); + + this->mutex_.dump (); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } @@ -312,8 +346,6 @@ ACE_Future<T>::operator &() } #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -// This should probably be moved elsewhere now that ACE_Atomic_Op<> -// isn't used. template class ACE_Atomic_Op<ACE_Thread_Mutex, int>; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/ace/Future.h b/ace/Future.h index 09d08f5fdcd..a296a91c632 100644 --- a/ace/Future.h +++ b/ace/Future.h @@ -1,6 +1,7 @@ /* -*- C++ -*- */ // $Id$ + // ============================================================================ // // = LIBRARY @@ -10,9 +11,8 @@ // Future.h // // = AUTHOR -// Andres Kruse <Andres.Kruse@cern.ch>, Douglas C. Schmidt -// <schmidt@cs.wustl.edu>, and Per Andersson -// <Per.Andersson@hfera.ericsson.se>. +// Andres Kruse <Andres.Kruse@cern.ch> and Douglas C. Schmidt +// <schmidt@cs.wustl.edu> // // ============================================================================ @@ -27,48 +27,24 @@ template <class T> class ACE_Future; template <class T> class ACE_Future_Rep - // = TITLE - // ACE_Future_Rep<T> - // - // = DESCRIPTION - // An ACE_Future_Rep<T> object encapsules a pointer to an - // object of class T which is the result of an asynchronous - // method invocation. It is pointed to by ACE_Future<T> object[s] - // and only accessible through them. +// = TITLE +// +// ACE_Future_Rep<T> +// +// = DESCRIPTION +// An ACE_Future_Rep<T> object encapsules a pointer to an +// object of class T which is the result of an asynchronous +// method invocation. It is pointed to by ACE_Future<T> object[s] +// and only accessible through them. { friend class ACE_Future<T>; private: - - // Create, attach, detach and assign encapsulates the reference - // count handling and the object lifetime of ACE_Future_Rep<T> - // instances. - - static ACE_Future_Rep<T> *create (void); - // Create a ACE_Future_Rep<T> and initialize the reference count - - static ACE_Future_Rep<T> *attach (ACE_Future_Rep<T> *&rep); - // Precondition(rep != 0) - // Increase the reference count and return argument. Uses - // the attribute "value_ready_mutex_" to synchronize reference - // count updating - - static void detach (ACE_Future_Rep<T> *&rep); - // Precondition(rep != 0) - // Decreases the reference count and and deletes rep if - // there are no more references to rep. - - static void assign (ACE_Future_Rep<T> *&rep, - ACE_Future_Rep<T> *new_rep); - // Precondition(rep != 0 && new_rep != 0) - // Decreases the rep's reference count and and deletes rep if there - // are no more references to rep. Then assigns new_rep to rep - + int set (const T &r); // Set the result value. - int get (T &value, - ACE_Time_Value *tv); + int get (T &value, ACE_Time_Value *tv); // Wait up to <tv> time to get the <value>. operator T (); @@ -86,7 +62,7 @@ private: ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. - // = Constructor and destructor private + // = constructor and destructor private ACE_Future_Rep (void); ~ACE_Future_Rep (void); @@ -96,7 +72,7 @@ private: T *value_; // Pointer to the result. - int ref_count_; + ACE_Atomic_Op<ACE_Thread_Mutex, int> ref_count_; // Reference count. // = Condition variable and mutex that protect the <value_>. @@ -106,12 +82,10 @@ private: template <class T> class ACE_Future // = TITLE - // This class implements a ``single write, multiple read'' - // pattern that can be used to return results from asynchronous - // method invocations. - // + // This class implements a ``single write, multiple read'' pattern + // that can be used to return results from asynchronous method + // invocations. // = DESCRIPTION - // @@ Please update me... { public: // = Initialization and termination methods. @@ -136,12 +110,6 @@ public: int cancel (const T &r); // Cancel an <ACE_Future> and assign the value <r>. It is used if a // client does not want to wait for <T> to be produced. - - int cancel (void); - // Cancel an <ACE_Future>. Put the future into its initial - // state. Returns 0 on succes and -1 on failure. It is now possible - // to reuse the ACE_Future<T>. But remember, the ACE_Future<T> - // is now bound to a new ACE_Future_Rep<T>. int operator == (const ACE_Future<T> &r) const; // Equality operator that returns 1 if both ACE_Future<T> objects @@ -156,8 +124,7 @@ public: // Make the result available. Is used by the server thread to give // the result to all waiting clients. - int get (T &value, - ACE_Time_Value *tv = 0); + int get (T &value, ACE_Time_Value *tv = 0); // Wait up to <tv> time to get the <value>. operator T (); @@ -179,19 +146,24 @@ public: // Declare the dynamic allocation hooks. private: - void *operator new (size_t nbytes); + ACE_Future_Rep<T> *create_rep_i (void) const; + // Create the <ACE_Future_Rep> object. + + void* operator new (size_t nbytes); // Do not allow new operator. - void operator delete (void *); + void operator delete(void *); // Do not allow delete operator void operator &(); // Do not allow address-of operator. + ACE_Future_Rep<T> *future_rep_; // the ACE_Future_Rep - typedef ACE_Future_Rep<T> FUTURE_REP; - FUTURE_REP *future_rep_; + + ACE_Thread_Mutex mutex_; // Protect operations on the <Future>. + }; #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) @@ -201,7 +173,5 @@ private: #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) #pragma implementation ("Future.cpp") #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - #endif /* ACE_HAS_THREADS */ #endif /* ACE_FUTURE_H */ - diff --git a/ace/Handle_Set.cpp b/ace/Handle_Set.cpp index b09333d144e..0648a515032 100644 --- a/ace/Handle_Set.cpp +++ b/ace/Handle_Set.cpp @@ -17,9 +17,9 @@ ACE_Handle_Set::dump (void) const ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); - ACE_DEBUG ((LM_DEBUG, "\nsize_ = %d", this->size_)); + ACE_DEBUG ((LM_DEBUG, "[ ")); + ACE_DEBUG ((LM_DEBUG, "size_ = %d", this->size_)); ACE_DEBUG ((LM_DEBUG, "\nmax_handle_ = %d", this->max_handle_)); - ACE_DEBUG ((LM_DEBUG, "\n[ ")); #if defined (ACE_WIN32) for (size_t i = 0; i < this->mask_.fd_count + 1; i++) @@ -30,10 +30,17 @@ ACE_Handle_Set::dump (void) const ACE_DEBUG ((LM_DEBUG, " %d ", i)); #endif /* ACE_WIN32 */ - ACE_DEBUG ((LM_DEBUG, " ]\n")); + ACE_DEBUG ((LM_DEBUG, " ]")); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } +#if defined (ACE_HAS_BROKEN_BITSHIFT) +static const ACE_UINT32 MSB_MASK = ~(ACE_UINT32 (1) << ACE_UINT32 (NFDBITS - 1)); +#else +// This needs to go here to avoid overflow problems on some compilers. +static const ACE_UINT32 MSB_MASK = ~(1 << (NFDBITS - 1)); +#endif /* ACE_HAS_BROKEN_BITSHIFT */ + // Table that maps bytes to counts of the enabled bits. const char ACE_Handle_Set::nbits_[256] = @@ -79,13 +86,11 @@ ACE_Handle_Set::ACE_Handle_Set (const ACE_FD_SET_TYPE &fd_mask) // speed up the count. int -ACE_Handle_Set::count_bits (u_long n) const +ACE_Handle_Set::count_bits (unsigned long n) const { ACE_TRACE ("ACE_Handle_Set::count_bits"); - return (ACE_Handle_Set::nbits_[n & 0xff] - + ACE_Handle_Set::nbits_[(n >> 8) & 0xff] - + ACE_Handle_Set::nbits_[(n >> 16) & 0xff] - + ACE_Handle_Set::nbits_[n >> 24]); + return (ACE_Handle_Set::nbits_[n & 0xff] + ACE_Handle_Set::nbits_[(n >> 8) & 0xff] + + ACE_Handle_Set::nbits_[(n >> 16) & 0xff] + ACE_Handle_Set::nbits_[n >> 24]); } // Synchronize the underlying FD_SET with the MAX_FD and the SIZE. @@ -95,16 +100,16 @@ ACE_Handle_Set::sync (ACE_HANDLE max) { ACE_TRACE ("ACE_Handle_Set::sync"); #if !defined(ACE_WIN32) - this->size_ = 0; + this->size_ = 0; - for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE; - i >= 0; - i--) - this->size_ += count_bits (this->mask_.fds_bits[i]); + for (int i = (max - 1) / ACE_Handle_Set::WORDSIZE; + i >= 0; + i--) + this->size_ += count_bits (this->mask_.fds_bits[i]); - this->set_max (max); + this->set_max (max); #else - ACE_UNUSED_ARG (max); + ACE_UNUSED_ARG (max); #endif /* !ACE_WIN32 */ } @@ -115,8 +120,9 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max) { ACE_TRACE ("ACE_Handle_Set::set_max"); #if !defined(ACE_WIN32) + if (this->size_ == 0) - this->max_handle_ = ACE_INVALID_HANDLE; + this->max_handle_ = -1; else { int i; @@ -127,10 +133,9 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max) continue; this->max_handle_ = i * ACE_Handle_Set::WORDSIZE; - for (fd_mask val = this->mask_.fds_bits[i]; - (val & ~1) != 0; // This obscure code is needed since "bit 0" is in location 1... - val = (val >> 1) & ACE_MSB_MASK) + (val & ~1) != 0; + val = (val >> 1) & MSB_MASK) this->max_handle_++; } @@ -138,7 +143,7 @@ ACE_Handle_Set::set_max (ACE_HANDLE current_max) if (this->max_handle_ >= ACE_Handle_Set::MAXSIZE) this->max_handle_ = ACE_Handle_Set::MAXSIZE - 1; #else - ACE_UNUSED_ARG (current_max); + ACE_UNUSED_ARG(current_max); #endif /* !ACE_WIN32 */ } @@ -150,7 +155,69 @@ ACE_Handle_Set_Iterator::dump (void) const ACE_TRACE ("ACE_Handle_Set_Iterator::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); - ACE_DEBUG ((LM_DEBUG, "\nhandle_index_ = %d", this->handle_index_)); - ACE_DEBUG ((LM_DEBUG, "\nword_num_ = %d", this->word_num_)); + ACE_DEBUG ((LM_DEBUG, "num_ = %d", this->num_)); + ACE_DEBUG ((LM_DEBUG, "\nindex_ = %d", this->index_)); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); } + +void +ACE_Handle_Set_Iterator::operator++ (void) +{ + ACE_TRACE ("ACE_Handle_Set_Iterator::operator++"); + +#if defined(ACE_WIN32) + this->index_++; +#else /* !ACE_WIN32 */ + this->val_ = (this->val_ >> 1) & MSB_MASK; + this->num_++; + + + if (this->val_ == 0) + { + for (this->index_++; + this->index_ < ACE_Handle_Set::NUM_WORDS + && this->handles_.mask_.fds_bits[this->index_] == 0; + this->index_++) + continue; + + if (this->index_ >= ACE_Handle_Set::NUM_WORDS) + { + this->num_ = this->handles_.max_handle_ + 1; + return; + } + else + { + this->val_ = this->handles_.mask_.fds_bits[this->index_]; + this->num_ = this->index_ * ACE_Handle_Set::WORDSIZE; + } + } + + for (; ACE_BIT_DISABLED (this->val_, 1); this->num_++) + this->val_ = (this->val_ >> 1) & MSB_MASK; +#endif /* !ACE_WIN32 */ +} + +ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &f) + : handles_ (f), + num_ (0), + index_ (0) +{ + ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator"); +#if !defined(ACE_WIN32) + // Loop until we've found the first non-zero bit or we run off the + // end of the bitset. + for (; + this->num_ < ACE_Handle_Set::MAXSIZE + && this->handles_.mask_.fds_bits[this->index_] == 0; + this->index_++) + this->num_ += ACE_Handle_Set::WORDSIZE; + + if (this->num_ >= ACE_Handle_Set::MAXSIZE) + this->num_ = this->handles_.max_handle_ + 1; + else + for (this->val_ = this->handles_.mask_.fds_bits[this->index_]; + (ACE_BIT_DISABLED (this->val_, 1)) && this->num_ < ACE_Handle_Set::MAXSIZE; + this->num_++) + this->val_ = (this->val_ >> 1) & MSB_MASK; +#endif /* !ACE_WIN32 */ +} diff --git a/ace/Handle_Set.h b/ace/Handle_Set.h index 3be77f18371..ef01db484e6 100644 --- a/ace/Handle_Set.h +++ b/ace/Handle_Set.h @@ -19,6 +19,16 @@ #include "ace/ACE.h" +// This wrapper design is not very portable to DEC OSF/1 I had to +// redefine NFDBITS to 32. On OSF/1 NFDBITS is a macro that expands to +// (sizeof(fd_mask)*8) which is 4096 by default. This was an +// inappropriate value for defining the MSB_MASK default value. Any +// ideas? The workaround is a pretty severe restriction for OSF/1. +// DJT +// #if defined (__osf__) +// #define NFDBITS 32 +// #endif + class ACE_Export ACE_Handle_Set { // = TITLE @@ -71,7 +81,7 @@ public: private: int size_; - // Size of the set, i.e., a count of the number of enabled bits. + // Size of the set. ACE_HANDLE max_handle_; // Current max handle. @@ -88,7 +98,7 @@ private: NBITS = 256 }; - int count_bits (u_long n) const; + int count_bits (unsigned long n) const; // Counts the number of bits enabled in N. Uses a table lookup to // speed up the count. @@ -101,22 +111,17 @@ private: class ACE_Export ACE_Handle_Set_Iterator // = TITLE - // Iterator for the <ACE_Handle_Set> abstraction. + // Iterator for the ACE_Handle_Set abstraction. { public: - ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs); + ACE_Handle_Set_Iterator (const ACE_Handle_Set &); // Constructor. - ACE_HANDLE operator () (void); - // "Next" operator. Returns the next unseen <ACE_HANDLE> in the - // <Handle_Set> up to <handle_set_.max_handle_>). When all the - // handles have been seen returns <ACE_INVALID_HANDLE>. Advances - // the iterator automatically, so you need not call <operator++> - // (which is now obsolete). + ACE_HANDLE operator ()(void); + // "Next" operator. void operator++ (void); - // This is a no-op and no longer does anything. It's only here for - // backwards compatibility. + // Advance by "one." void dump (void) const; // Dump the state of an object. @@ -128,16 +133,16 @@ private: const ACE_Handle_Set &handles_; // The <Handle_Set> we are iterating through. - int handle_index_; - // Index of the bit we're examining in the current <word_num_> word. + int num_; + // Number of the word we're iterating on. - int word_num_; - // Number of the word we're iterating over (typically between 0..7). + size_t index_; + // Index of the current <num_> word. #if !defined (ACE_WIN32) - fd_mask word_val_; - // Value of the bits in the word we're iterating on. + fd_mask val_; #endif /* ACE_WIN32 */ + // Value of the bits in the word we're iterating on. }; #if defined (__ACE_INLINE__) diff --git a/ace/Handle_Set.i b/ace/Handle_Set.i index e6d9265076d..d7577404ea3 100644 --- a/ace/Handle_Set.i +++ b/ace/Handle_Set.i @@ -41,7 +41,7 @@ ACE_Handle_Set::set_bit (ACE_HANDLE handle) if (!this->is_set (handle)) { #if defined(ACE_WIN32) - FD_SET ((SOCKET) handle, &this->mask_); + FD_SET ((SOCKET)handle, &this->mask_); #else /* !ACE_WIN32 */ FD_SET (handle, &this->mask_); this->size_++; @@ -77,7 +77,7 @@ ACE_INLINE int ACE_Handle_Set::num_set (void) const { ACE_TRACE ("ACE_Handle_Set::num_set"); -#if defined (ACE_WIN32) +#if defined(ACE_WIN32) return this->mask_.fd_count; #else /* !ACE_WIN32 */ return this->size_; @@ -97,108 +97,11 @@ ACE_INLINE ACE_HANDLE ACE_Handle_Set_Iterator::operator () (void) { ACE_TRACE ("ACE_Handle_Set_Iterator::operator"); -#if defined (ACE_WIN32) - if (this->handle_index_ < this->handles_.mask_.fd_count) - // Return the handle and advance the iterator. - return (ACE_HANDLE) this->handles_.mask_.fd_array[this->handle_index_++]; - else - return ACE_INVALID_HANDLE; - +#if defined(ACE_WIN32) + return this->index_ < this->handles_.mask_.fd_count + ? (ACE_HANDLE)this->handles_.mask_.fd_array[this->index_] + : ACE_INVALID_HANDLE; #else /* !ACE_WIN32 */ - // No sense searching further than the max_handle_ + 1; - ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1; - - if (this->handle_index_ >= maxhandlep1) - // We've seen all the handles we're interested in seeing for this - // iterator. - return ACE_INVALID_HANDLE; - else - { - ACE_HANDLE result = this->handle_index_; - - // Increment the iterator. - this->handle_index_++; - this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK; - - // If've examined all the bits in this word, we'll go onto the - // next word. - - if (this->word_val_ == 0) - { - // Loop until we've found the first non-zero bit or we run - // past the <maxhandlep1> of the bitset. - while (this->handle_index_ < maxhandlep1 - && this->handles_.mask_.fds_bits[++this->word_num_] == 0) - this->handle_index_ += ACE_Handle_Set::WORDSIZE; - - // If the bit index becomes >= the maxhandlep1 that means - // there weren't any more bits set that we want to consider. - // Therefore, we'll just store the maxhandlep1, which will - // cause <operator()> to return <ACE_INVALID_HANDLE> - // immediately next time it's called. - if (this->handle_index_ >= maxhandlep1) - { - this->handle_index_ = maxhandlep1; - return result; - } - else - // Load the bits of the next word. - this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_]; - } - - // Loop until we get <word_val_> to have its least significant - // bit enabled, keeping track of which <handle_index> this - // represents (this information is used by subsequent calls to - // <operator()>). - - for (; - ACE_BIT_DISABLED (this->word_val_, 1); - this->handle_index_++) - this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK; - - return result; - } + return this->num_ <= this->handles_.max_handle_ ? this->num_ : -1; #endif /* ACE_WIN32 */ } - -ACE_INLINE void -ACE_Handle_Set_Iterator::operator++ (void) -{ - ACE_TRACE ("ACE_Handle_Set_Iterator::operator++"); - - // This is now a no-op. -} - -ACE_INLINE -ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator (const ACE_Handle_Set &hs) - : handles_ (hs), - handle_index_ (0), - word_num_ (-1) -{ - ACE_TRACE ("ACE_Handle_Set_Iterator::ACE_Handle_Set_Iterator"); -#if !defined(ACE_WIN32) - // No sense searching further than the max_handle_ + 1; - ACE_HANDLE maxhandlep1 = this->handles_.max_handle_ + 1; - - // Loop until we've found the first non-zero bit or we run past the - // <maxhandlep1> of the bitset. - while (this->handle_index_ < maxhandlep1 - && this->handles_.mask_.fds_bits[++this->word_num_] == 0) - this->handle_index_ += ACE_Handle_Set::WORDSIZE; - - // If the bit index becomes >= the maxhandlep1 that means there weren't - // any bits set. Therefore, we'll just store the maxhandlep1, which will - // cause <operator()> to return <ACE_INVALID_HANDLE> immediately. - if (this->handle_index_ >= maxhandlep1) - this->handle_index_ = maxhandlep1; - else - // Loop until we get <word_val_> to have its least significant bit - // enabled, keeping track of which <handle_index> this represents - // (this information is used by <operator()>). - for (this->word_val_ = this->handles_.mask_.fds_bits[this->word_num_]; - ACE_BIT_DISABLED (this->word_val_, 1) - && this->handle_index_ < maxhandlep1; - this->handle_index_++) - this->word_val_ = (this->word_val_ >> 1) & ACE_MSB_MASK; -#endif /* !ACE_WIN32 */ -} diff --git a/ace/IOStream.cpp b/ace/IOStream.cpp index 4737cf6318a..8f9ceb042e7 100644 --- a/ace/IOStream.cpp +++ b/ace/IOStream.cpp @@ -4,10 +4,10 @@ #if !defined (ACE_IOSTREAM_C) #define ACE_IOSTREAM_C -#if !defined (ACE_LACKS_ACE_IOSTREAM) - #define ACE_BUILD_DLL #include "ace/IOStream.h" +#include "ace/Thread.h" +#include "ace/Handle_Set.h" /////////////////////////////////////////////////////////////////////////// @@ -42,7 +42,7 @@ // invokes iostream::operator>> (int&) then iostream::operator>> (String&) // // What has happened is that the first >> is invoked on the base class and returns - // a reference to iostream. The second >> has no idea of the ACE_IOStream_T and + // a reference to iostream. The second >> has no idea of the ACE_IOStream and // gets invoked on iostream. Probably NOT what you wanted! @@ -84,8 +84,10 @@ // a myiostream&, the second >> will be invoked as desired. */ -ACE_Time_Value * -ACE_Streambuf::recv_timeout (ACE_Time_Value * tv) +#if ! defined (ACE_IOSTREAM_BUILDING_TEMPLATE) + +ACE_Time_Value * +ACE_Streambuf_T::recv_timeout (ACE_Time_Value * tv) { ACE_Time_Value * rval = recv_timeout_; if (tv) @@ -100,7 +102,7 @@ ACE_Streambuf::recv_timeout (ACE_Time_Value * tv) } int -ACE_Streambuf::underflow (void) +ACE_Streambuf_T::underflow (void) { // If input mode is not set, any attempt to read from the stream is // a failure. @@ -219,7 +221,7 @@ ACE_Streambuf::underflow (void) // rather than repeating a lot of what you've already seen. int -ACE_Streambuf::overflow (int c) +ACE_Streambuf_T::overflow (int c) { // Check to see if output is allowed at all. if (! (mode_ & ios::out)) @@ -289,7 +291,7 @@ ACE_Streambuf::overflow (int c) // syncin int -ACE_Streambuf::syncin (void) +ACE_Streambuf_T::syncin (void) { // As discussed, there really isn't any way to sync input from a socket-like // device. We specifially override this base-class function so that it won't @@ -300,7 +302,7 @@ ACE_Streambuf::syncin (void) // syncout int -ACE_Streambuf::syncout (void) +ACE_Streambuf_T::syncout (void) { // Unlike syncin, syncout is a doable thing. All we have to do is // write whatever is in the output buffer to the peer. flushbuf () @@ -313,7 +315,7 @@ ACE_Streambuf::syncout (void) } int -ACE_Streambuf::sync (void) +ACE_Streambuf_T::sync (void) { // sync () is fairly traditional in that it syncs both input and output. // We could have omitted the call to syncin () but someday, we may want it @@ -332,7 +334,7 @@ ACE_Streambuf::sync (void) // flushbuf int -ACE_Streambuf::flushbuf (void) +ACE_Streambuf_T::flushbuf (void) { // pptr () is one character beyond the last character put // into the buffer. pbase () points to the beginning of @@ -393,8 +395,8 @@ ACE_Streambuf::flushbuf (void) return 0; } -int -ACE_Streambuf::get_one_byte (void) +int +ACE_Streambuf_T::get_one_byte (void) { // The recv function will return immediately if there is no data // waiting. So, we use recv_n to wait for exactly one byte to come @@ -409,7 +411,7 @@ ACE_Streambuf::get_one_byte (void) } int -ACE_Streambuf::fillbuf (void) +ACE_Streambuf_T::fillbuf (void) // This will be called when the read (get) buffer has been // exhausted (ie -- gptr == egptr) { @@ -420,7 +422,7 @@ ACE_Streambuf::fillbuf (void) return EOF; // Now, get whatever else may be in the buffer. This will return if - // there is nothing in the buffer. + // there is nothing in the buffer. int bc = this->recv (base (), blen (), recv_timeout_); @@ -439,7 +441,7 @@ ACE_Streambuf::fillbuf (void) return bc; } -ACE_Streambuf::ACE_Streambuf (u_int streambuf_size, int io_mode) +ACE_Streambuf_T::ACE_Streambuf_T (u_int streambuf_size, int io_mode) : eback_saved_ (0), // to avoid Purify UMR pbase_saved_ (0), // to avoid Purify UMR get_mode_ (1), @@ -452,26 +454,26 @@ ACE_Streambuf::ACE_Streambuf (u_int streambuf_size, int io_mode) (void)reset_put_buffer (); } -u_int ACE_Streambuf::streambuf_size (void) +u_int ACE_Streambuf_T::streambuf_size (void) { return streambuf_size_; } -u_int ACE_Streambuf::get_waiting (void) +u_int ACE_Streambuf_T::get_waiting (void) // Return the number of bytes not yet gotten. // eback + get_waiting = gptr { return this->gptr_saved_ - this->eback_saved_; } -u_int ACE_Streambuf::get_avail (void) +u_int ACE_Streambuf_T::get_avail (void) // Return the number of bytes in the get area (includes some already gotten); // eback + get_avail = egptr { return this->egptr_saved_ - this->eback_saved_; } -u_int ACE_Streambuf::put_avail (void) +u_int ACE_Streambuf_T::put_avail (void) // Return the number of bytes to be 'put' onto the stream media. // pbase + put_avail = pptr { @@ -479,7 +481,7 @@ u_int ACE_Streambuf::put_avail (void) } char * -ACE_Streambuf::reset_get_buffer (char * newBuffer, u_int _streambuf_size, u_int _gptr, u_int _egptr) +ACE_Streambuf_T::reset_get_buffer (char * newBuffer, u_int _streambuf_size, u_int _gptr, u_int _egptr) // // Typical usage: // @@ -534,7 +536,7 @@ ACE_Streambuf::reset_get_buffer (char * newBuffer, u_int _streambuf_size, u_int } char * -ACE_Streambuf::reset_put_buffer (char * newBuffer, u_int _streambuf_size, u_int _pptr) +ACE_Streambuf_T::reset_put_buffer (char * newBuffer, u_int _streambuf_size, u_int _pptr) // // Typical usage: // @@ -582,7 +584,7 @@ ACE_Streambuf::reset_put_buffer (char * newBuffer, u_int _streambuf_size, u_int } void -ACE_Streambuf::reset_base (void) +ACE_Streambuf_T::reset_base (void) { // Until we experience the first get or put operation, we do not // know what our current IO mode is. @@ -600,12 +602,191 @@ ACE_Streambuf::reset_base (void) // would be deleted when the object destructs. Since we are providing // separate read/write buffers, it is up to us to manage their memory. -ACE_Streambuf::~ACE_Streambuf (void) +ACE_Streambuf_T::~ACE_Streambuf_T (void) { delete [] this->eback_saved_; delete [] this->pbase_saved_; } -#endif /* !ACE_LACKS_ACE_IOSTREAM */ +#endif // ACE_IOSTREAM_BUILDING_TEMPLATE + +/////////////////////////////////////////////////////////////////////////// + + +// We will be given a STREAM by the iostream object which creates us. +// See the ACE_IOStream template for how that works. Like other +// streambuf objects, we can be input-only, output-only or both. + +template <class STREAM> +ACE_Streambuf<STREAM>::ACE_Streambuf (STREAM *peer, u_int streambuf_size, int io_mode) + : ACE_Streambuf_T (streambuf_size, io_mode), peer_ (peer) +{ + // A streambuf allows for unbuffered IO where every character is + // read as requested and written as provided. To me, this seems + // terribly inefficient for socket-type operations, so I've disabled + // it. All of the work would be done by the underflow/overflow + // functions anyway and I haven't implemented anything there to + // support unbuffered IO. + + this->unbuffered (0); + + // Linebuffered is similar to unbuffered. Again, I don't have any + // need for this and I don't see the advantage. I believe this + // would have to be supported by underflow/overflow to be effective. +#if !defined (ACE_LACKS_LINEBUFFERED_STREAMBUF) + this->linebuffered (0); +#endif /* ! ACE_LACKS_LINEBUFFERED_STREAMBUF */ + +} + + +/////////////////////////////////////////////////////////////////////////// + + +// The typical constructor. This will initiailze your STREAM and then +// setup the iostream baseclass to use a custom streambuf based on +// STREAM. + +template <class STREAM> +ACE_IOStream<STREAM>::ACE_IOStream (STREAM & stream, u_int streambuf_size) + : iostream (streambuf_ = new ACE_Streambuf<STREAM> ((STREAM *) this, streambuf_size)), + STREAM (stream) +{ + iostream::init (this->streambuf_); +} + +template <class STREAM> +ACE_IOStream<STREAM>::ACE_IOStream (u_int streambuf_size) + : iostream (streambuf_ = new ACE_Streambuf<STREAM> ((STREAM *) this, streambuf_size)) +{ + iostream::init (this->streambuf_); +} + +// We have to get rid of the streambuf_ ourselves since we gave it to +// iostream () + +template <class STREAM> +ACE_IOStream<STREAM>::~ACE_IOStream (void) +{ + delete this->streambuf_; +} + +// The only ambituity in the multiple inheritance is the close () +// function. + +template <class STREAM> int +ACE_IOStream<STREAM>::close (void) +{ + return STREAM::close (); +} + +template <class STREAM> ACE_IOStream<STREAM> & +ACE_IOStream<STREAM>::operator>> (ACE_Time_Value *& tv) +{ + ACE_Time_Value * old_tv = this->streambuf_->recv_timeout (tv); + tv = old_tv; + return *this; +} + +#if defined (ACE_HAS_STRING_CLASS) +// A simple string operator. The base iostream has 'em for char* but +// that isn't always the best thing for a String. If we don't provide +// our own here, we may not get what we want. + +template <class STREAM> ACE_IOStream<STREAM> & +ACE_IOStream<STREAM>::operator>> (ACE_IOStream_String & v) +{ + if (ipfx0 ()) + { + char c; + iostream::operator>> (c); + + for (v = c ; this->get (c) && !isspace (c) ; v += c) + continue; + } + + isfx (); + + return *this; +} + + +template <class STREAM> ACE_IOStream<STREAM> & +ACE_IOStream<STREAM>::operator<< (ACE_IOStream_String & v) +{ + if (opfx ()) + { +#if defined (ACE_WIN32) + for (int i = 0 ; i < v.GetLength () ; ++i) +#else + for (u_int i = 0 ; i < (u_int) v.length () ; ++i) +#endif + this->put (v[i]); + } + + osfx (); + + return *this; +} + + +////////////////////////////////////////////////////////////////// +// A more clever put operator for strings that knows how to +// deal with quoted strings containing back-quoted quotes. +// +template <class STREAM> ACE_IOStream<STREAM> & +ACE_IOStream<STREAM>::operator>> (QuotedString & str) +{ + if (ipfx0 ()) + { + char c; + + if (! (*this >> c)) // eat space up to the first char + // this->set (ios::eofbit|ios::failbit); + return *this; + + str = ""; // Initialize the string + + // if we don't have a quote, append until we see space + if (c != '"') + for (str = c ; this->get (c) && !isspace (c) ; str += c) + continue; + else + for (; this->get (c) && c != '"' ; str += c) + if (c == '\\') + { + this->get (c); + if (c != '"') + str += '\\'; + } + } + + isfx (); + + return *this; +} + +template <class STREAM> ACE_IOStream<STREAM> & +ACE_IOStream<STREAM>::operator<< (QuotedString & str) +{ + if (opfx ()) + { + this->put ('"'); + for (u_int i = 0 ; i < str.length () ; ++i) + { + if (str[i] == '"') + this->put ('\\'); + this->put (str[i]); + } + this->put ('"'); + } + + osfx (); + + return *this; +} + +#endif /* ACE_HAS_STRING_CLASS */ #endif /* ACE_IOSTREAM_C */ + diff --git a/ace/IOStream.h b/ace/IOStream.h index 1a9ac2886a5..7603553178d 100644 --- a/ace/IOStream.h +++ b/ace/IOStream.h @@ -7,7 +7,7 @@ // ace // // = FILENAME -// IOStream.h +// iostream.h // // = AUTHOR // James CE Johnson <jcej@lads.com> @@ -20,7 +20,7 @@ /* Changes 4/5/97 - ACE_Streambuf + ACE_Streambuf_T New public functions added @@ -62,27 +62,26 @@ Constructor changed Initialization of the get/put buffers was moved here from - the derived class/template ACE_Streambuf_T<...> + the derived class/template ACE_Streambuf<...> At the same time, the new functions reset_get/put_buffer are now used instead of the previous monolithic function. - ACE_Streambuf_T<...> + ACE_Streambuf<...> Constructor changed: Initialization of the get/put buffers has been moved to the - baseclass ACE_Streambuf. This will reduce template bloat + baseclass ACE_Streambuf_T. This will reduce template bloat as well as giving us more functionality as described above. */ #if !defined (ACE_IOSTREAM_H) #define ACE_IOSTREAM_H -#if !defined (ACE_LACKS_ACE_IOSTREAM) - #include "ace/INET_Addr.h" #include "ace/Handle_Set.h" +#include <iomanip.h> #if defined (ACE_HAS_STRING_CLASS) #if defined (ACE_WIN32) @@ -105,15 +104,15 @@ public: inline QuotedString (void) { *this = ""; } inline QuotedString (const char * c) { *this = ACE_IOStream_String (c); } inline QuotedString (const ACE_IOStream_String& s) { *this = s; } - inline QuotedString& operator= (const ACE_IOStream_String& s) + inline QuotedString& operator= (const ACE_IOStream_String& s) { return (QuotedString&) ACE_IOStream_String::operator= (s); } inline QuotedString & operator = (const char c) { - return (QuotedString&) ACE_IOStream_String::operator= (c); + return (QuotedString&) ACE_IOStream_String::operator= (c); } - inline QuotedString & operator = (const char* c) { - return (QuotedString&) ACE_IOStream_String::operator= (c); + inline QuotedString & operator = (const char* c) { + return (QuotedString&) ACE_IOStream_String::operator= (c); } inline bool operator < (const QuotedString& s) const { return *(ACE_IOStream_String *) this < (ACE_IOStream_String) s; @@ -127,7 +126,7 @@ public: /////////////////////////////////////////////////////////////////////////// -class ACE_Export ACE_Streambuf : public streambuf +class ACE_Export ACE_Streambuf_T : public streambuf // = TITLE // Create your custom streambuf by providing and ACE_*_Stream // object to this template. I have tested it with @@ -191,7 +190,7 @@ class ACE_Export ACE_Streambuf : public streambuf { public: - virtual ~ACE_Streambuf (void); + virtual ~ACE_Streambuf_T (void); // If the default allocation strategey were used the common buffer // would be deleted when the object destructs. Since we are // providing separate read/write buffers, it is up to us to manage @@ -233,7 +232,7 @@ public: // Query the streambuf for the size of it's buffers. protected: - ACE_Streambuf (u_int streambuf_size, int io_mode); + ACE_Streambuf_T (u_int streambuf_size, int io_mode); virtual int sync (void); // Sync both input and output. See syncin/syncout below for @@ -323,6 +322,47 @@ protected: /////////////////////////////////////////////////////////////////////////// +template <class STREAM> +class ACE_Streambuf : public ACE_Streambuf_T +{ +public: + ACE_Streambuf (STREAM * peer, u_int streambuf_size = ACE_STREAMBUF_SIZE, int io_mode = ios::in | ios::out); + // We will be given a STREAM by the iostream object which creates + // us. See the ACE_IOStream template for how that works. Like + // other streambuf objects, we can be input-only, output-only or + // both. + + virtual ssize_t send ( char * buf, ssize_t len ) + { + return peer_->send_n(buf,len); + } + virtual ssize_t recv ( char * buf, ssize_t len, ACE_Time_Value * tv = NULL ) + { + return this->recv( buf, len, 0, tv ); + } + virtual ssize_t recv ( char * buf, ssize_t len, int flags, ACE_Time_Value * tv = NULL ) + { + ssize_t rval = peer_->recv(buf,len,flags,tv); + return rval; + } + virtual ssize_t recv_n( char * buf, ssize_t len, int flags = 0, ACE_Time_Value * tv = NULL ) + { + ssize_t rval = peer_->recv_n(buf,len,flags,tv); + return rval; + } + +protected: + STREAM * peer_; + // This will be our ACE_SOCK_Stream or similar object. + + virtual ACE_HANDLE get_handle(void) + { + return peer_ ? peer_->get_handle() : 0 ; + } +}; + +/////////////////////////////////////////////////////////////////////////// + // These typedefs are provided by G++ (on some systems?) without the // trailing '_'. Since we can't count on 'em, I've defined them to // what GNU wants here. @@ -402,8 +442,8 @@ typedef ostream& (*__omanip_)(ostream&); PUT_PROT(MT,char,CODE) \ PUT_PROT(MT,u_char,CODE) \ PUT_PROT(MT,const char *,CODE) \ - PUT_PROT(MT,u_char *,CODE) \ - PUT_PROT(MT,void *,CODE) \ + PUT_PROT(MT,const u_char *,CODE) \ + PUT_PROT(MT,const void *,CODE) \ inline virtual MT& operator<<(__omanip_ func) CODE2 \ inline virtual MT& operator<<(__manip_ func) CODE2 @@ -438,9 +478,212 @@ typedef ostream& (*__omanip_)(ostream&); /////////////////////////////////////////////////////////////////////////// -// Include the templates here. -#include "ace/IOStream_T.h" +template <class STREAM> +class ACE_IOStream : public iostream, public STREAM + // = TITLE + // A template adapter for creating an iostream-like object using + // an ACE IPC Stream for the actual I/O. Iostreams use an + // underlying streambuf object for the IO interface. The + // iostream class and derivatives provide you with a host of + // convenient operators that access the streambuf. + // + // = DESCRIPTION + // We inherit all characteristics of iostream and your <STREAM> + // class. When you create a new class from this template, you + // can use it anywhere you would have used your original + // <STREAM> class. + // + // To create an iostream for your favorite ACE IPC class (e.g., + // <ACE_SOCK_Stream>), feed that class to this template's + // <STREAM> parameter, e.g., + // + // typedef ACE_Svc_Handler<ACE_SOCK_iostream, + // ACE_INET_Addr, ACE_NULL_SYNCH> + // Service_Handler; + // + // Because the operators in the iostream class are not virtual, + // you cannot easily provide overloads in your custom + // ACE_IOStream classes. To make these things work correctly, + // you need to overload ALL operators of the ACE_IOStream you + // create. I've attempted to do that here to make things easier + // for you but there are no guarantees. + // + // In the iostream.cpp file is an example of why it is necessary + // to overload all of the get/put operators when you want to + // customize only one or two. +{ +public: + ACE_IOStream (STREAM & stream, u_int streambuf_size = ACE_STREAMBUF_SIZE); + ACE_IOStream (u_int streambuf_size = ACE_STREAMBUF_SIZE); + // The default constructor. This will initiailze your STREAM and + // then setup the iostream baseclass to use a custom streambuf based + // on STREAM. + + virtual ~ACE_IOStream (void); + // We have to get rid of the streambuf_ ourselves since we gave it + // to iostream(); + + virtual int close (void); + // The only ambituity in the multiple inheritance is the close() + // function. + +#if defined (ACE_HAS_STRING_CLASS) + virtual ACE_IOStream<STREAM> & operator>>(ACE_IOStream_String & v); + // A simple string operator. The base iostream has 'em for char* + // but that isn't always the best thing for a String. If we don't + // provide our own here, we may not get what we want. + + virtual ACE_IOStream<STREAM> & operator<<(ACE_IOStream_String & v); + // The converse of the String put operator. -#endif /* !ACE_LACKS_ACE_IOSTREAM */ + virtual ACE_IOStream<STREAM> & operator>>(QuotedString &v); + // A more clever operator that handles quoted strings so that we + // can get strings containing whitespace! + + virtual ACE_IOStream<STREAM> & operator<<(QuotedString &v); + // The converse of the QuotedString put operator. +#endif /* ACE_HAS_STRING_CLASS */ + + // = Using the macros to provide get/set operators. +#if !defined (ACE_LACKS_IOSTREAM_SETGET) + GETPUT_FUNC_SET (ACE_IOStream<STREAM>) +#endif /* ACE_LACKS_IOSTREAM_SETSET */ + +#if defined (ACE_LACKS_IOSTREAM_FX) + virtual int ipfx (int need = 0) { return good(); } + virtual int ipfx0(void) { return good(); } // Optimized ipfx(0) + virtual int ipfx1(void) { return good(); } // Optimized ipfx(1) + virtual void isfx (void) { return; } + virtual int opfx (void) { return good(); } + virtual void osfx (void) { put(' '); return; } +#else +#if defined (__GNUC__) + virtual int ipfx0(void) { return(iostream::ipfx0()); } // Optimized ipfx(0) + virtual int ipfx1(void) { return(iostream::ipfx1()); } // Optimized ipfx(1) +#else + virtual int ipfx0(void) { return(iostream::ipfx(0)); } + virtual int ipfx1(void) { return(iostream::ipfx(1)); } +#endif + virtual int ipfx (int need = 0) { return(iostream::ipfx(need)); } + virtual void isfx (void) { iostream::isfx(); return; } + virtual int opfx (void) { return(iostream::opfx()); } + virtual void osfx (void) { iostream::osfx(); return; } +#endif /* ACE_LACKS_IOSTREAM_FX */ + + ACE_IOStream<STREAM> & operator>>(ACE_Time_Value *&tv); + // Allow the programmer to provide a timeout for read operations. + // Give it a pointer to NULL to block forever. + +protected: + + ACE_Streambuf<STREAM> *streambuf_; + // This is where all of the action takes place. The + // streambuf_ is the interface to the underlying STREAM. + +private: + // We move these into the private section so that they cannot + // be used by the application programmer. This is necessary + // because streambuf_ will be buffering IO on the STREAM + // object. If these functions were used in your program, + // there is a danger of getting the datastream out of sync. + ssize_t send (...); + ssize_t recv (...); + ssize_t send_n (...); + ssize_t recv_n (...); +}; + +/////////////////////////////////////////////////////////////////////////// + +template <class STREAM> +class ACE_SOCK_Dgram_SC : public STREAM +// Datagrams don't have the notion of a "peer". Each send and receive +// on a datagram can go to a different peer if you want. If you're +// using datagrams for stream activity, you probably want 'em all to +// go to (and come from) the same place. That's what this class is +// for. BTW: 'Dgram_SC' is short for 'Datagram-Self-Contained'. +// Here, we keep an address object so that we can remember who last +// sent us data. When we write back, we're then able to write back to +// that same address. +{ +protected: + ACE_INET_Addr peer_; + +public: + ACE_SOCK_Dgram_SC (void) + { + } + + ACE_SOCK_Dgram_SC (STREAM &source, ACE_INET_Addr &dest) + : STREAM (source), peer_ (dest) + { + } + + inline ssize_t send_n (char *buf, ssize_t len) + { + return STREAM::send (buf, len, peer_); + } + + inline ssize_t recv (char * buf, ssize_t len, ACE_Time_Value * tv = NULL) + { + return recv (buf, len, 0, tv); + } + + inline ssize_t recv (char * buf, ssize_t len, int flags, ACE_Time_Value * tv = NULL) + { + if (tv != 0) + { + ACE_HANDLE handle = this->get_handle (); + ACE_Handle_Set handle_set; + + handle_set.set_bit (handle); + + switch (ACE_OS::select (int (handle) + 1, + (fd_set *) handle_set, // read_fds. + (fd_set *) 0, // write_fds. + (fd_set *) 0, // exception_fds. + tv)) + { + case 0: + errno = ETIME; + case -1: + return -1; + default: + ; // Do the 'recv' below + } + } + + int rval = STREAM::recv (buf, len, peer_, flags); +#ifdef WIN32 + if (rval == SOCKET_ERROR) + if (WSAGetLastError() == WSAEMSGSIZE) + if (flags & MSG_PEEK) + rval = len; +#endif + + return rval < len ? rval : len; + } + inline ssize_t recv_n (char * buf, + ssize_t len, int flags = 0, + ACE_Time_Value * tv = NULL) + { + int rval = this->recv (buf, len, flags, tv); + return rval; + } + + inline int get_remote_addr (ACE_INET_Addr &addr) const + { + addr = peer_; + return 0; + } + +}; + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +# if ! defined( ACE_IOSTREAM_C ) +# define ACE_IOSTREAM_BUILDING_TEMPLATE +# endif +# include "ace/IOStream.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ #endif /* ACE_IOSTREAM_H */ + diff --git a/ace/Local_Tokens.h b/ace/Local_Tokens.h index 3cd9c688b0f..5663e0913d0 100644 --- a/ace/Local_Tokens.h +++ b/ace/Local_Tokens.h @@ -641,6 +641,7 @@ private: // Name of the token. }; + // 7.. class ACE_Export ACE_Token_Proxy // = TITLE diff --git a/ace/Local_Tokens_T.cpp b/ace/Local_Tokens_T.cpp index 1be17133702..c28e62feb31 100644 --- a/ace/Local_Tokens_T.cpp +++ b/ace/Local_Tokens_T.cpp @@ -1,7 +1,6 @@ // Local_Tokens_T.cpp // $Id$ -#if 0 #if !defined (ACE_LOCAL_TOKENS_T_C) #define ACE_LOCAL_TOKENS_T_C @@ -54,4 +53,3 @@ ACE_Token_Name<TYPE>::dump (void) const } #endif /* ACE_LOCAL_TOKENS_T_C */ -#endif /* 0 */ diff --git a/ace/Local_Tokens_T.h b/ace/Local_Tokens_T.h index a47651eeaa8..c8a5f21db2a 100644 --- a/ace/Local_Tokens_T.h +++ b/ace/Local_Tokens_T.h @@ -1,6 +1,7 @@ /* -*- C++ -*- */ // $Id$ + // ============================================================================ // // = LIBRARY @@ -20,7 +21,6 @@ // // ============================================================================ -#if 0 #if !defined (ACE_LOCAL_TOKENS_T_H) #define ACE_LOCAL_TOKENS_T_H @@ -93,4 +93,3 @@ private: #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ #endif /* ACE_LOCAL_TOKENS_T_H */ -#endif /* 0 */ diff --git a/ace/Local_Tokens_T.i b/ace/Local_Tokens_T.i index eb356d1ae9a..1eb8881a464 100644 --- a/ace/Local_Tokens_T.i +++ b/ace/Local_Tokens_T.i @@ -2,7 +2,6 @@ // $Id$ // Local_Tokens_T.i -#if 0 template <class TYPE> ACE_INLINE void ACE_Token_Name<TYPE>::operator= (const ACE_Token_Name<TYPE> &rhs) @@ -64,4 +63,3 @@ ACE_Token_Name<TYPE>::type (TYPE type) this->type_ = type; } -#endif /* 0 */ diff --git a/ace/Map_Manager.h b/ace/Map_Manager.h index d9d1ea56ea1..74ec2902f33 100644 --- a/ace/Map_Manager.h +++ b/ace/Map_Manager.h @@ -140,13 +140,11 @@ public: int unbind (const EXT_ID &ext_id); // Unbind (remove) the <ext_id> from the map. Don't return the // <int_id> to the caller (this is useful for collections where the - // <int_id>s are *not* dynamically allocated...) Returns 0 if - // successful, else -1. + // <int_id>s are *not* dynamically allocated...) int unbind (const EXT_ID &ext_id, INT_ID &int_id); - // Break any association of <ext_id>. Returns the value of <int_id> - // in case the caller needs to deallocate memory. Returns 0 if - // successful, else -1. + // Break any association of <ext_id>. Returns the value of <int_id> in + // case the caller needs to deallocate memory. size_t current_size (void); // Return the current size of the map. diff --git a/ace/OS.cpp b/ace/OS.cpp index 450c4d2f129..42e24c9a72a 100644 --- a/ace/OS.cpp +++ b/ace/OS.cpp @@ -466,19 +466,7 @@ int ACE_OS::sched_params (const ACE_Sched_Params &sched_params) { // ACE_TRACE ("ACE_OS::sched_params"); -#if defined (CHORUS) - int result; - struct sched_param param; - ACE_thread_t thr_id = ACE_OS::thr_self (); - - param.sched_priority = sched_params.priority (); - - ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam (thr_id, - sched_params.policy (), - ¶m), - result), - int, -1); -#elif defined (ACE_HAS_STHREADS) +#if defined (ACE_HAS_STHREADS) // Set priority class, priority, and quantum of this LWP or process as // specified in sched_params. @@ -643,6 +631,19 @@ ACE_OS::sched_params (const ACE_Sched_Params &sched_params) // Set the thread priority on the current thread. return ACE_OS::thr_setprio (sched_params.priority ()); + +#elif defined (CHORUS) + int result; + struct sched_param param; + ACE_thread_t thr_id = ACE_OS::thr_self (); + + param.sched_priority = sched_params.priority (); + + ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam (thr_id, + sched_params.policy (), + ¶m), + result), + int, -1); #else ACE_UNUSED_ARG (sched_params); ACE_NOTSUP_RETURN (-1); @@ -1280,14 +1281,6 @@ ACE_OS::thr_create (ACE_THR_FUNC func, stacksize = ACE_NEEDS_HUGE_THREAD_STACKSIZE; # endif /* ACE_NEEDS_HUGE_THREAD_STACKSIZE */ -# if defined (CHORUS) - // if it is a super actor, we can't set stacksize. - // But for the time bing we are all non-super actors - // To be fixed later - if (stacksize == 0) - stacksize = 0x100000; -# endif /*CHORUS */ - if (stacksize != 0) { size_t size = stacksize; @@ -1455,6 +1448,7 @@ ACE_OS::thr_create (ACE_THR_FUNC func, if (priority != ACE_DEFAULT_THREAD_PRIORITY) { struct sched_param sparam; + ACE_OS::memset ((void *) &sparam, 0, sizeof sparam); # if defined (ACE_HAS_DCETHREADS) && !defined (ACE_HAS_SETKIND_NP) @@ -1479,42 +1473,32 @@ ACE_OS::thr_create (ACE_THR_FUNC func, sparam.sched_priority = priority; # endif -# if defined (ACE_HAS_FSU_PTHREADS) - if (sparam.sched_priority >= PTHREAD_MIN_PRIORITY - && sparam.sched_priority <= PTHREAD_MAX_PRIORITY) - attr.prio = sparam.sched_priority; - else - { - pthread_attr_destroy (&attr); - errno = EINVAL; - return -1; - } -# else - { -# if defined (ACE_HAS_STHREADS) - // Solaris POSIX only allows priorities > 0 to - // ::pthread_attr_setschedparam. If a priority of 0 was - // requested, set the thread priority after creating it, below. - if (priority > 0) -# endif /* STHREADS */ - { +# if !defined (ACE_HAS_FSU_PTHREADS) + int retval = 0; # if defined (ACE_HAS_SETKIND_NP) - result = ::pthread_attr_setsched (&attr, SCHED_OTHER); + retval = ::pthread_attr_setsched (&attr, SCHED_OTHER); # else /* ACE_HAS_SETKIND_NP */ - result = ::pthread_attr_setschedparam (&attr, &sparam); + retval = ::pthread_attr_setschedparam (&attr, &sparam); # endif /* ACE_HAS_SETKIND_NP */ - if (result != 0) - { + if (retval != 0) + { # if defined (ACE_HAS_SETKIND_NP) - ::pthread_attr_delete (&attr); + ::pthread_attr_delete (&attr); # else /* ACE_HAS_SETKIND_NP */ - ::pthread_attr_destroy (&attr); + ::pthread_attr_destroy (&attr); # endif /* ACE_HAS_SETKIND_NP */ - errno = result; - return -1; - } - } - } + errno = retval; + return -1; + } +# else + if (sparam.sched_priority >= PTHREAD_MIN_PRIORITY + && sparam.sched_priority <= PTHREAD_MAX_PRIORITY) + attr.prio = sparam.sched_priority; + else + { + pthread_attr_destroy (&attr); + return -1; + } # endif /* ACE_HAS_FSU_PTHREADS */ } @@ -1600,46 +1584,6 @@ ACE_OS::thr_create (ACE_THR_FUNC func, // ACE_thread_t and ACE_hthread_t are the same. if (result != -1) *thr_handle = *thr_id; - - // If the priority is 0, then we might have to set it now because we couldn't - // set it with ::pthread_attr_setschedparam, as noted above. This doesn't - // provide strictly correct behavior, because the thread was created - // (above) with the priority of its parent. (That applies regardless - // of the inherit_sched attribute: if it was PTHREAD_INHERIT_SCHED, then - // it certainly inherited its parent's priority. If it was - // PTHREAD_EXPLICIT_SCHED, then "attr" was initialized by the Solaris - // ::pthread_attr_init () to contain NULL for the priority, which indicated - // to Solaris ::pthread_create () to inherit the parent priority.) - if (priority == 0) - { - // Check the priority of this thread, which is the parent of the - // newly created thread. If it is 0, then the newly created thread - // will have inherited the priority of 0, so there's no need to - // explicitly set it. - struct sched_param sparam; - int policy = 0; - ACE_OSCALL (ACE_ADAPT_RETVAL (::pthread_getschedparam (thr_self (), - &policy, - &sparam), - result), int, - -1, result); - - if (sparam.sched_priority != 0) - { - ACE_OS::memset ((void *) &sparam, 0, sizeof sparam); - // The memset to 0 sets the priority to 0, so we don't need - // to explicitly set sparam.sched_priority. - - // The only policy currently (version 2.5.1) supported by by Solaris - // is SCHED_OTHER, so that's hard-coded below. - ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::pthread_setschedparam ( - *thr_id, - SCHED_OTHER, - &sparam), - result), - int, -1); - } - } # else *thr_handle = ACE_OS::NULL_hthread; # endif /* ACE_HAS_STHREADS */ @@ -1659,28 +1603,15 @@ ACE_OS::thr_create (ACE_THR_FUNC func, if (result != -1) { - // With Solaris threads, ACE_thread_t and ACE_hthread_t are the same. - *thr_handle = *thr_id; - if (priority != ACE_DEFAULT_THREAD_PRIORITY) { // Set the priority of the new thread and then let it // continue, but only if the user didn't start it suspended // in the first place! - if ((result = ACE_OS::thr_setprio (*thr_id, priority)) != 0) - { - errno = result; - return -1; - } + ACE_OS::thr_setprio (*thr_handle, priority); if (start_suspended == 0) - { - if ((result = ACE_OS::thr_continue (*thr_id)) != 0) - { - errno = result; - return -1; - } - } + ACE_OS::thr_continue (*thr_handle); } } return result; @@ -190,6 +190,7 @@ private: #define ACE_MAX(x,y) (((x)>(y))?(x):(y)) #define ACE_MIN(x,y) (((x)<(y))?(x):(y)) + // keep the compiler from complaining of // parameters which are not used. #if defined (ghs) @@ -1072,11 +1073,7 @@ typedef pthread_mutex_t ACE_thread_mutex_t; # endif /* ACE_HAS_DCETHREADS */ # define THR_BOUND 0x00000001 -# if defined (CHORUS) -# define THR_NEW_LWP 0x00000000 -# else # define THR_NEW_LWP 0x00000002 -# endif /* CHORUS */ # define THR_DETACHED 0x00000040 # define THR_SUSPENDED 0x00000080 # define THR_DAEMON 0x00000100 @@ -1520,9 +1517,6 @@ struct utsname #define ACE_DEFAULT_GLOBALNAME_A "\\globalnames" #define ACE_DEFAULT_GLOBALNAME_W L"\\globalnames" -// Need to work around odd glitches with NT. -#define ACE_MAX_DEFAULT_PORT 65279 - // We're on WinNT or Win95 #define ACE_PLATFORM_A "Win32" #define ACE_PLATFORM_EXE_SUFFIX_A ".exe" @@ -1741,9 +1735,6 @@ typedef char TCHAR; #define RUSAGE_SELF 1 #endif /* m88k */ -// Default port is MAX_SHORT. -#define ACE_MAX_DEFAULT_PORT 65535 - // Default semaphore key #define ACE_DEFAULT_SEM_KEY 1234 #define ACE_INVALID_SEM_KEY -1 @@ -2085,9 +2076,6 @@ extern "C" #if defined (ACE_HAS_STHREADS) #include /**/ <sys/priocntl.h> -#if defined (ACE_LACKS_PRI_T) -typedef int pri_t; -#endif /* ACE_LACKS_PRI_T */ typedef id_t ACE_id_t; typedef pri_t ACE_pri_t; #else @@ -2572,13 +2560,6 @@ struct ACE_Export ACE_Str_Buf : public strbuf // Constructor. }; -#if defined (ACE_HAS_BROKEN_BITSHIFT) -#define ACE_MSB_MASK (~(ACE_UINT32 (1) << ACE_UINT32 (NFDBITS - 1))) -#else -// This needs to go here to avoid overflow problems on some compilers. -#define ACE_MSB_MASK (~(1 << (NFDBITS - 1))) -#endif /* ACE_HAS_BROKEN_BITSHIFT */ - class ACE_Export ACE_OS // = TITLE // This class defines an operating system independent @@ -2733,14 +2714,9 @@ public: #undef getpwnam_r #endif /* ACE_HAS_BROKEN_R_ROUTINES */ -#if defined (difftime) -#define ACE_DIFFTIME(t1, t0) difftime(t1,t0) -#undef difftime -#endif /* difftime */ - // = A set of wrappers for operations on time. - static double difftime (time_t t1, time_t t0); static time_t time (time_t *tloc); + static double difftime (time_t t1, time_t t0); static time_t mktime (struct tm *timeptr); static struct tm *localtime (const time_t *clock); static struct tm *localtime_r (const time_t *clock, struct tm *res); @@ -912,12 +912,11 @@ ACE_OS::unlink (const char *path) #endif /* VXWORKS */ } - ACE_INLINE char * ACE_OS::tempnam (const char *dir, const char *pfx) { // ACE_TRACE ("ACE_OS::tempnam"); -#if defined (VXWORKS) || defined (ACE_LACKS_TEMPNAM) +#if defined (VXWORKS) ACE_NOTSUP_RETURN (0); #else #if defined (WIN32) @@ -928,7 +927,6 @@ ACE_OS::tempnam (const char *dir, const char *pfx) #endif /* VXWORKS */ } - ACE_INLINE LPTSTR ACE_OS::cuserid (LPTSTR user, size_t maxlen) { @@ -4154,16 +4152,9 @@ ACE_OS::thr_min_stack (void) // ACE_TRACE ("ACE_OS::thr_min_stack"); #if defined (ACE_HAS_THREADS) #if defined (ACE_HAS_STHREADS) -#if defined (ACE_HAS_THR_MINSTACK) - // Tandem did some weirdo mangling of STHREAD names... - ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_minstack (), - ace_result_), - int, -1); -#else ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_min_stack (), - ace_result_), - int, -1); -#endif /* !ACE_HAS_THR_MINSTACK */ + ace_result_), + int, -1); #elif (defined (ACE_HAS_DCETHREADS) || defined (ACE_HAS_PTHREADS)) && !defined (ACE_HAS_SETKIND_NP) #if defined (ACE_HAS_IRIX62_THREADS) return (size_t) ACE_OS::sysconf (_SC_THREAD_STACK_MIN); @@ -5087,13 +5078,6 @@ ACE_OS::dlsym (void *handle, ACE_DL_TYPE symbolname) #if defined (ACE_HAS_SVR4_DYNAMIC_LINKING) #if defined (ACE_LACKS_POSIX_PROTO) ACE_OSCALL_RETURN (::dlsym (handle, (char*) symbolname), void *, 0); -#elif defined (ACE_USES_ASM_SYMBOL_IN_DLSYM) - char asm_symbolname [MAXPATHLEN] ; - if (strlen (symbolname) + 2 > sizeof asm_symbolname) - return 0 ; - ACE_OS::strcpy (asm_symbolname, "_") ; - ACE_OS::strcpy (asm_symbolname + 1, symbolname) ; - ACE_OSCALL_RETURN (::dlsym (handle, asm_symbolname), void *, 0); #else ACE_OSCALL_RETURN (::dlsym (handle, symbolname), void *, 0); #endif /* ACE_LACKS_POSIX_PROTO */ @@ -5665,18 +5649,12 @@ ACE_OS::open (const char *filename, #endif /* ACE_WIN32 */ } - ACE_INLINE double ACE_OS::difftime (time_t t1, time_t t0) { -#if defined (ACE_DIFFTIME) - return ACE_DIFFTIME(t1, t0); -#else return ::difftime (t1, t0); -#endif /* ACE_DIFFTIME */ } - ACE_INLINE char * ACE_OS::ctime (const time_t *t) { @@ -6415,7 +6393,7 @@ ACE_OS::sleep (u_int seconds) #if defined (ACE_WIN32) ::Sleep (seconds * 1000); return 0; -#elif defined (ACE_HAS_CLOCK_GETTIME) +#elif defined (VXWORKS) struct timespec rqtp; // Initializer doesn't work with Green Hills 1.8.7 rqtp.tv_sec = seconds; @@ -6855,14 +6833,8 @@ ACE_OS::sigaddset (sigset_t *s, int signum) #if !defined (ACE_LACKS_SIGSET) ACE_OSCALL_RETURN (::sigaddset (s, signum), int, -1); #else - if (s == NULL) { - errno = EFAULT ; - return -1 ; - } - if (signum < 1 || signum > NSIG) { - errno = EINVAL ; - return -1 ; // Invalid signum, return error - } + if (signum < 1 || signum > NSIG) + return 1 ; // Invalid signum, return error *s |= (1 << (signum - 1)) ; return 0 ; #endif /* !ACE_LACKS_SIGSET */ @@ -6874,14 +6846,8 @@ ACE_OS::sigdelset (sigset_t *s, int signum) #if !defined (ACE_LACKS_SIGSET) ACE_OSCALL_RETURN (::sigdelset (s, signum), int, -1); #else - if (s == NULL) { - errno = EFAULT ; - return -1 ; - } - if (signum < 1 || signum > NSIG) { - errno = EINVAL ; - return -1 ; // Invalid signum, return error - } + if (signum < 1 || signum > NSIG) + return 1 ; // Invalid signum, return error *s &= ~(1 << (signum - 1)) ; return 0 ; #endif /* !ACE_LACKS_SIGSET */ @@ -6893,10 +6859,6 @@ ACE_OS::sigemptyset (sigset_t *s) #if !defined (ACE_LACKS_SIGSET) ACE_OSCALL_RETURN (::sigemptyset (s), int, -1); #else - if (s == NULL) { - errno = EFAULT ; - return -1 ; - } *s = 0 ; return 0 ; #endif /* !ACE_LACKS_SIGSET */ @@ -6908,10 +6870,6 @@ ACE_OS::sigfillset (sigset_t *s) #if !defined (ACE_LACKS_SIGSET) ACE_OSCALL_RETURN (::sigfillset (s), int, -1); #else - if (s == NULL) { - errno = EFAULT ; - return -1 ; - } *s = ~(sigset_t) 0 ; return 0 ; #endif /* !ACE_LACKS_SIGSET */ @@ -6923,14 +6881,8 @@ ACE_OS::sigismember (sigset_t *s, int signum) #if !defined (ACE_LACKS_SIGSET) ACE_OSCALL_RETURN (::sigismember (s, signum), int, -1); #else - if (s == NULL) { - errno = EFAULT ; - return -1 ; - } - if (signum < 1 || signum > NSIG) { - errno = EINVAL ; - return -1 ; // Invalid signum, return error - } + if (signum < 1 || signum > NSIG) + return 1 ; // Invalid signum, return error return ((*s & (1 << (signum - 1))) != 0) ; #endif /* !ACE_LACKS_SIGSET */ } diff --git a/ace/Process.cpp b/ace/Process.cpp index 3e6dd376221..8f71a7c2941 100644 --- a/ace/Process.cpp +++ b/ace/Process.cpp @@ -280,6 +280,8 @@ ACE_Process::spawn (ACE_Process_Options &options) // Server process. The fork succeeded. return this->child_id_; } + + return 0; #endif /* ACE_WIN32 */ } @@ -633,7 +635,7 @@ ACE_Process_Options::command_line_argv (void) return command_line_argv_; } -char * const * +char ** ACE_Process_Options::env_argv (void) { return environment_argv_; diff --git a/ace/Process.h b/ace/Process.h index 6295c606a63..cd3ef49cba4 100644 --- a/ace/Process.h +++ b/ace/Process.h @@ -137,7 +137,7 @@ public: // and returned with each entry pointing to the start of // null-terminated string. Returns { 0 } if nothing has been set. - char * const *env_argv (void); + char **env_argv (void); // argv-style array of environment settings. // = Accessors for the standard handles. diff --git a/ace/README b/ace/README index 18e453add2f..6f7f7c56e43 100644 --- a/ace/README +++ b/ace/README @@ -57,7 +57,6 @@ ACE_HAS_IP_MULTICAST Platform supports IP multicast ACE_HAS_IRIX_GETTIMEOFDAY Denotes that IRIX 5.3 has second argument to gettimeofday() which is variable ... ACE_HAS_IRIX62_THREADS Platform supports the very odd IRIX 6.2 threads... ACE_HAS_THR_KEYDELETE Platform supports thr_keydelete (e.g,. UNIXWARE) -ACE_HAS_THR_MINSTACK Platform calls thr_minstack() rather than thr_min_stack() (e.g., Tandem). ACE_HAS_LIMITED_RUSAGE_T The rusage_t structure has only two fields. ACE_HAS_LONGLONG_T Compiler/platform supports the "long long" datatype. ACE_HAS_LONG_MAP_FAILED Platform defines MAP_FAILED as a long constant. @@ -163,7 +162,6 @@ ACE_HAS_XLI Platform has the XLI version of TLI ACE_HAS_XT Platform has Xt and Motif ACE_HAS_YIELD_VOID_PTR Platform requires pthread_yield() to take a NULL. ACE_LACKS_ACCESS Platform lacks access() (e.g., VxWorks and Chorus) -ACE_LACKS_ACE_IOSTREAM Platform can not build ace/IOStream{,_T}.cpp. This does not necessarily mean that the platform does not support iostreams. ACE_LACKS_CONST_STRBUF_PTR Platform uses struct strbuf * rather than const struct strbuf * (e.g., HP/UX 10.x) ACE_LACKS_CONST_TIMESPEC_PTR Platform forgot const in cond_timewait (e.g., HP/UX). ACE_LACKS_COND_T Platform lacks condition variables (e.g., Win32 and VxWorks) @@ -172,6 +170,7 @@ ACE_LACKS_EXEC Platform lacks the exec() family of system calls (e.g., Win32, ACE_LACKS_FILELOCKS Platform lacks file locking mechanism ACE_LACKS_GETPGID Platform lacks getpgid() call (e.g., Win32, Chorus, and FreeBSD). ACE_LACKS_GETSERVBYNAME Platforms lacks getservbyname() (e.g., VxWorks and Chorus). +ACE_LACKS_IOSTREAM_SETGET Platforms lacks IOStream get/set operators (e.g., SGI IRIX 6.2). ACE_LACKS_IOSTREAM_FX iostream header does not declare ipfx (), opfx (), etc. ACE_LACKS_LINEBUFFERED_STREAMBUF Platform lacks streambuf "linebuffered ()". ACE_LACKS_MADVISE Platform lacks madvise() (e.g., Linux) @@ -189,7 +188,6 @@ ACE_LACKS_NETDB_REENTRANT_FUNCTIONS Platform does not support reentrant netdb fu ACE_LACKS_RPC_H Platform lacks the ONC RPC header files. ACE_LACKS_PARAM_H Platform lacks <sys/param.h> (e.g., MVS) ACE_LACKS_POSIX_PROTO Platform lacks POSIX prototypes for certain System V functions like shared memory and message queues. -ACE_LACKS_PRI_T Platform lacks pri_t (e.g., Tandem NonStop UNIX). ACE_LACKS_PTHREAD_CANCEL Platform lacks pthread_cancel(). ACE_LACKS_PTHREAD_THR_SIGSETMASK Platform lacks pthread_thr_sigsetmask (e.g., MVS, HP/UX, and OSF/1 3.2) ACE_LACKS_PWD_REENTRANT_FUNCTIONS Platform lacks getpwnam_r() methods (e.g., SGI 6.2). @@ -240,7 +238,6 @@ ACE_TEMPLATES_REQUIRE_PRAGMA Compiler's template mechanism must use a pragma Th ACE_TEMPLATES_REQUIRE_SOURCE Compiler's template mechanim must see source code (i.e., .cpp files). This is used for GNU G++. ACE_TEMPLATES_REQUIRE_SPECIALIZATION Compiler's template mechanism requires the use of explicit C++ specializations for all used templates. This is also used for GNU G++ if you don't use the "repo" patches. ACE_USE_POLL Use the poll() event demultiplexor rather than select(). -ACE_USES_ASM_SYMBOL_IN_DLSYM Platform uses assembly symbols instead of C symbols in dlsym() ACE_WSOCK_VERSION A parameter list indicating the version of WinSock (e.g., "1, 1" is version 1.1). ---------------------------------------- diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp index 0ccb58321c6..70b04a8a371 100644 --- a/ace/Reactor.cpp +++ b/ace/Reactor.cpp @@ -212,7 +212,7 @@ ACE_Reactor_Handler_Repository::bind (ACE_HANDLE handle, break; } // Here's the first free slot, so let's take it. - else if (ACE_REACTOR_HANDLE (i) == ACE_INVALID_HANDLE + else if (ACE_REACTOR_EVENT_HANDLER (this, i) == ACE_INVALID_HANDLE && assigned_slot == -1) assigned_slot = i; } @@ -1031,9 +1031,9 @@ ACE_Reactor::remove_handler_i (const ACE_Handle_Set &handles, ACE_TRACE ("ACE_Reactor::remove_handler_i"); ACE_HANDLE h; - ACE_Handle_Set_Iterator handle_iter (handles); - - while ((h = handle_iter ()) != ACE_INVALID_HANDLE) + for (ACE_Handle_Set_Iterator handle_iter (handles); + (h = handle_iter ()) != ACE_INVALID_HANDLE; + ++handle_iter) if (this->remove_handler_i (h, mask) == -1) return -1; @@ -1048,8 +1048,9 @@ ACE_Reactor::register_handler_i (const ACE_Handle_Set &handles, ACE_TRACE ("ACE_Reactor::register_handler_i"); ACE_HANDLE h; - ACE_Handle_Set_Iterator handle_iter (handles); - while ((h = handle_iter ()) != ACE_INVALID_HANDLE) + for (ACE_Handle_Set_Iterator handle_iter (handles); + (h = handle_iter ()) != ACE_INVALID_HANDLE; + ++handle_iter) if (this->register_handler_i (h, handler, mask) == -1) return -1; @@ -1426,15 +1427,16 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles, { ACE_HANDLE handle; - // Handle output events (this code needs to come first to handle - // the obscure case of piggy-backed data coming along with the - // final handshake message of a nonblocking connection). - - ACE_Handle_Set_Iterator handle_iter_wr (dispatch_set.wr_mask_); + // Handle output events (this code needs to come first + // to handle the obscure case of piggy-backed data + // coming along with the final handshake message of a + // nonblocking connection). - while ((handle = handle_iter_wr ()) != ACE_INVALID_HANDLE + for (ACE_Handle_Set_Iterator handle_iter_wr (dispatch_set.wr_mask_); + (handle = handle_iter_wr ()) != ACE_INVALID_HANDLE && number_dispatched < number_of_active_handles - && this->state_changed_ == 0) + && this->state_changed_ == 0; + ++handle_iter_wr) { number_dispatched++; this->notify_handle (handle, @@ -1459,12 +1461,11 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles, ACE_HANDLE handle; // Handle "exceptional" events. - - ACE_Handle_Set_Iterator handle_iter_ex (dispatch_set.ex_mask_); - - while ((handle = handle_iter_ex ()) != ACE_INVALID_HANDLE + for (ACE_Handle_Set_Iterator handle_iter_ex (dispatch_set.ex_mask_); + (handle = handle_iter_ex ()) != ACE_INVALID_HANDLE && number_dispatched < number_of_active_handles - && this->state_changed_ == 0) + && this->state_changed_ == 0; + ++handle_iter_ex) { this->notify_handle (handle, ACE_Event_Handler::EXCEPT_MASK, @@ -1474,7 +1475,6 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles, number_dispatched++; } } - if (number_dispatched > 0) { number_of_active_handles -= number_dispatched; @@ -1489,12 +1489,11 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles, ACE_HANDLE handle; // Handle input, passive connection, and shutdown events. - - ACE_Handle_Set_Iterator handle_iter_rd (dispatch_set.rd_mask_); - - while ((handle = handle_iter_rd ()) != ACE_INVALID_HANDLE + for (ACE_Handle_Set_Iterator handle_iter_rd (dispatch_set.rd_mask_); + (handle = handle_iter_rd ()) != ACE_INVALID_HANDLE && number_dispatched < number_of_active_handles - && this->state_changed_ == 0) + && this->state_changed_ == 0; + ++handle_iter_rd) { this->notify_handle (handle, ACE_Event_Handler::READ_MASK, @@ -1504,11 +1503,9 @@ ACE_Reactor::dispatch_io_handlers (int &number_of_active_handles, number_dispatched++; } } - if (number_dispatched > 0) { number_of_active_handles -= number_dispatched; - if (this->state_changed_) return -1; } @@ -1572,7 +1569,7 @@ ACE_Reactor::dispatch (int number_of_active_handles, break; // State has changed, exit inner loop. else if (this->dispatch_io_handlers (number_of_active_handles, dispatch_set) == -1) - // State has changed, so exit the inner loop. + // State has changed exit inner loop. break; } diff --git a/ace/Sched_Params.cpp b/ace/Sched_Params.cpp index a6e5553f71e..35b7bcdf5cf 100644 --- a/ace/Sched_Params.cpp +++ b/ace/Sched_Params.cpp @@ -63,11 +63,17 @@ ACE_Sched_Params::priority_min (const Policy policy, // pcinfo.pc_clinfo)->ts_maxupri. The minimum priority is just // the negative of that. - return -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri; + int priority = -((tsinfo_t *) pcinfo.pc_clinfo)->ts_maxupri; + + // Don't return priority of 0, because that can't be used with + // ::pthread_attr_setschedparam on Solaris 2.5.1. + return priority == 0 ? 1 : 0; } else { - return 0; + // Don't return priority of 0, because that can't be used with + // ::pthread_attr_setschedparam on Solaris 2.5.1. + return 1; } #elif defined (ACE_HAS_DCETHREADS) || defined(ACE_HAS_PTHREADS) && !defined(ACE_LACKS_SETSCHED) @@ -80,9 +86,7 @@ ACE_Sched_Params::priority_min (const Policy policy, return ACE_THR_PRI_FIFO_MIN; case ACE_SCHED_RR: return ACE_THR_PRI_RR_MIN; -#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value - case ACE_SCHED_OTHER: -#endif /* CHORUS */ + case ACE_SCHED_OTHER: default: return ACE_THR_PRI_OTHER_MIN; } @@ -95,9 +99,7 @@ ACE_Sched_Params::priority_min (const Policy policy, return ACE_PROC_PRI_FIFO_MIN; case ACE_SCHED_RR: return ACE_PROC_PRI_RR_MIN; -#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value - case ACE_SCHED_OTHER: -#endif /* CHORUS */ + case ACE_SCHED_OTHER: default: return ACE_PROC_PRI_OTHER_MIN; } @@ -162,9 +164,7 @@ ACE_Sched_Params::priority_max (const Policy policy, return ACE_THR_PRI_FIFO_MAX; case ACE_SCHED_RR: return ACE_THR_PRI_RR_MAX; -#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value - case ACE_SCHED_OTHER: -#endif /* CHORUS */ + case ACE_SCHED_OTHER: default: return ACE_THR_PRI_OTHER_MAX; } @@ -177,9 +177,7 @@ ACE_Sched_Params::priority_max (const Policy policy, return ACE_PROC_PRI_FIFO_MAX; case ACE_SCHED_RR: return ACE_PROC_PRI_RR_MAX; -#if !defined (CHORUS) // SCHED_OTHRE and SCHED_RR have same value - case ACE_SCHED_OTHER: -#endif /* CHORUS */ + case ACE_SCHED_OTHER: default: return ACE_PROC_PRI_OTHER_MAX; } diff --git a/ace/Thread_Manager.h b/ace/Thread_Manager.h index b5d96080c9b..ac486095846 100644 --- a/ace/Thread_Manager.h +++ b/ace/Thread_Manager.h @@ -289,7 +289,7 @@ protected: ACE_Task_Base *task = 0); // Create a new thread (must be called with locks held). -protected: +private: int resize (size_t); // Resize the pool of Thread_Descriptors. diff --git a/ace/config-chorus.h b/ace/config-chorus.h index ea98287a098..7008b8a62c6 100644 --- a/ace/config-chorus.h +++ b/ace/config-chorus.h @@ -33,7 +33,6 @@ // got struct timespec #define ACE_HAS_POSIX_TIME -#define ACE_HAS_CLOCK_GETTIME #define ACE_LACKS_STRRECVFD #define ACE_HAS_CPLUSPLUS_HEADERS @@ -48,8 +47,7 @@ // Platforms lacks UNIX domain sockets. #define ACE_LACKS_UNIX_DOMAIN_SOCKETS #define ACE_LACKS_UTSNAME_T -#define ACE_HAS_PTHREADS_1003_DOT_1C -//#define ACE_LACKS_SETSCHED +#define ACE_LACKS_SETSCHED #define ACE_LACKS_MSYNC #define ACE_LACKS_MADVISE diff --git a/ace/config-freebsd-pthread.h b/ace/config-freebsd-pthread.h index 9708973eda4..d1e1311cdc7 100644 --- a/ace/config-freebsd-pthread.h +++ b/ace/config-freebsd-pthread.h @@ -1,5 +1,5 @@ /* -*- C++ -*- */ -// $Id$ +// config-freebsd-pthread.h // ***** This configuration file is still under debugging. ***** // ***** It still doesn't work quite the way it expected to. ***** @@ -22,18 +22,6 @@ #define ACE_LACKS_GETPGID #define ACE_LACKS_RWLOCK_T #define ACE_HAS_SIG_MACROS -#define ACE_HAS_CHARPTR_DL -#define ACE_USES_ASM_SYMBOL_IN_DLSYM - -// sched.h still not fully support on FreeBSD ? -// this is taken from /usr/src/lib/libc_r/uthread/pthread-private.h -enum schedparam_policy { - SCHED_RR, - SCHED_IO, - SCHED_FIFO, - SCHED_OTHER -}; - // Platform supports POSIX timers via timestruct_t. #define ACE_HAS_POSIX_TIME #define ACE_NEEDS_SYSTIME_H diff --git a/ace/config-freebsd.h b/ace/config-freebsd.h index 5b9e8c426c7..7c81d324656 100644 --- a/ace/config-freebsd.h +++ b/ace/config-freebsd.h @@ -22,8 +22,6 @@ #define ACE_LACKS_GETPGID #define ACE_LACKS_RWLOCK_T #define ACE_HAS_SIG_MACROS -#define ACE_HAS_CHARPTR_DL -#define ACE_USES_ASM_SYMBOL_IN_DLSYM // This is for 2.1.x only. By default, gcc defines __FreeBSD__ automatically #if defined(FreeBSD_2_1) diff --git a/ace/config-hpux-9.x-orbix.h b/ace/config-hpux-9.x-orbix.h index 4a3395e01d3..8684a385aab 100644 --- a/ace/config-hpux-9.x-orbix.h +++ b/ace/config-hpux-9.x-orbix.h @@ -90,8 +90,6 @@ // Platform has the XLI version of ACE_TLI. // #define ACE_HAS_XLI -#define ACE_LACKS_ACE_IOSTREAM - #define ACE_NEEDS_DEV_IO_CONVERSION // Turns off the tracing feature. diff --git a/ace/config-hpux-9.x.h b/ace/config-hpux-9.x.h index 6ec331e3dee..43ba829af2e 100644 --- a/ace/config-hpux-9.x.h +++ b/ace/config-hpux-9.x.h @@ -16,9 +16,7 @@ #define ACE_HAS_BROKEN_HPUX_TEMPLATES #endif /* __cplusplus < 199707L */ -#define ACE_HAS_BROKEN_ENUMS -#define ACE_HAS_IP_MULTICAST -#define ACE_LACKS_GETPGID +#define ACE_HAS_BROKEN_ENUM #define ACE_HAS_BROKEN_CONVERSIONS // They forgot a const in the prototype of const_timewait... @@ -89,8 +87,6 @@ // Platform has the XLI version of ACE_TLI. // #define ACE_HAS_XLI -#define ACE_LACKS_ACE_IOSTREAM - #define ACE_NEEDS_DEV_IO_CONVERSION // Turns off the tracing feature. diff --git a/ace/config-irix6.2-sgic++-nothreads.h b/ace/config-irix6.2-sgic++-nothreads.h index 60cfbb2d61f..bed586602ab 100644 --- a/ace/config-irix6.2-sgic++-nothreads.h +++ b/ace/config-irix6.2-sgic++-nothreads.h @@ -17,7 +17,7 @@ // Include XtReactor into the library. #define ACE_HAS_XT -#define ACE_LACKS_SIGNED_CHAR +#define ACE_LACKS_IOSTREAM_SETGET // Platform supports getpagesize() call. #define ACE_HAS_GETPAGESIZE diff --git a/ace/config-irix6.2-sgic++.h b/ace/config-irix6.2-sgic++.h index a82bddb1c63..d60e0e9c3c0 100644 --- a/ace/config-irix6.2-sgic++.h +++ b/ace/config-irix6.2-sgic++.h @@ -13,7 +13,7 @@ #if !defined (ACE_CONFIG_H) #define ACE_CONFIG_H -#define ACE_LACKS_SIGNED_CHAR +#define ACE_LACKS_IOSTREAM_SETGET #define ACE_HAS_P_READ_WRITE #define ACE_HAS_IRIX62_THREADS #define ACE_HAS_PTHREAD_SIGMASK diff --git a/ace/config-vxworks-g++.h b/ace/config-vxworks-g++.h deleted file mode 100644 index 72218a1e6c7..00000000000 --- a/ace/config-vxworks-g++.h +++ /dev/null @@ -1,78 +0,0 @@ -Return-Path: ace@svappl36.mdc.com -Delivery-Date: Thu, 24 Oct 1996 10:50:14 -0500 -Return-Path: ace@svappl36.mdc.com -Return-Path: <ace@svappl36.mdc.com> -Received: from svmail01.mdc.com by cs.wustl.edu (SMI-8.6/ECL-J1.00) - id KAA03041; Thu, 24 Oct 1996 10:50:01 -0500 -Received: from svappl36 (SVAPPL36.MDC.COM) by svmail01.mdc.com with SMTP - (1.37.109.11/16.2) id AA215472200; Thu, 24 Oct 1996 10:50:00 -0500 -Received: from huskers by svappl36 (5.x/SMI-SVR4) - id AA25932; Thu, 24 Oct 1996 10:49:09 -0500 -Received: by huskers (SMI-8.6/SMI-SVR4) - id KAA26789; Thu, 24 Oct 1996 10:49:27 -0500 -Date: Thu, 24 Oct 1996 10:49:27 -0500 -From: ace@svappl36.mdc.com (Adaptive Comm Env) -Message-Id: <199610241549.KAA26789@huskers> -Content-Type: text -Apparently-To: levine@cs.wustl.edu -content-length: 1599 - -// The following configuration file is designed to work for VxWorks -// 5.2 platforms using the GNU g++ 2.7.2 compiler, without repo patch - -#if !defined (ACE_CONFIG_H) -#define ACE_CONFIG_H - -#define ACE_HAS_BROKEN_SENDMSG -#define ACE_HAS_BROKEN_WRITEV -#define ACE_HAS_CHARPTR_SOCKOPT -#define ACE_HAS_CONSISTENT_SIGNAL_PROTOTYPES -#define ACE_HAS_CPLUSPLUS_HEADERS -#define ACE_HAS_GNU_CSTRING_H -#define ACE_HAS_GREENHILLS_SOCKETS -#define ACE_HAS_MSG -#define ACE_HAS_MT_SAFE_SOCKETS -#define ACE_HAS_POSIX_NONBLOCK -#define ACE_HAS_POSIX_SEM -#define ACE_HAS_POSIX_TIME -#define ACE_HAS_SIG_ATOMIC_T -#define ACE_HAS_SIGINFO_T -#define ACE_HAS_SIGWAIT -#define ACE_HAS_THREADS -#define ACE_LACKS_MADVISE -#define ACE_LACKS_MALLOC_H -#define ACE_LACKS_MKTEMP -#define ACE_LACKS_MMAP -#define ACE_LACKS_MSYNC -#define ACE_LACKS_PARAM_H -#define ACE_LACKS_RLIMIT -#define ACE_LACKS_SBRK -#define ACE_LACKS_SEMBUF_T -#define ACE_LACKS_SIGINFO_H -#define ACE_LACKS_SI_ADDR -#define ACE_LACKS_SOCKETPAIR -#define ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES -#define ACE_LACKS_STRRECVFD -#define ACE_LACKS_SYSCALL -#define ACE_LACKS_SYSV_SHMEM -#define ACE_LACKS_UCONTEXT_H -#define ACE_LACKS_UTSNAME_T -#define ACE_MT_SAFE -#define ACE_TEMPLATES_REQUIRE_SOURCE -#define ACE_TEMPLATES_REQUIRE_SPECIALIZATION -#define SIGNAL_SAFE_OS_CALLS - -// Defines the page size of the system. -#define ACE_PAGE_SIZE 4096 - - -// vxWorks.h must be included before time.h, and key_t must be -// defined early also: these are here -// because Time_Value.h #includes ace/config.h, but not ace/OS.h -typedef int key_t; -#include <vxWorks.h> - - -#endif /* ACE_CONFIG_H */ - - diff --git a/apps/Gateway/Gateway/Channel.cpp b/apps/Gateway/Gateway/Channel.cpp deleted file mode 100644 index 99699a6ee87..00000000000 --- a/apps/Gateway/Gateway/Channel.cpp +++ /dev/null @@ -1,710 +0,0 @@ - -// $Id$ - -#include "Routing_Entry.h" -#include "Channel_Connector.h" - -// Convenient short-hands. -#define CO CONDITION -#define MU MUTEX - -// = The total number of bytes sent/received on this channel. -size_t -Channel::total_bytes (void) -{ - return this->total_bytes_; -} - -void -Channel::total_bytes (size_t bytes) -{ - this->total_bytes_ += bytes; -} - -Channel::Channel (ROUTING_TABLE *rt, - Channel_Connector *cc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : ACE_Svc_Handler<CHANNEL_PEER_STREAM, SYNCH> (thr_mgr), - routing_table_ (rt), - id_ (-1), - total_bytes_ (0), - state_ (Channel::IDLE), - connector_ (cc), - timeout_ (1), - max_timeout_ (Channel::MAX_RETRY_TIMEOUT), - socket_queue_size_ (socket_queue_size) -{ -} - -// Set the associated channel. - -void -Channel::active (int a) -{ - this->state (a == 0 ? Channel::IDLE : Channel::ESTABLISHED); -} - -// Get the associated channel. - -int -Channel::active (void) -{ - return this->state () == Channel::ESTABLISHED; -} - -// Set the direction. - -void -Channel::direction (char d) -{ - this->direction_ = d; -} - -// Get the direction. - -char -Channel::direction (void) -{ - return this->direction_; -} - -// Sets the timeout delay. - -void -Channel::timeout (int to) -{ - if (to > this->max_timeout_) - to = this->max_timeout_; - - this->timeout_ = to; -} - -// Recalculate the current retry timeout delay using exponential -// backoff. Returns the original timeout (i.e., before the -// recalculation). - -int -Channel::timeout (void) -{ - int old_timeout = this->timeout_; - this->timeout_ *= 2; - - if (this->timeout_ > this->max_timeout_) - this->timeout_ = this->max_timeout_; - - return old_timeout; -} - -// Sets the max timeout delay. - -void -Channel::max_timeout (int mto) -{ - this->max_timeout_ = mto; -} - -// Gets the max timeout delay. - -int -Channel::max_timeout (void) -{ - return this->max_timeout_; -} - -// Restart connection asynchronously when timeout occurs. - -int -Channel::handle_timeout (const ACE_Time_Value &, const void *) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) attempting to reconnect Channel %d with timeout = %d\n", - this->id (), this->timeout_)); - return this->connector_->initiate_connection (this, ACE_Synch_Options::asynch); -} - -// Restart connection (blocking_semantics dicates whether we -// restart synchronously or asynchronously). - -int -Channel::reinitiate_connection (void) -{ - // Skip over deactivated descriptors. - if (this->get_handle () != -1) - { - // Make sure to close down peer to reclaim descriptor. - this->peer ().close (); - -#if 0 -// if (this->state () == FAILED) -// { - // Reinitiate timeout to improve reconnection time. -// this->timeout (1); -#endif - - ACE_DEBUG ((LM_DEBUG, - "(%t) scheduling reinitiation of Channel %d\n", - this->id ())); - - // Reschedule ourselves to try and connect again. - if (ACE_Service_Config::reactor ()->schedule_timer (this, 0, - this->timeout ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - } - return 0; -} - -// Handle shutdown of the Channel object. - -int -Channel::handle_close (ACE_HANDLE, ACE_Reactor_Mask) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) shutting down Channel %d on handle %d\n", - this->id (), this->get_handle ())); - - return this->reinitiate_connection (); -} - -// Set the state of the channel. - -void -Channel::state (Channel::State s) -{ - this->state_ = s; -} - -// Perform the first-time initiation of a connection to the peer. - -int -Channel::initialize_connection (void) -{ - this->state_ = Channel::ESTABLISHED; - - // Restart the timeout to 1. - this->timeout (1); - -#if defined (ASSIGN_ROUTING_ID) - // Action that sends the route id to the peerd. - - CONN_ID id = htons (this->id ()); - - ssize_t n = this->peer ().send ((const void *) &id, sizeof id); - - if (n != sizeof id) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - n == 0 ? "gatewayd has closed down unexpectedly" : "send"), -1); -#endif /* ASSIGN_ROUTING_ID */ - return 0; -} - -// Set the size of the socket queue. - -void -Channel::socket_queue_size (void) -{ - if (this->socket_queue_size_ > 0) - { - int option = this->direction_ == 'I' ? SO_RCVBUF : SO_SNDBUF; - - if (this->peer ().set_option (SOL_SOCKET, option, - &this->socket_queue_size_, sizeof (int)) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "set_option")); - } -} - -// Upcall from the ACE_Acceptor::handle_input() that -// delegates control to our application-specific Channel. - -int -Channel::open (void *a) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) Channel's fd = %d\n", this->peer ().get_handle ())); - - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn on non-blocking I/O. - if (this->peer ().enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Call down to the base class to activate and register this handler. - if (this->ACE_Svc_Handler<CHANNEL_PEER_STREAM, SYNCH>::open (a) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "activate"), -1); - - return this->initialize_connection (); -} - -// Return the current state of the channel. - -Channel::State -Channel::state (void) -{ - return this->state_; -} - -void -Channel::id (CONN_ID id) -{ - this->id_ = id; -} - -CONN_ID -Channel::id (void) -{ - return this->id_; -} - -// Set the peer's address information. -int -Channel::bind (const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - CONN_ID id) -{ - this->remote_addr_ = remote_addr; - this->local_addr_ = local_addr; - this->id_ = id; - return 0; -} - -ACE_INET_Addr & -Channel::remote_addr (void) -{ - return this->remote_addr_; -} - -ACE_INET_Addr & -Channel::local_addr (void) -{ - return this->local_addr_; -} - -// Constructor sets the routing table pointer. - -Output_Channel::Output_Channel (ROUTING_TABLE *rt, - Channel_Connector *cc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : Channel (rt, cc, thr_mgr, socket_queue_size) -{ - this->direction_ = 'O'; - this->msg_queue ()->high_water_mark (Output_Channel::QUEUE_SIZE); -} - -// This method should be called only when the peer shuts down -// unexpectedly. This method simply marks the Channel as -// having failed so that handle_close () can reconnect. - -int -Output_Channel::handle_input (ACE_HANDLE) -{ - char buf[1]; - - this->state (Channel::FAILED); - - switch (this->peer ().recv (buf, sizeof buf)) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has failed unexpectedly for Output Channel %d\n", - this->id ()), -1); - /* NOTREACHED */ - case 0: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has shutdown unexpectedly for Output Channel %d\n", - this->id ()), -1); - /* NOTREACHED */ - default: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer is sending input on Output Channel %d\n", - this->id ()), -1); - /* NOTREACHED */ - } -} - -int -Output_Channel::svc (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, "(%t) svc should not be called on Output_Channel!\n"), -1); -} - -// Perform a non-blocking put() of message MB. If we are unable to -// send the entire message the remainder is re-queued at the *front* of -// the Message_List. - -int -Output_Channel::nonblk_put (ACE_Message_Block *mb) -{ - // Try to send the message. If we don't send it all (e.g., due to - // flow control), then re-queue the remainder at the head of the - // Message_List and ask the ACE_Reactor to inform us (via - // handle_output()) when it is possible to try again. - - ssize_t n; - - if ((n = this->send_peer (mb)) == -1) - { - // Things have gone wrong, let's try to close down and set up a new reconnection. - this->state (Channel::FAILED); - this->handle_close (); - return -1; - } - else if (errno == EWOULDBLOCK) // Didn't manage to send everything. - { - ACE_DEBUG ((LM_DEBUG, "(%t) queueing activated on handle %d to routing id %d\n", - this->get_handle (), this->id ())); - - // ACE_Queue in *front* of the list to preserve order. - if (this->msg_queue ()->enqueue_head (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enqueue_head"), -1); - - // Tell ACE_Reactor to call us back when we can send again. - else if (ACE_Service_Config::reactor ()-> - schedule_wakeup (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "schedule_wakeup"), -1); - return 0; - } - else - return n; -} - -int -Output_Channel::send_peer (ACE_Message_Block *mb) -{ - ssize_t n; - size_t len = mb->length (); - - if ((n = this->peer ().send (mb->rd_ptr (), len)) <= 0) - return errno == EWOULDBLOCK ? 0 : n; - else if (n < len) - // Re-adjust pointer to skip over the part we did send. - mb->rd_ptr (n); - else /* if (n == length) */ - { - // The whole message is sent, we can now safely deallocate the buffer. - // Note that this should decrement a reference count... - delete mb; - errno = 0; - } - this->total_bytes (n); - return n; -} - -// Finish sending a message when flow control conditions abate. -// This method is automatically called by the ACE_Reactor. - -int -Output_Channel::handle_output (ACE_HANDLE) -{ - ACE_Message_Block *mb = 0; - int status = 0; - - ACE_DEBUG ((LM_DEBUG, "(%t) in handle_output on handle %d\n", this->get_handle ())); - // The list had better not be empty, otherwise there's a bug! - - if (this->msg_queue ()->dequeue_head (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) != -1) - { - switch (this->nonblk_put (mb)) - { - case 0: // Partial send. - ACE_ASSERT (errno == EWOULDBLOCK); - // Didn't write everything this time, come back later... - break; - - case -1: - // Caller is responsible for freeing a ACE_Message_Block if failures occur. - delete mb; - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "transmission failure")); - - /* FALLTHROUGH */ - default: // Sent the whole thing. - - // If we succeed in writing the entire message (or we did not fail - // due to EWOULDBLOCK) then check if there are more messages on the Message_List. - // If there aren't, tell the ACE_Reactor not to notify us anymore (at least - // until there are new messages queued up). - - if (this->msg_queue ()->is_empty ()) - { - ACE_DEBUG ((LM_DEBUG, "(%t) queueing deactivated on handle %d to routing id %d\n", - this->get_handle (), this->id ())); - - - if (ACE_Service_Config::reactor ()-> - cancel_wakeup (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "cancel_wakeup")); - } - } - } - else - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "dequeue_head")); - return 0; -} - -// Send a message to a peer (may queue if necessary). - -int -Output_Channel::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - if (this->msg_queue ()->is_empty ()) - // Try to send the message *without* blocking! - return this->nonblk_put (mb); - else - // If we have queued up messages due to flow control - // then just enqueue and return. - return this->msg_queue ()->enqueue_tail (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Constructor sets the routing table pointer and the connector pointer. - -Input_Channel::Input_Channel (ROUTING_TABLE *rt, - Channel_Connector *cc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : msg_frag_ (0), - Channel (rt, cc, thr_mgr, socket_queue_size) -{ - this->direction_ = 'I'; - this->msg_queue ()->high_water_mark (0); -} - -int -Input_Channel::put (ACE_Message_Block *, ACE_Time_Value *) -{ - ACE_ERROR_RETURN ((LM_ERROR, "(%t) put should not be called on Input_Channel!\n"), -1); -} - -int -Input_Channel::svc (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, "(%t) svc should not be called on Input_Channel!\n"), -1); -} - -// Receive a Peer message from peerd. Handles fragmentation. -// -// The routing message returned from recv_peer consists of two parts: -// 1. The Address part, contains the virtual routing id. -// 2. The Data part, which contains the actual data to be routed. -// -// The reason for having two parts is to shield the higher layers -// of software from knowledge of the message structure. - -int -Input_Channel::recv_peer (ACE_Message_Block *&route_addr) -{ - Peer_Message *peer_msg; - size_t len; - ssize_t n = 0; - ssize_t m = 0; - size_t offset = 0; - - if (this->msg_frag_ == 0) - // No existing fragment... - ACE_NEW_RETURN (this->msg_frag_, - ACE_Message_Block (sizeof (Peer_Message)), - -1); - - peer_msg = (Peer_Message *) this->msg_frag_->rd_ptr (); - - const ssize_t HEADER_SIZE = sizeof (Peer_Header); - ssize_t header_bytes_left_to_read = HEADER_SIZE - this->msg_frag_->length (); - - if (header_bytes_left_to_read > 0) - { - n = this->peer ().recv (this->msg_frag_->wr_ptr (), header_bytes_left_to_read); - - if (n == -1 /* error */ - || n == 0 /* EOF */) - { - ACE_ERROR ((LM_ERROR, "%p\n", "Recv error during header read ")); - ACE_DEBUG ((LM_DEBUG, "attempted to read %d\n", header_bytes_left_to_read)); - delete this->msg_frag_; - this->msg_frag_ = 0; - return n; - } - - // Bump the write pointer by the amount read. - this->msg_frag_->wr_ptr (n); - - // At this point we may or may not have the ENTIRE header. - if (this->msg_frag_->length () < HEADER_SIZE) - { - ACE_DEBUG ((LM_DEBUG, "Partial header received: only %d bytes\n", - this->msg_frag_->length ())); - // Notify the caller that we didn't get an entire message. - errno = EWOULDBLOCK; - return -1; - } - } - - // At this point there is a complete, valid header in msg_frag_ - len = sizeof peer_msg->buf_ + HEADER_SIZE - this->msg_frag_->length (); - - // Try to receive the remainder of the message - - switch (m = this->peer ().recv (peer_msg->buf_ + offset, len)) - { - case -1: - if (errno == EWOULDBLOCK) - { - // This shouldn't happen since the ACE_Reactor - // just triggered us to handle pending I/O! - ACE_DEBUG ((LM_DEBUG, "(%t) unexpected recv failure\n")); - errno = EWOULDBLOCK; - return -1; - } - else - /* FALLTHROUGH */; - - case 0: // Premature EOF. - delete this->msg_frag_; - this->msg_frag_ = 0; - return 0; - - default: - if (m != len) - // Re-adjust pointer to skip over the part we've read. - { - this->msg_frag_->wr_ptr (m); - errno = EWOULDBLOCK; - return -1; // Inform caller that we didn't get the whole message. - } - else - { - // Set the write pointer at 1 past the end of the message. - this->msg_frag_->wr_ptr (m); - - // Set the read pointer to the beginning of the message. - this->msg_frag_->rd_ptr (this->msg_frag_->base ()); - - // Allocate a routing message header and chain the data portion - // onto its continuation field. - ACE_NEW_RETURN (route_addr, - ACE_Message_Block (sizeof (Peer_Addr), - ACE_Message_Block::MB_PROTO, - this->msg_frag_), - -1); - - Peer_Addr peer_addr (this->id (), peer_msg->header_.routing_id_, 0); - // Copy the routing address from the Peer_Message into routing_addr. - route_addr->copy ((char *) &peer_addr, sizeof (Peer_Addr)); - - // Reset the pointer to indicate we've got an entire message. - this->msg_frag_ = 0; - } - this->total_bytes (m + n); -#if defined (VERBOSE) - ACE_DEBUG ((LM_DEBUG, "(%t) channel id = %d, route id = %d, len = %d, payload = %*s", - peer_addr.conn_id_, peer_msg->header_.routing_id_, peer_msg->header_.len_, - peer_msg->header_.len_, peer_msg->buf_)); -#else - ACE_DEBUG ((LM_DEBUG, "(%t) route id = %d, cur len = %d, total bytes read = %d\n", - peer_msg->header_.routing_id_, peer_msg->header_.len_, this->total_bytes ())); -#endif - return m + n; - } -} - -// Receive various types of input (e.g., Peer message from the -// gatewayd, as well as stdio). - -int -Input_Channel::handle_input (ACE_HANDLE) -{ - ACE_Message_Block *route_addr = 0; - - switch (this->recv_peer (route_addr)) - { - case 0: - // Note that a peer should never initiate a shutdown. - this->state (Channel::FAILED); - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has closed down unexpectedly for Input Channel %d\n", - this->id ()), -1); - /* NOTREACHED */ - case -1: - if (errno == EWOULDBLOCK) - // A short-read, we'll come back and finish it up later on! - return 0; - else // A weird problem occurred, shut down and start again. - { - this->state (Channel::FAILED); - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p for Input Channel %d\n", - "Peer has failed unexpectedly", - this->id ()), -1); - } - /* NOTREACHED */ - default: - return this->route_message (route_addr); - } -} - -// Route a message to its appropriate destination. - -int -Input_Channel::route_message (ACE_Message_Block *route_addr) -{ - // We got a valid message, so determine its virtual routing id, - // which is stored in the first of the two message blocks chained together. - - Peer_Addr *routing_key = (Peer_Addr *) route_addr->rd_ptr (); - - // Skip over the address portion. - const ACE_Message_Block *const data = route_addr->cont (); - - // RE points to the routing entry located for this routing id. - Routing_Entry *re = 0; - - if (this->routing_table_->find (*routing_key, re) != -1) - { - // Check to see if there are any destinations. - if (re->destinations ()->size () == 0) - ACE_DEBUG ((LM_WARNING, - "there are no active destinations for this message currently\n")); - - else // There are destinations, so forward the message. - { - Routing_Entry::ENTRY_SET *esp = re->destinations (); - Routing_Entry::ENTRY_ITERATOR si (*esp); - - for (Channel **channel = 0; si.next (channel) != 0; si.advance ()) - { - // Only process active channels. - if ((*channel)->active ()) - { - // Clone the message portion (should be doing reference counting here...) - ACE_Message_Block *newmsg = data->clone (); - - ACE_DEBUG ((LM_DEBUG, "(%t) sending to peer %d\n", (*channel)->id ())); - - if ((*channel)->put (newmsg) == -1) - { - if (errno == EWOULDBLOCK) // The queue has filled up! - ACE_ERROR ((LM_ERROR, "(%t) %p\n", - "gateway is flow controlled, so we're dropping messages")); - else - ACE_ERROR ((LM_ERROR, "(%t) %p transmission error to route %d\n", - "put", (*channel)->id ())); - - // Caller is responsible for freeing a ACE_Message_Block if failures occur. - delete newmsg; - } - } - } - // Will become superfluous once we have reference counting... - delete route_addr; - return 0; - } - } - delete route_addr; - // Failure return. - ACE_ERROR ((LM_DEBUG, "(%t) find failed on conn id = %d, logical id = %d, payload = %d\n", - routing_key->conn_id_, routing_key->logical_id_, routing_key->payload_)); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Map_Manager<Peer_Addr, Routing_Entry *, MUTEX>; -template class ACE_Map_Iterator<Peer_Addr, Routing_Entry *, MUTEX>; -template class ACE_Map_Entry<Peer_Addr, Routing_Entry *>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/apps/Gateway/Gateway/Channel.h b/apps/Gateway/Gateway/Channel.h deleted file mode 100644 index 339716bc55a..00000000000 --- a/apps/Gateway/Gateway/Channel.h +++ /dev/null @@ -1,280 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Channel.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CHANNEL) -#define _CHANNEL - -#include "ace/Service_Config.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Connector.h" -#include "ace/Svc_Handler.h" -#include "Routing_Table.h" -#include "Routing_Entry.h" -#include "Peer_Message.h" - -// The following typedefs are used in order to parameterize the -// synchronization policies without changing the source code! - -// If we don't have threads then use the single-threaded synchronization. -#if !defined (ACE_HAS_THREADS) -#define SYNCH ACE_NULL_SYNCH -typedef ACE_Null_Mutex MUTEX; -#define CHANNEL_PEER_STREAM ACE_SOCK_STREAM -#define CHANNEL_PEER_CONNECTOR ACE_SOCK_CONNECTOR -#else /* ACE_HAS_THREADS */ - -// Select communication mechanisms. -#if 0 // defined (ACE_HAS_TLI) -// Note that due to inconsistencies between the semantics of sockets -// and TLI with respect to establishing non-blocking connections it's -// not a good idea to use TLI... -#include "ace/TLI_Connector.h" -#define CHANNEL_PEER_STREAM ACE_TLI_STREAM -#define CHANNEL_PEER_CONNECTOR ACE_TLI_CONNECTOR -#else -#define CHANNEL_PEER_STREAM ACE_SOCK_STREAM -#define CHANNEL_PEER_CONNECTOR ACE_SOCK_CONNECTOR -#endif /* 0 */ - -// Note that we only need to make the ACE_Task thread-safe if we -// are using the multi-threaded Thr_Output_Channel... -#if defined (USE_OUTPUT_MT) -#define SYNCH ACE_MT_SYNCH -#else -#define SYNCH ACE_NULL_SYNCH -#endif /* USE_OUTPUT_MT || USE_INPUT_MT */ - -// Note that we only need to make the ACE_Map_Manager thread-safe if -// we are using the multi-threaded Thr_Input_Channel... -#if defined (USE_INPUT_MT) -typedef ACE_RW_Mutex MUTEX; -#else -typedef ACE_Null_Mutex MUTEX; -#endif /* USE_INPUT_MT */ -#endif /* ACE_HAS_THREADS */ - -// Typedef for the routing table. -typedef Routing_Table<Peer_Addr, Routing_Entry, MUTEX> - ROUTING_TABLE; - -// Forward declaration. -class Channel_Connector; - -class Channel : public ACE_Svc_Handler<CHANNEL_PEER_STREAM, SYNCH> - // = TITLE - // Channel contains info about connection state and addressing. - // - // = DESCRIPTION - // The Channel classes process messages sent from the peers to the - // gateway. These classes works as follows: - // - // 1. Channel_Connector creates a number of connections with the set of - // peers specified in a configuration file. - // - // 2. For each peer that connects successfully, Channel_Connector - // creates an Channel object. Each object assigns a unique routing - // id to its associated peer. The Channels are used by gatewayd - // that to receive, route, and forward messages from source peer(s) - // to destination peer(s). -{ -public: - Channel (ROUTING_TABLE *, - Channel_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - - virtual int open (void * = 0); - // Initialize and activate a single-threaded Channel (called by - // ACE_Connector::handle_output()). - - int bind (const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - CONN_ID); - // Set the peer's addressing and routing information. - - ACE_INET_Addr &remote_addr (void); - // Returns the peer's routing address. - - ACE_INET_Addr &local_addr (void); - // Returns our local address. - - // = Set/get routing id. - CONN_ID id (void); - void id (CONN_ID); - - // = Set/get the current state of the Channel. - enum State - { - IDLE = 1, // Prior to initialization. - CONNECTING, // During connection establishment. - ESTABLISHED, // Channel is established and active. - DISCONNECTING, // Channel is in the process of connecting. - FAILED // Channel has failed. - }; - - // = Set/get the current state. - State state (void); - void state (State); - - // = Set/get the current retry timeout delay. - int timeout (void); - void timeout (int); - - // = Set/get the maximum retry timeout delay. - int max_timeout (void); - void max_timeout (int); - - // = Set/get Channel activity status. - int active (void); - void active (int); - - // = Set/get direction (necessary for error checking). - char direction (void); - void direction (char); - - // = The total number of bytes sent/received on this channel. - size_t total_bytes (void); - void total_bytes (size_t bytes); - // Increment count by <bytes>. - - virtual int handle_timeout (const ACE_Time_Value &, const void *arg); - // Perform timer-based Channel reconnection. - -protected: - enum - { - MAX_RETRY_TIMEOUT = 300 // 5 minutes is the maximum timeout. - }; - - int initialize_connection (void); - // Perform the first-time initiation of a connection to the peer. - - int reinitiate_connection (void); - // Reinitiate a connection asynchronously when peers fail. - - void socket_queue_size (void); - // Set the socket queue size. - - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = ACE_Event_Handler::RWE_MASK); - // Perform Channel termination. - - ROUTING_TABLE *routing_table_; - // Pointer to table that maps a Peer_Addr - // to a Set of Channel *'s for output. - - ACE_INET_Addr remote_addr_; - // Address of peer. - - ACE_INET_Addr local_addr_; - // Address of us. - - CONN_ID id_; - // The assigned routing ID of this entry. - - size_t total_bytes_; - // The total number of bytes sent/received on this channel. - - State state_; - // The current state of the channel. - - Channel_Connector *connector_; - // Back pointer to Channel_Connector to reestablish broken - // connections. - - int timeout_; - // Amount of time to wait between reconnection attempts. - - int max_timeout_; - // Maximum amount of time to wait between reconnection attempts. - - char direction_; - // Indicates which direction data flows through the channel ('O' == - // output and 'I' == input). - - int socket_queue_size_; - // Size of the socket queue (0 means "use default"). -}; - -class Input_Channel : public Channel - // = TITLE - // Handle reception of Peer messages arriving as events. -{ -public: - Input_Channel (ROUTING_TABLE *, - Channel_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - // Constructor sets the routing table pointer. - - virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); - // Receive and process peer messages. - -protected: - virtual int recv_peer (ACE_Message_Block *&); - // Receive a message from a peer. - - int route_message (ACE_Message_Block *); - // Action that receives messages from peerd. - - ACE_Message_Block *msg_frag_; - // Keep track of message fragment to handle non-blocking recv's from - // peers. - - virtual int svc (void); - // This method is not used since we are single-threaded. - -private: - virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0); - // This methods should not be called to handle input. -}; - -class Output_Channel : public Channel - // = TITLE - // Handle transmission of messages to other Peers using a - // single-threaded approach. -{ -public: - Output_Channel (ROUTING_TABLE *, - Channel_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - // Send a message to a gateway (may be queued if necessary). - -protected: - // = We'll allow up to 16 megabytes to be queued per-output - // channel. - enum {QUEUE_SIZE = 1024 * 1024 * 16}; - - virtual int handle_input (ACE_HANDLE); - // Receive and process shutdowns from peer. - - virtual int handle_output (ACE_HANDLE); - // Finish sending a message when flow control conditions abate. - - int nonblk_put (ACE_Message_Block *mb); - // Perform a non-blocking put(). - - virtual int send_peer (ACE_Message_Block *); - // Send a message to a peer. - - virtual int svc (void); - // This method is not used since we are single-threaded. -}; - -#endif /* _CHANNEL */ diff --git a/apps/Gateway/Gateway/Channel_Connector.cpp b/apps/Gateway/Gateway/Channel_Connector.cpp deleted file mode 100644 index a5394e8b013..00000000000 --- a/apps/Gateway/Gateway/Channel_Connector.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "Channel_Connector.h" -// $Id$ - - -Channel_Connector::Channel_Connector (void) -{ -} - -// Override the connection-failure method to add timer support. -// Note that these timers perform "expoential backoff" to -// avoid rapidly trying to reestablish connections when a link -// goes down. - -int -Channel_Connector::handle_close (ACE_HANDLE sd, ACE_Reactor_Mask) -{ - ACE_Connector<Channel, CHANNEL_PEER_CONNECTOR>::AST *stp = 0; - - // Locate the ACE_Svc_Handler corresponding to the socket descriptor. - if (this->handler_map_.find (sd, stp) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) can't locate channel %d in map, %p\n", - sd, "find"), -1); - - Channel *channel = stp->svc_handler (); - - // Schedule a reconnection request at some point in the future - // (note that channel uses an exponential backoff scheme). - if (ACE_Service_Config::reactor ()->schedule_timer (channel, 0, - channel->timeout ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - return 0; -} - -// Initiate (or reinitiate) a connection to the Channel. - -int -Channel_Connector::initiate_connection (Channel *channel, - ACE_Synch_Options &synch_options) -{ - char buf[MAXHOSTNAMELEN]; - - // Mark ourselves as idle so that the various iterators - // will ignore us until we are reconnected. - channel->state (Channel::IDLE); - - if (channel->remote_addr ().addr_to_string (buf, sizeof buf) == -1 - || channel->local_addr ().addr_to_string (buf, sizeof buf) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "can't obtain peer's address"), -1); - - // Try to connect to the Peer. - - if (this->connect (channel, channel->remote_addr (), - synch_options, channel->local_addr ()) == -1) - { - if (errno != EWOULDBLOCK) - { - channel->state (Channel::FAILED); - ACE_DEBUG ((LM_DEBUG, "(%t) %p on address %s\n", - "connect", buf)); - - // Reschedule ourselves to try and connect again. - if (synch_options[ACE_Synch_Options::USE_REACTOR]) - { - if (ACE_Service_Config::reactor ()->schedule_timer - (channel, 0, channel->timeout ()) == 0) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - } - else - // Failures on synchronous connects are reported as errors - // so that the caller can decide how to proceed. - return -1; - } - else - { - channel->state (Channel::CONNECTING); - ACE_DEBUG ((LM_DEBUG, - "(%t) in the process of connecting %s to %s\n", - synch_options[ACE_Synch_Options::USE_REACTOR] - ? "asynchronously" : "synchronously", buf)); - } - } - else - { - channel->state (Channel::ESTABLISHED); - ACE_DEBUG ((LM_DEBUG, "(%t) connected to %s on %d\n", - buf, channel->get_handle ())); - } - return 0; -} diff --git a/apps/Gateway/Gateway/Channel_Connector.h b/apps/Gateway/Gateway/Channel_Connector.h deleted file mode 100644 index 3e27f37355a..00000000000 --- a/apps/Gateway/Gateway/Channel_Connector.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Channel_Connector.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CHANNEL_CONNECTOR) -#define _CHANNEL_CONNECTOR - -#include "ace/Connector.h" -#include "Thr_Channel.h" - -class Channel_Connector : public ACE_Connector<Channel, CHANNEL_PEER_CONNECTOR> - // = TITLE - // A concrete factory class that setups connections to peerds - // and produces a new Channel object to do the dirty work... -{ -public: - Channel_Connector (void); - - // Initiate (or reinitiate) a connection on the Channel. - int initiate_connection (Channel *, - ACE_Synch_Options & = ACE_Synch_Options::synch); - -protected: - // Override the connection-failure method to add timer support. - virtual int handle_close (ACE_HANDLE sd, ACE_Reactor_Mask); -}; - -#endif /* _CHANNEL_CONNECTOR */ diff --git a/apps/Gateway/Gateway/Concurrency_Strategies.h b/apps/Gateway/Gateway/Concurrency_Strategies.h deleted file mode 100644 index 28e59a4b2e6..00000000000 --- a/apps/Gateway/Gateway/Concurrency_Strategies.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Concurrency_strategies.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CONCURRENCY_STRATEGIES) -#define _CONCURRENCY_STRATEGIES - -#include "ace/Synch.h" - -// The following typedefs are used in order to parameterize the -// synchronization policies without changing the source code! - -// If we don't have threads then use the single-threaded synchronization. -#if !defined (ACE_HAS_THREADS) -#define SYNCH_STRATEGY ACE_NULL_SYNCH -typedef ACE_Null_Mutex MAP_MUTEX; -#else /* ACE_HAS_THREADS */ - -// Note that we only need to make the ACE_Task thread-safe if we are -// using the multi-threaded Thr_Consumer_Proxy... -#if defined (USE_OUTPUT_MT) -#define SYNCH_STRATEGY ACE_MT_SYNCH -#else -#define SYNCH_STRATEGY ACE_NULL_SYNCH -#endif /* USE_OUTPUT_MT || USE_INPUT_MT */ - -// Note that we only need to make the ACE_Map_Manager thread-safe if -// we are using the multi-threaded Thr_Supplier_Proxy. In this -// case, we use an RW_Mutex since we'll lookup Consumers far more -// often than we'll update them. -#if defined (USE_INPUT_MT) -typedef ACE_RW_Mutex MAP_MUTEX; -#else -typedef ACE_Null_Mutex MAP_MUTEX; -#endif /* USE_INPUT_MT */ -#endif /* ACE_HAS_THREADS */ - -// = Forward decls -class Thr_Consumer_Proxy; -class Thr_Supplier_Proxy; -class Consumer_Proxy; -class Supplier_Proxy; - -#if defined (ACE_HAS_THREADS) && (defined (USE_OUTPUT_MT) || defined (USE_INPUT_MT)) -#if defined (USE_OUTPUT_MT) -typedef Thr_Consumer_Proxy CONSUMER_PROXY; -#else -typedef Consumer_Proxy CONSUMER_PROXY; -#endif /* USE_OUTPUT_MT */ - -#if defined (USE_INPUT_MT) -typedef Thr_Supplier_Proxy SUPPLIER_PROXY; -#else -typedef Supplier_Proxy SUPPLIER_PROXY; -#endif /* USE_INPUT_MT */ -#else -// Instantiate a non-multi-threaded Gateway. -typedef Supplier_Proxy SUPPLIER_PROXY; -typedef Consumer_Proxy CONSUMER_PROXY; -#endif /* ACE_HAS_THREADS */ - -#endif /* _CONCURRENCY_STRATEGIES */ diff --git a/apps/Gateway/Gateway/Consumer_Entry.cpp b/apps/Gateway/Gateway/Consumer_Entry.cpp deleted file mode 100644 index c3dcd96ebbf..00000000000 --- a/apps/Gateway/Gateway/Consumer_Entry.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Defines an entry in the Consumer Map. -// $Id$ - -#include "Consumer_Entry.h" - -Consumer_Entry::Consumer_Entry (void) -{ - ACE_NEW (this->destinations_, Consumer_Entry::ENTRY_SET); -} - -Consumer_Entry::~Consumer_Entry (void) -{ - delete this->destinations_; -} - -// Get the associated set of destinations. - -Consumer_Entry::ENTRY_SET * -Consumer_Entry::destinations (void) -{ - return this->destinations_; -} - -// Set the associated set of destinations. - -void -Consumer_Entry::destinations (Consumer_Entry::ENTRY_SET *s) -{ - this->destinations_ = s; -} - diff --git a/apps/Gateway/Gateway/Consumer_Entry.h b/apps/Gateway/Gateway/Consumer_Entry.h deleted file mode 100644 index fe502991514..00000000000 --- a/apps/Gateway/Gateway/Consumer_Entry.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Consumer_Entry.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_ROUTING_ENTRY) -#define _ROUTING_ENTRY - -#include "ace/Set.h" - -// Forward reference. -class IO_Handler; - -class Consumer_Entry -{ - // = TITLE - // Defines an entry in the Consumer_Map. -public: - Consumer_Entry (void); - ~Consumer_Entry (void); - - typedef ACE_Unbounded_Set<IO_Handler *> ENTRY_SET; - typedef ACE_Unbounded_Set_Iterator<IO_Handler *> ENTRY_ITERATOR; - - // = Set/get the associated set of destinations. - ENTRY_SET *destinations (void); - void destinations (ENTRY_SET *); - -protected: - ENTRY_SET *destinations_; - // The set of destinations; -}; - -#endif /* _ROUTING_ENTRY */ diff --git a/apps/Gateway/Gateway/Consumer_Map.cpp b/apps/Gateway/Gateway/Consumer_Map.cpp deleted file mode 100644 index 6d16601f949..00000000000 --- a/apps/Gateway/Gateway/Consumer_Map.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -#if !defined (_CONSUMER_MAP_C) -#define _CONSUMER_MAP_C - -#include "Consumer_Map.h" - -// Bind the Event_Addr to the INT_ID. - -int -Consumer_Map::bind (Event_Addr event_addr, - Consumer_Entry *Consumer_Entry) -{ - return this->map_.bind (event_addr, Consumer_Entry); -} - -// Find the Consumer_Entry corresponding to the Event_Addr. - -int -Consumer_Map::find (Event_Addr event_addr, - Consumer_Entry *&Consumer_Entry) -{ - return this->map_.find (event_addr, Consumer_Entry); -} - -// Unbind (remove) the Event_Addr from the map. - -int -Consumer_Map::unbind (Event_Addr event_addr) -{ - return this->map_.unbind (event_addr); -} - -Consumer_Map_Iterator::Consumer_Map_Iterator (Consumer_Map &rt) - : map_iter_ (rt.map_) -{ -} - -int -Consumer_Map_Iterator::next (Consumer_Entry *&ss) -{ - // Loop in order to skip over inactive entries if necessary. - - for (ACE_Map_Entry<Event_Addr, Consumer_Entry *> *temp = 0; - this->map_iter_.next (temp) != 0; - this->advance ()) - { - // Otherwise, return the next item. - ss = temp->int_id_; - return 1; - } - return 0; -} - -int -Consumer_Map_Iterator::advance (void) -{ - return this->map_iter_.advance (); -} -#endif /* _CONSUMER_MAP_C */ diff --git a/apps/Gateway/Gateway/Consumer_Map.h b/apps/Gateway/Gateway/Consumer_Map.h deleted file mode 100644 index fd392afaf6e..00000000000 --- a/apps/Gateway/Gateway/Consumer_Map.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Consumer_Map.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CONSUMER_MAP_H) -#define _CONSUMER_MAP_H - -#include "ace/Map_Manager.h" -#include "Concurrency_Strategies.h" -#include "Event.h" -#include "Consumer_Entry.h" - -class Consumer_Map -{ - // = TITLE - // Define a generic consumer map based on the ACE Map_Manager. - // - // = DESCRIPTION - // This class makes it easier to use the Map_Manager. -public: - int bind (Event_Addr event, Consumer_Entry *Consumer_Entry); - // Associate Event with the Consumer_Entry. - - int find (Event_Addr event, Consumer_Entry *&Consumer_Entry); - // Break any association of EXID. - - int unbind (Event_Addr event); - // Locate EXID and pass out parameter via INID. If found, - // return 0, else -1. - -public: - ACE_Map_Manager<Event_Addr, Consumer_Entry *, MAP_MUTEX> map_; - // Map that associates Event Addrs (external ids) with Consumer_Entry *'s - // <internal IDs>. -}; - -class Consumer_Map_Iterator -{ - // = TITLE - // Define an iterator for the Consumer Map. -public: - Consumer_Map_Iterator (Consumer_Map &mm); - int next (Consumer_Entry *&); - int advance (void); - -private: - ACE_Map_Iterator<Event_Addr, Consumer_Entry *, MAP_MUTEX> map_iter_; - // Map we are iterating over. -}; -#endif /* _CONSUMER_MAP_H */ diff --git a/apps/Gateway/Gateway/Dispatch_Set.h b/apps/Gateway/Gateway/Dispatch_Set.h deleted file mode 100644 index a867f1ca5ff..00000000000 --- a/apps/Gateway/Gateway/Dispatch_Set.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Dispatch_Set.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_DISPATCH_SET) -#define _DISPATCH_SET - -#include "ace/Set.h" - -// Forward reference. -class Proxy_Handler; - -typedef ACE_Unbounded_Set<Proxy_Handler *> Dispatch_Set; -typedef ACE_Unbounded_Set_Iterator<Proxy_Handler *> Dispatch_Set_Iterator; - -#endif /* _DISPATCH_SET */ diff --git a/apps/Gateway/Gateway/IO_Handler.cpp b/apps/Gateway/Gateway/IO_Handler.cpp deleted file mode 100644 index ba1b355b3ba..00000000000 --- a/apps/Gateway/Gateway/IO_Handler.cpp +++ /dev/null @@ -1,710 +0,0 @@ -// $Id$ - -#include "Consumer_Entry.h" -#include "IO_Handler_Connector.h" - -// Convenient short-hands. -#define CO CONDITION -#define MU MAP_MUTEX - -// The total number of bytes sent/received on this channel. - -size_t -IO_Handler::total_bytes (void) -{ - return this->total_bytes_; -} - -void -IO_Handler::total_bytes (size_t bytes) -{ - this->total_bytes_ += bytes; -} - -IO_Handler::IO_Handler (Consumer_Map *consumer_map, - IO_Handler_Connector *ioc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : ACE_Svc_Handler<ACE_SOCK_STREAM, SYNCH_STRATEGY> (thr_mgr), - consumer_map_ (consumer_map), - id_ (-1), - total_bytes_ (0), - state_ (IO_Handler::IDLE), - connector_ (ioc), - timeout_ (1), - max_timeout_ (IO_Handler::MAX_RETRY_TIMEOUT), - socket_queue_size_ (socket_queue_size) -{ -} - -// Set the associated channel. - -void -IO_Handler::active (int a) -{ - this->state (a == 0 ? IO_Handler::IDLE : IO_Handler::ESTABLISHED); -} - -// Get the associated channel. - -int -IO_Handler::active (void) -{ - return this->state () == IO_Handler::ESTABLISHED; -} - -// Set the direction. - -void -IO_Handler::direction (char d) -{ - this->direction_ = d; -} - -// Get the direction. - -char -IO_Handler::direction (void) -{ - return this->direction_; -} - -// Sets the timeout delay. - -void -IO_Handler::timeout (int to) -{ - if (to > this->max_timeout_) - to = this->max_timeout_; - - this->timeout_ = to; -} - -// Recalculate the current retry timeout delay using exponential -// backoff. Returns the original timeout (i.e., before the -// recalculation). - -int -IO_Handler::timeout (void) -{ - int old_timeout = this->timeout_; - this->timeout_ *= 2; - - if (this->timeout_ > this->max_timeout_) - this->timeout_ = this->max_timeout_; - - return old_timeout; -} - -// Sets the max timeout delay. - -void -IO_Handler::max_timeout (int mto) -{ - this->max_timeout_ = mto; -} - -// Gets the max timeout delay. - -int -IO_Handler::max_timeout (void) -{ - return this->max_timeout_; -} - -// Restart connection asynchronously when timeout occurs. - -int -IO_Handler::handle_timeout (const ACE_Time_Value &, const void *) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) attempting to reconnect IO_Handler %d with timeout = %d\n", - this->id (), this->timeout_)); - return this->connector_->initiate_connection (this, ACE_Synch_Options::asynch); -} - -// Restart connection (blocking_semantics dicates whether we -// restart synchronously or asynchronously). - -int -IO_Handler::reinitiate_connection (void) -{ - // Skip over deactivated descriptors. - if (this->get_handle () != -1) - { - // Make sure to close down peer to reclaim descriptor. - this->peer ().close (); - -#if 0 -// if (this->state () == FAILED) -// { - // Reinitiate timeout to improve reconnection time. -// this->timeout (1); -#endif - - ACE_DEBUG ((LM_DEBUG, - "(%t) scheduling reinitiation of IO_Handler %d\n", - this->id ())); - - // Reschedule ourselves to try and connect again. - if (ACE_Service_Config::reactor ()->schedule_timer - (this, 0, this->timeout ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - } - return 0; -} - -// Handle shutdown of the IO_Handler object. - -int -IO_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) shutting down IO_Handler %d on handle %d\n", - this->id (), this->get_handle ())); - - return this->reinitiate_connection (); -} - -// Set the state of the channel. - -void -IO_Handler::state (IO_Handler::State s) -{ - this->state_ = s; -} - -// Perform the first-time initiation of a connection to the peer. - -int -IO_Handler::initialize_connection (void) -{ - this->state_ = IO_Handler::ESTABLISHED; - - // Restart the timeout to 1. - this->timeout (1); - -#if defined (ASSIGN_SUPPLIER_ID) - // Action that sends the route id to the peerd. - - CONN_ID id = htons (this->id ()); - - ssize_t n = this->peer ().send ((const void *) &id, sizeof id); - - if (n != sizeof id) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - n == 0 ? "gatewayd has closed down unexpectedly" : "send"), - -1); -#endif /* ASSIGN_SUPPLIER_ID */ - return 0; -} - -// Set the size of the socket queue. - -void -IO_Handler::socket_queue_size (void) -{ - if (this->socket_queue_size_ > 0) - { - int option = this->direction_ == 'S' ? SO_RCVBUF : SO_SNDBUF; - - if (this->peer ().set_option (SOL_SOCKET, option, - &this->socket_queue_size_, sizeof (int)) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "set_option")); - } -} - -// Upcall from the ACE_Acceptor::handle_input() that -// delegates control to our application-specific IO_Handler. - -int -IO_Handler::open (void *a) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) IO_Handler's fd = %d\n", - this->peer ().get_handle ())); - - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn on non-blocking I/O. - if (this->peer ().enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Call down to the base class to activate and register this handler. - if (this->ACE_Svc_Handler<ACE_SOCK_STREAM, SYNCH_STRATEGY>::open (a) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "activate"), -1); - - return this->initialize_connection (); -} - -// Return the current state of the channel. - -IO_Handler::State -IO_Handler::state (void) -{ - return this->state_; -} - -void -IO_Handler::id (CONN_ID id) -{ - this->id_ = id; -} - -CONN_ID -IO_Handler::id (void) -{ - return this->id_; -} - -// Set the peer's address information. -int -IO_Handler::bind (const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - CONN_ID id) -{ - this->remote_addr_ = remote_addr; - this->local_addr_ = local_addr; - this->id_ = id; - return 0; -} - -ACE_INET_Addr & -IO_Handler::remote_addr (void) -{ - return this->remote_addr_; -} - -ACE_INET_Addr & -IO_Handler::local_addr (void) -{ - return this->local_addr_; -} - -// Constructor sets the consumer map pointer. - -Consumer_Handler::Consumer_Handler (Consumer_Map *consumer_map, - IO_Handler_Connector *ioc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : IO_Handler (consumer_map, ioc, thr_mgr, socket_queue_size) -{ - this->direction_ = 'C'; - this->msg_queue ()->high_water_mark (Consumer_Handler::QUEUE_SIZE); -} - -// This method should be called only when the peer shuts down -// unexpectedly. This method simply marks the IO_Handler as -// having failed so that handle_close () can reconnect. - -int -Consumer_Handler::handle_input (ACE_HANDLE) -{ - char buf[1]; - - this->state (IO_Handler::FAILED); - - switch (this->peer ().recv (buf, sizeof buf)) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has failed unexpectedly for Output IO_Handler %d\n", - this->id ()), -1); - /* NOTREACHED */ - case 0: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has shutdown unexpectedly for Output IO_Handler %d\n", - this->id ()), -1); - /* NOTREACHED */ - default: - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer is sending input on Output IO_Handler %d\n", - this->id ()), -1); - /* NOTREACHED */ - } -} - -// Perform a non-blocking put() of event MB. If we are unable to -// send the entire event the remainder is re-queued at the *front* of -// the Event_List. - -int -Consumer_Handler::nonblk_put (ACE_Message_Block *mb) -{ - // Try to send the event. If we don't send it all (e.g., due to - // flow control), then re-queue the remainder at the head of the - // Event_List and ask the ACE_Reactor to inform us (via - // handle_output()) when it is possible to try again. - - ssize_t n = this->send (mb); - - if (n == -1) - { - // Things have gone wrong, let's try to close down and set up a new reconnection. - this->state (IO_Handler::FAILED); - this->handle_close (); - return -1; - } - else if (errno == EWOULDBLOCK) // Didn't manage to send everything. - { - ACE_DEBUG ((LM_DEBUG, "(%t) queueing activated on handle %d to routing id %d\n", - this->get_handle (), this->id ())); - - // ACE_Queue in *front* of the list to preserve order. - if (this->msg_queue ()->enqueue_head - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enqueue_head"), -1); - - // Tell ACE_Reactor to call us back when we can send again. - else if (ACE_Service_Config::reactor ()-> - schedule_wakeup (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "schedule_wakeup"), -1); - return 0; - } - else - return n; -} - -ssize_t -Consumer_Handler::send (ACE_Message_Block *mb) -{ - ssize_t len = mb->length (); - ssize_t n = this->peer ().send (mb->rd_ptr (), len); - - if (n <= 0) - return errno == EWOULDBLOCK ? 0 : n; - else if (n < len) - // Re-adjust pointer to skip over the part we did send. - mb->rd_ptr (n); - else /* if (n == length) */ - { - // The whole event is sent, we can now safely deallocate the - // buffer. Note that this should decrement a reference count... - delete mb; - errno = 0; - } - this->total_bytes (n); - return n; -} - -// Finish sending an event when flow control conditions abate. -// This method is automatically called by the ACE_Reactor. - -int -Consumer_Handler::handle_output (ACE_HANDLE) -{ - ACE_Message_Block *mb = 0; - - ACE_DEBUG ((LM_DEBUG, - "(%t) in handle_output on handle %d\n", - this->get_handle ())); - // The list had better not be empty, otherwise there's a bug! - - if (this->msg_queue ()->dequeue_head - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) != -1) - { - switch (this->nonblk_put (mb)) - { - case 0: // Partial send. - ACE_ASSERT (errno == EWOULDBLOCK); - // Didn't write everything this time, come back later... - break; - - case -1: - // Caller is responsible for freeing a ACE_Message_Block if failures occur. - delete mb; - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "transmission failure")); - - /* FALLTHROUGH */ - default: // Sent the whole thing. - - // If we succeed in writing the entire event (or we did not - // fail due to EWOULDBLOCK) then check if there are more - // events on the Event_List. If there aren't, tell the - // ACE_Reactor not to notify us anymore (at least until - // there are new events queued up). - - if (this->msg_queue ()->is_empty ()) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) queueing deactivated on handle %d to routing id %d\n", - this->get_handle (), this->id ())); - - - if (ACE_Service_Config::reactor ()-> - cancel_wakeup (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "cancel_wakeup")); - } - } - } - else - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "dequeue_head")); - return 0; -} - -// Send an event to a peer (may queue if necessary). - -int -Consumer_Handler::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - if (this->msg_queue ()->is_empty ()) - // Try to send the event *without* blocking! - return this->nonblk_put (mb); - else - // If we have queued up events due to flow control then just - // enqueue and return. - return this->msg_queue ()->enqueue_tail - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Constructor sets the consumer map pointer and the connector -// pointer. - -Supplier_Handler::Supplier_Handler (Consumer_Map *consumer_map, - IO_Handler_Connector *ioc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : msg_frag_ (0), - IO_Handler (consumer_map, ioc, thr_mgr, socket_queue_size) -{ - this->direction_ = 'S'; - this->msg_queue ()->high_water_mark (0); -} - -// Receive a Peer event from peerd. Handles fragmentation. -// -// The routing event returned from recv consists of two parts: -// 1. The Address part, contains the virtual routing id. -// 2. The Data part, which contains the actual data to be routed. -// -// The reason for having two parts is to shield the higher layers -// of software from knowledge of the event structure. - -int -Supplier_Handler::recv (ACE_Message_Block *&forward_addr) -{ - Event *event; - ssize_t len; - ssize_t n = 0; - size_t offset = 0; - - if (this->msg_frag_ == 0) - // No existing fragment... - ACE_NEW_RETURN (this->msg_frag_, - ACE_Message_Block (sizeof (Event)), - -1); - - event = (Event *) this->msg_frag_->rd_ptr (); - - const ssize_t HEADER_SIZE = sizeof (Event_Header); - ssize_t header_bytes_left_to_read = HEADER_SIZE - this->msg_frag_->length (); - - if (header_bytes_left_to_read > 0) - { - n = this->peer ().recv (this->msg_frag_->wr_ptr (), - header_bytes_left_to_read); - - if (n == -1 /* error */ - || n == 0 /* EOF */) - { - ACE_ERROR ((LM_ERROR, "%p\n", - "Recv error during header read ")); - ACE_DEBUG ((LM_DEBUG, - "attempted to read %d\n", - header_bytes_left_to_read)); - delete this->msg_frag_; - this->msg_frag_ = 0; - return n; - } - - // Bump the write pointer by the amount read. - this->msg_frag_->wr_ptr (n); - - // At this point we may or may not have the ENTIRE header. - if (this->msg_frag_->length () < HEADER_SIZE) - { - ACE_DEBUG ((LM_DEBUG, - "Partial header received: only %d bytes\n", - this->msg_frag_->length ())); - // Notify the caller that we didn't get an entire event. - errno = EWOULDBLOCK; - return -1; - } - } - - // At this point there is a complete, valid header in msg_frag_ - len = sizeof event->buf_ + HEADER_SIZE - this->msg_frag_->length (); - - ssize_t m = this->peer ().recv (event->buf_ + offset, len); - - // Try to receive the remainder of the event - - switch (m) - { - case -1: - if (errno == EWOULDBLOCK) - { - // This shouldn't happen since the ACE_Reactor - // just triggered us to handle pending I/O! - ACE_DEBUG ((LM_DEBUG, "(%t) unexpected recv failure\n")); - errno = EWOULDBLOCK; - return -1; - } - else - /* FALLTHROUGH */; - - case 0: // Premature EOF. - delete this->msg_frag_; - this->msg_frag_ = 0; - return 0; - - default: - if (m != len) - // Re-adjust pointer to skip over the part we've read. - { - this->msg_frag_->wr_ptr (m); - errno = EWOULDBLOCK; - return -1; // Inform caller that we didn't get the whole event. - } - else - { - // Set the write pointer at 1 past the end of the event. - this->msg_frag_->wr_ptr (m); - - // Set the read pointer to the beginning of the event. - this->msg_frag_->rd_ptr (this->msg_frag_->base ()); - - // Allocate an event forwarding header and chain the data - // portion onto its continuation field. - ACE_NEW_RETURN (forward_addr, - ACE_Message_Block (sizeof (Event_Addr), - ACE_Message_Block::MB_PROTO, - this->msg_frag_), - -1); - - Event_Addr event_addr (this->id (), event->header_.routing_id_, 0); - // Copy the forwarding address from the Event_Addr into - // forward_addr. - forward_addr->copy ((char *) &event_addr, sizeof (Event)); - - // Reset the pointer to indicate we've got an entire event. - this->msg_frag_ = 0; - } - this->total_bytes (m + n); -#if defined (VERBOSE) - ACE_DEBUG ((LM_DEBUG, "(%t) channel id = %d, route id = %d, len = %d, payload = %*s", - event_addr.conn_id_, event->header_.routing_id_, event->header_.len_, - event->header_.len_, event->buf_)); -#else - ACE_DEBUG ((LM_DEBUG, "(%t) route id = %d, cur len = %d, total bytes read = %d\n", - event->header_.routing_id_, event->header_.len_, this->total_bytes ())); -#endif - return m + n; - } -} - -// Receive various types of input (e.g., Peer event from the -// gatewayd, as well as stdio). - -int -Supplier_Handler::handle_input (ACE_HANDLE) -{ - ACE_Message_Block *forward_addr = 0; - - switch (this->recv (forward_addr)) - { - case 0: - // Note that a peer should never initiate a shutdown. - this->state (IO_Handler::FAILED); - ACE_ERROR_RETURN ((LM_ERROR, - "(%t) Peer has closed down unexpectedly for Input IO_Handler %d\n", - this->id ()), -1); - /* NOTREACHED */ - case -1: - if (errno == EWOULDBLOCK) - // A short-read, we'll come back and finish it up later on! - return 0; - else // A weird problem occurred, shut down and start again. - { - this->state (IO_Handler::FAILED); - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p for Input IO_Handler %d\n", - "Peer has failed unexpectedly", - this->id ()), -1); - } - /* NOTREACHED */ - default: - return this->forward (forward_addr); - } -} - -// Route an event to its appropriate destination. - -int -Supplier_Handler::forward (ACE_Message_Block *forward_addr) -{ - // We got a valid event, so determine its virtual routing id, - // which is stored in the first of the two event blocks chained - // together. - - Event_Addr *forwarding_key = (Event_Addr *) forward_addr->rd_ptr (); - - // Skip over the address portion. - const ACE_Message_Block *const data = forward_addr->cont (); - - // RE points to the routing entry located for this routing id. - Consumer_Entry *re = 0; - - if (this->consumer_map_->find (*forwarding_key, re) != -1) - { - // Check to see if there are any destinations. - if (re->destinations ()->size () == 0) - ACE_DEBUG ((LM_WARNING, - "there are no active destinations for this event currently\n")); - - else // There are destinations, so forward the event. - { - Consumer_Entry::ENTRY_SET *esp = re->destinations (); - Consumer_Entry::ENTRY_ITERATOR si (*esp); - - for (IO_Handler **channel = 0; si.next (channel) != 0; si.advance ()) - { - // Only process active channels. - if ((*channel)->active ()) - { - // Clone the event portion (should be doing reference counting here...) - ACE_Message_Block *newmsg = data->clone (); - - ACE_DEBUG ((LM_DEBUG, "(%t) sending to peer %d\n", (*channel)->id ())); - - if ((*channel)->put (newmsg) == -1) - { - if (errno == EWOULDBLOCK) // The queue has filled up! - ACE_ERROR ((LM_ERROR, "(%t) %p\n", - "gateway is flow controlled, so we're dropping events")); - else - ACE_ERROR ((LM_ERROR, "(%t) %p transmission error to route %d\n", - "put", (*channel)->id ())); - - // Caller is responsible for freeing a ACE_Message_Block if failures occur. - delete newmsg; - } - } - } - // Will become superfluous once we have reference counting... - delete forward_addr; - return 0; - } - } - delete forward_addr; - // Failure return. - ACE_ERROR ((LM_DEBUG, "(%t) find failed on conn id = %d, logical id = %d, payload = %d\n", - forwarding_key->conn_id_, forwarding_key->logical_id_, forwarding_key->payload_)); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Map_Manager<Event_Addr, Consumer_Entry *, MAP_MUTEX>; -template class ACE_Map_Iterator<Event_Addr, Consumer_Entry *, MAP_MUTEX>; -template class ACE_Map_Entry<Event_Addr, Consumer_Entry *>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/apps/Gateway/Gateway/IO_Handler.h b/apps/Gateway/Gateway/IO_Handler.h deleted file mode 100644 index 7bda073f09b..00000000000 --- a/apps/Gateway/Gateway/IO_Handler.h +++ /dev/null @@ -1,224 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// IO_Handler.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_IO_HANDLER) -#define _IO_HANDLER - -#include "ace/Service_Config.h" -#include "ace/SOCK_Connector.h" -#include "ace/Svc_Handler.h" -#include "Consumer_Map.h" -#include "Consumer_Entry.h" -#include "Event.h" - -// Forward declaration. -class IO_Handler_Connector; - -class IO_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, SYNCH_STRATEGY> - // = TITLE - // IO_Handler contains info about connection state and addressing. - // - // = DESCRIPTION - // The IO_Handler classes process events sent from the peers to the - // gateway. These classes works as follows: - // - // 1. IO_Handler_Connector creates a number of connections with the set of - // peers specified in a configuration file. - // - // 2. For each peer that connects successfully, IO_Handler_Connector - // creates an IO_Handler object. Each object assigns a unique routing - // id to its associated peer. The Handlers are used by gatewayd - // that to receive, route, and forward events from source peer(s) - // to destination peer(s). -{ -public: - IO_Handler (Consumer_Map *, - IO_Handler_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - - virtual int open (void * = 0); - // Initialize and activate a single-threaded IO_Handler (called by - // ACE_Connector::handle_output()). - - int bind (const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - CONN_ID); - // Set the peer's addressing and routing information. - - ACE_INET_Addr &remote_addr (void); - // Returns the peer's routing address. - - ACE_INET_Addr &local_addr (void); - // Returns our local address. - - // = Set/get routing id. - CONN_ID id (void); - void id (CONN_ID); - - // = Set/get the current state of the IO_Handler. - enum State - { - IDLE = 1, // Prior to initialization. - CONNECTING, // During connection establishment. - ESTABLISHED, // IO_Handler is established and active. - DISCONNECTING, // IO_Handler is in the process of connecting. - FAILED // IO_Handler has failed. - }; - - // = Set/get the current state. - State state (void); - void state (State); - - // = Set/get the current retry timeout delay. - int timeout (void); - void timeout (int); - - // = Set/get the maximum retry timeout delay. - int max_timeout (void); - void max_timeout (int); - - // = Set/get IO_Handler activity status. - int active (void); - void active (int); - - // = Set/get direction (necessary for error checking). - char direction (void); - void direction (char); - - // = The total number of bytes sent/received on this channel. - size_t total_bytes (void); - void total_bytes (size_t bytes); - // Increment count by <bytes>. - - virtual int handle_timeout (const ACE_Time_Value &, const void *arg); - // Perform timer-based IO_Handler reconnection. - -protected: - enum - { - MAX_RETRY_TIMEOUT = 300 // 5 minutes is the maximum timeout. - }; - - int initialize_connection (void); - // Perform the first-time initiation of a connection to the peer. - - int reinitiate_connection (void); - // Reinitiate a connection asynchronously when peers fail. - - void socket_queue_size (void); - // Set the socket queue size. - - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = ACE_Event_Handler::RWE_MASK); - // Perform IO_Handler termination. - - Consumer_Map *consumer_map_; - // Pointer to table that maps an event - // to a Set of IO_Handler *'s for output. - - ACE_INET_Addr remote_addr_; - // Address of peer. - - ACE_INET_Addr local_addr_; - // Address of us. - - CONN_ID id_; - // The assigned routing ID of this entry. - - size_t total_bytes_; - // The total number of bytes sent/received on this channel. - - State state_; - // The current state of the channel. - - IO_Handler_Connector *connector_; - // Back pointer to IO_Handler_Connector to reestablish broken - // connections. - - int timeout_; - // Amount of time to wait between reconnection attempts. - - int max_timeout_; - // Maximum amount of time to wait between reconnection attempts. - - char direction_; - // Indicates which direction data flows through the channel ('O' == - // output and 'I' == input). - - int socket_queue_size_; - // Size of the socket queue (0 means "use default"). -}; - -class Supplier_Handler : public IO_Handler - // = TITLE - // Handle reception of Peer events arriving as events. -{ -public: - Supplier_Handler (Consumer_Map *, - IO_Handler_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - // Constructor sets the consumer map pointer. - - virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); - // Receive and process peer events. - -protected: - virtual int recv (ACE_Message_Block *&); - // Receive an event from a Supplier. - - int forward (ACE_Message_Block *event); - // Forward the Event to a Consumer. - - ACE_Message_Block *msg_frag_; - // Keep track of event fragment to handle non-blocking recv's from - // Suppliers. -}; - -class Consumer_Handler : public IO_Handler - // = TITLE - // Handle transmission of events to other Peers using a - // single-threaded approach. -{ -public: - Consumer_Handler (Consumer_Map *, - IO_Handler_Connector *, - ACE_Thread_Manager * = 0, - int socket_queue_size = 0); - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - // Send an event to a Consumer (may be queued if necessary). - -protected: - // = We'll allow up to 16 megabytes to be queued per-output - // channel. - enum {QUEUE_SIZE = 1024 * 1024 * 16}; - - virtual int handle_input (ACE_HANDLE); - // Receive and process shutdowns from a Consumer. - - virtual int handle_output (ACE_HANDLE); - // Finish sending event when flow control conditions abate. - - int nonblk_put (ACE_Message_Block *mb); - // Perform a non-blocking put(). - - virtual ssize_t send (ACE_Message_Block *); - // Send an event to a Consumer. -}; - -#endif /* _IO_HANDLER */ diff --git a/apps/Gateway/Gateway/IO_Handler_Connector.cpp b/apps/Gateway/Gateway/IO_Handler_Connector.cpp deleted file mode 100644 index 712b348951d..00000000000 --- a/apps/Gateway/Gateway/IO_Handler_Connector.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "IO_Handler_Connector.h" -// $Id$ - - -IO_Handler_Connector::IO_Handler_Connector (void) -{ -} - -// Override the connection-failure method to add timer support. -// Note that these timers perform "expoential backoff" to -// avoid rapidly trying to reestablish connections when a link -// goes down. - -int -IO_Handler_Connector::handle_close (ACE_HANDLE sd, ACE_Reactor_Mask) -{ - ACE_Connector<IO_Handler, ACE_SOCK_CONNECTOR>::AST *stp = 0; - - // Locate the ACE_Svc_Handler corresponding to the socket descriptor. - if (this->handler_map_.find (sd, stp) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) can't locate channel %d in map, %p\n", - sd, "find"), -1); - - IO_Handler *channel = stp->svc_handler (); - - // Schedule a reconnection request at some point in the future - // (note that channel uses an exponential backoff scheme). - if (ACE_Service_Config::reactor ()->schedule_timer (channel, 0, - channel->timeout ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - return 0; -} - -// Initiate (or reinitiate) a connection to the IO_Handler. - -int -IO_Handler_Connector::initiate_connection (IO_Handler *channel, - ACE_Synch_Options &synch_options) -{ - char buf[MAXHOSTNAMELEN]; - - // Mark ourselves as idle so that the various iterators - // will ignore us until we are reconnected. - channel->state (IO_Handler::IDLE); - - if (channel->remote_addr ().addr_to_string (buf, sizeof buf) == -1 - || channel->local_addr ().addr_to_string (buf, sizeof buf) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "can't obtain peer's address"), -1); - - // Try to connect to the Peer. - - if (this->connect (channel, channel->remote_addr (), - synch_options, channel->local_addr ()) == -1) - { - if (errno != EWOULDBLOCK) - { - channel->state (IO_Handler::FAILED); - ACE_DEBUG ((LM_DEBUG, "(%t) %p on address %s\n", - "connect", buf)); - - // Reschedule ourselves to try and connect again. - if (synch_options[ACE_Synch_Options::USE_REACTOR]) - { - if (ACE_Service_Config::reactor ()->schedule_timer - (channel, 0, channel->timeout ()) == 0) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "schedule_timer"), -1); - } - else - // Failures on synchronous connects are reported as errors - // so that the caller can decide how to proceed. - return -1; - } - else - { - channel->state (IO_Handler::CONNECTING); - ACE_DEBUG ((LM_DEBUG, - "(%t) in the process of connecting %s to %s\n", - synch_options[ACE_Synch_Options::USE_REACTOR] - ? "asynchronously" : "synchronously", buf)); - } - } - else - { - channel->state (IO_Handler::ESTABLISHED); - ACE_DEBUG ((LM_DEBUG, "(%t) connected to %s on %d\n", - buf, channel->get_handle ())); - } - return 0; -} diff --git a/apps/Gateway/Gateway/IO_Handler_Connector.h b/apps/Gateway/Gateway/IO_Handler_Connector.h deleted file mode 100644 index 585428c88ee..00000000000 --- a/apps/Gateway/Gateway/IO_Handler_Connector.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// IO_Handler_Connector.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_IO_HANDLER_CONNECTOR) -#define _IO_HANDLER_CONNECTOR - -#include "ace/Connector.h" -#include "Thr_IO_Handler.h" - -class IO_Handler_Connector : public ACE_Connector<IO_Handler, ACE_SOCK_CONNECTOR> - // = TITLE - // A concrete factory class that setups connections to peerds - // and produces a new IO_Handler object to do the dirty work... -{ -public: - IO_Handler_Connector (void); - - // Initiate (or reinitiate) a connection on the IO_Handler. - int initiate_connection (IO_Handler *, - ACE_Synch_Options & = ACE_Synch_Options::synch); - -protected: - // Override the connection-failure method to add timer support. - virtual int handle_close (ACE_HANDLE sd, ACE_Reactor_Mask); -}; - -#endif /* _IO_HANDLER_CONNECTOR */ diff --git a/apps/Gateway/Gateway/Peer_Message.h b/apps/Gateway/Gateway/Peer_Message.h deleted file mode 100644 index d9e65650095..00000000000 --- a/apps/Gateway/Gateway/Peer_Message.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Peer_Message.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (PEER_MESSAGE) -#define PEER_MESSAGE - -// This is the unique connection identifier that denotes a particular -// Channel in the Gateway. -typedef short CONN_ID; - -class Peer_Addr - // = TITLE - // Peer address is used to identify the source/destination of a - // routing message. -{ -public: - Peer_Addr (CONN_ID cid = -1, u_char lid = 0, u_char pay = 0) - : conn_id_ (cid), logical_id_ (lid), payload_ (pay) {} - - int operator== (const Peer_Addr &pa) const - { - return this->conn_id_ == pa.conn_id_ - && this->logical_id_ == pa.logical_id_ - && this->payload_ == pa.payload_; - } - - CONN_ID conn_id_; - // Unique connection identifier that denotes a particular Channel. - - u_char logical_id_; - // Logical ID. - - u_char payload_; - // Payload type. -}; - - -class Peer_Header - // = TITLE - // Fixed sized header. -{ -public: - typedef u_short ROUTING_ID; - // Type used to route messages from gatewayd. - - enum - { - INVALID_ID = -1 // No peer can validly use this number. - }; - - ROUTING_ID routing_id_; - // Source ID. - - size_t len_; - // Length of the message in bytes. -}; - -class Peer_Message - // = TITLE - // Variable-sized message (buf_ may be variable-sized between - // 0 and MAX_PAYLOAD_SIZE). -{ -public: - enum { MAX_PAYLOAD_SIZE = 1024 }; - // The maximum size of an Peer message (see Peer protocol specs for - // exact #). - - Peer_Header header_; - // Message header. - - char buf_[MAX_PAYLOAD_SIZE]; - // Message payload. -}; - -#endif /* PEER_MESSAGE */ diff --git a/apps/Gateway/Gateway/Routing_Entry.cpp b/apps/Gateway/Gateway/Routing_Entry.cpp deleted file mode 100644 index cc270cfac3a..00000000000 --- a/apps/Gateway/Gateway/Routing_Entry.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Defines an entry in the Routing Table. -// $Id$ - -#include "Routing_Entry.h" - -Routing_Entry::Routing_Entry (int validity_interval) - : validity_interval_ (validity_interval) -{ - ACE_NEW (this->destinations_, Routing_Entry::ENTRY_SET); -} - -Routing_Entry::~Routing_Entry (void) -{ - delete this->destinations_; -} - -// Get the associated set of destinations. - -Routing_Entry::ENTRY_SET * -Routing_Entry::destinations (void) -{ - return this->destinations_; -} - -// Set the associated set of destinations. - -void -Routing_Entry::destinations (Routing_Entry::ENTRY_SET *s) -{ - this->destinations_ = s; -} - -// Get the current validity interval for this route. - -int -Routing_Entry::validity_interval (void) -{ - return this->validity_interval_; -} - -// Set the current validity interval for this route. - -void -Routing_Entry::validity_interval (int vi) -{ - this->validity_interval_ = vi; -} diff --git a/apps/Gateway/Gateway/Routing_Entry.h b/apps/Gateway/Gateway/Routing_Entry.h deleted file mode 100644 index ab8e0eee53d..00000000000 --- a/apps/Gateway/Gateway/Routing_Entry.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Routing_Entry.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_ROUTING_ENTRY) -#define _ROUTING_ENTRY - -#include "ace/Set.h" - -// Forward reference. -class Channel; - -class Routing_Entry -{ - // = TITLE - // Defines an entry in the Routing_Table. -public: - Routing_Entry (int validity_interval = 0); - ~Routing_Entry (void); - - typedef ACE_Unbounded_Set<Channel *> ENTRY_SET; - typedef ACE_Unbounded_Set_Iterator<Channel *> ENTRY_ITERATOR; - - // = Set/get the associated set of destinations. - ENTRY_SET *destinations (void); - void destinations (ENTRY_SET *); - - // = Set/get current validity interval for this routing entry. - int validity_interval (void); - void validity_interval (int); - -protected: - ENTRY_SET *destinations_; - // The set of destinations; - - int validity_interval_; - // The current validity interval of this link. -}; - -#endif /* _ROUTING_ENTRY */ diff --git a/apps/Gateway/Gateway/Routing_Table.cpp b/apps/Gateway/Gateway/Routing_Table.cpp deleted file mode 100644 index 3ef2f21bc1f..00000000000 --- a/apps/Gateway/Gateway/Routing_Table.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -#if !defined (_ROUTING_TABLE_C) -#define _ROUTING_TABLE_C - - -#include "Routing_Table.h" - -/* Bind the EXT_ID to the INT_ID. */ - -template <class EXT_ID, class INT_ID, class LOCK> int -Routing_Table<EXT_ID, INT_ID, LOCK>::bind (EXT_ID ext_id, INT_ID *int_id) -{ - return this->map_.bind (ext_id, int_id); -} - -/* Find the INT_ID corresponding to the EXT_ID. */ - -template <class EXT_ID, class INT_ID, class LOCK> int -Routing_Table<EXT_ID, INT_ID, LOCK>::find (EXT_ID ext_id, INT_ID *&int_id) -{ - return this->map_.find (ext_id, int_id); -} - -/* Unbind (remove) the EXT_ID from the map. */ - -template <class EXT_ID, class INT_ID, class LOCK> int -Routing_Table<EXT_ID, INT_ID, LOCK>::unbind (EXT_ID ext_id) -{ - return this->map_.unbind (ext_id); -} - -template <class EXT_ID, class INT_ID, class LOCK> -Routing_Iterator<EXT_ID, INT_ID, LOCK>::Routing_Iterator (Routing_Table<EXT_ID, - INT_ID, LOCK> &rt, - int ignore_inactive) - : map_iter_ (rt.map_), - ignore_inactive_ (ignore_inactive) -{ -} - -template <class EXT_ID, class INT_ID, class LOCK> int -Routing_Iterator<EXT_ID, INT_ID, LOCK>::next (INT_ID *&ss) -{ - // Loop in order to skip over inactive entries if necessary. - - for (ACE_Map_Entry<EXT_ID, INT_ID *> *temp = 0; - this->map_iter_.next (temp) != 0; - this->advance ()) - { - // Skip over inactive entries if necessary. - if (temp->int_id_->active () == 0 && this->ignore_inactive_) - continue; - - // Otherwise, return the next item. - ss = temp->int_id_; - return 1; - } - return 0; -} - -template <class EXT_ID, class INT_ID, class LOCK> int -Routing_Iterator<EXT_ID, INT_ID, LOCK>::advance (void) -{ - return this->map_iter_.advance (); -} -#endif /* _ROUTING_TABLE_C */ diff --git a/apps/Gateway/Gateway/Routing_Table.h b/apps/Gateway/Gateway/Routing_Table.h deleted file mode 100644 index 84194f13e49..00000000000 --- a/apps/Gateway/Gateway/Routing_Table.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Routing_Table.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_ROUTING_TABLE_H) -#define _ROUTING_TABLE_H - -#include "ace/Map_Manager.h" - -template <class EXT_ID, class INT_ID, class LOCK> -class Routing_Table -{ - // = TITLE - // Define a generic routing table based on the ACE Map_Manager. - // - // = DESCRIPTION - // We need to have this table, rather than just using the Map_Manager - // directly in order to ignore "inactive" routing entries... -public: - int bind (EXT_ID ext_id, INT_ID *int_id); - // Associate EXT_ID with the INT_ID. - - int find (EXT_ID ext_id, INT_ID *&int_id); - // Break any association of EXID. - - int unbind (EXT_ID ext_id); - // Locate EXID and pass out parameter via INID. If found, - // return 0, else -1. - -public: - ACE_Map_Manager<EXT_ID, INT_ID *, LOCK> map_; - // Map external IDs to internal IDs. -}; - -template <class EXT_ID, class INT_ID, class LOCK> -class Routing_Iterator -{ - // = TITLE - // Define an iterator for the Routing Table. -public: - Routing_Iterator (Routing_Table<EXT_ID, INT_ID, LOCK> &mm, - int ignore_inactive = 1); - int next (INT_ID *&); - int advance (void); - -private: - ACE_Map_Iterator<EXT_ID, INT_ID *, LOCK> map_iter_; - int ignore_inactive_; -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Routing_Table.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ -#endif /* _ROUTING_TABLE_H */ diff --git a/apps/Gateway/Gateway/Thr_Channel.cpp b/apps/Gateway/Gateway/Thr_Channel.cpp deleted file mode 100644 index 26e385e2727..00000000000 --- a/apps/Gateway/Gateway/Thr_Channel.cpp +++ /dev/null @@ -1,204 +0,0 @@ -#include "Thr_Channel.h" -// $Id$ - -#include "Channel_Connector.h" - -#if defined (ACE_HAS_THREADS) -Thr_Output_Channel::Thr_Output_Channel (ROUTING_TABLE *rt, - Channel_Connector *cc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : Output_Channel (rt, cc, thr_mgr, socket_queue_size) -{ -} - -// This method should be called only when the peer shuts down -// unexpectedly. This method marks the Channel as having failed and -// deactivates the ACE_Message_Queue (to wake up the thread blocked on -// <dequeue_head> in svc()). Thr_Output_Handler::handle_close () will -// eventually try to reconnect... - -int -Thr_Output_Channel::handle_input (ACE_HANDLE h) -{ - this->Output_Channel::handle_input (h); - ACE_Service_Config::reactor ()->remove_handler (h, - ACE_Event_Handler::RWE_MASK - | ACE_Event_Handler::DONT_CALL); - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - return 0; -} - -// Initialize the threaded Output_Channel object and spawn a new -// thread. - -int -Thr_Output_Channel::open (void *) -{ - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Register ourselves to receive input events (which indicate that - // the Peer has shut down unexpectedly). - if (ACE_Service_Config::reactor ()->register_handler (this, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "register_handler"), -1); - - if (this->initialize_connection ()) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "initialize_connection"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // messages to peers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// ACE_Queue up a message for transmission (must not block since all -// Input_Channels are single-threaded). - -int -Thr_Output_Channel::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - // Perform non-blocking enqueue. - return this->msg_queue ()->enqueue_tail (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Transmit messages to the peer (note simplification resulting from -// threads...) - -int -Thr_Output_Channel::svc (void) -{ - for (;;) - { - ACE_DEBUG ((LM_DEBUG, "(%t) connected! Thr_Output_Channel's fd = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread it is OK to block on - // output. - - for (ACE_Message_Block *mb = 0; - this->msg_queue ()->dequeue_head (mb) != -1; ) - if (this->send_peer (mb) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "send failed")); - - ACE_ASSERT (errno == ESHUTDOWN); - - ACE_DEBUG ((LM_DEBUG, "(%t) shutting down threaded Output_Channel %d on handle %d\n", - this->id (), this->get_handle ())); - - this->peer ().close (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->connector_->initiate_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", - tv.sec ())); - ACE_OS::sleep (tv); - } - } - - return 0; -} - -Thr_Input_Channel::Thr_Input_Channel (ROUTING_TABLE *rt, - Channel_Connector *cc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : Input_Channel (rt, cc, thr_mgr, socket_queue_size) -{ -} - -int -Thr_Input_Channel::open (void *) -{ - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - if (this->initialize_connection ()) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "initialize_connection"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // messages to peers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// Receive messages from a Peer in a separate thread (note reuse of -// existing code!). - -int -Thr_Input_Channel::svc (void) -{ - for (;;) - { - ACE_DEBUG ((LM_DEBUG, "(%t) connected! Thr_Input_Channel's fd = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread and processes - // messages for one connection it is OK to block on input and - // output. - - while (this->handle_input () != -1) - continue; - - ACE_DEBUG ((LM_DEBUG, - "(%t) shutting down threaded Input_Channel %d on handle %d\n", - this->id (), - this->get_handle ())); - - this->peer ().close (); - - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->connector_->initiate_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", tv.sec ())); - ACE_OS::sleep (tv); - } - } - return 0; -} - -#endif /* ACE_HAS_THREADS */ diff --git a/apps/Gateway/Gateway/Thr_Channel.h b/apps/Gateway/Gateway/Thr_Channel.h deleted file mode 100644 index a1dc91b1619..00000000000 --- a/apps/Gateway/Gateway/Thr_Channel.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Thr_Channel.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_THR_CHANNEL) -#define _THR_CHANNEL - -#include "Channel.h" - -#if defined (ACE_HAS_THREADS) -class Thr_Output_Channel : public Output_Channel - // = TITLE - // Runs each Output Channel in a separate thread. -{ -public: - Thr_Output_Channel (ROUTING_TABLE *, - Channel_Connector *, - ACE_Thread_Manager *, - int socket_queue_size); - - virtual int open (void *); - // Initialize the threaded Output_Channel object and spawn a new - // thread. - - virtual int handle_input (ACE_HANDLE); - // Called when Peer shutdown unexpectedly. - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - // Send a message to a peer. - - virtual int svc (void); - // Transmit peer messages. -}; - -class Thr_Input_Channel : public Input_Channel - // = TITLE - // Runs each Input Channel in a separate thread. -{ -public: - Thr_Input_Channel (ROUTING_TABLE *, - Channel_Connector *, - ACE_Thread_Manager *, - int socket_queue_size); - - virtual int open (void *); - // Initialize the object and spawn a new thread. - - virtual int svc (void); - // Transmit peer messages. -}; -#endif /* ACE_HAS_THREADS */ -#endif /* _THR_CHANNEL */ diff --git a/apps/Gateway/Gateway/Thr_IO_Handler.cpp b/apps/Gateway/Gateway/Thr_IO_Handler.cpp deleted file mode 100644 index 109cfad9c3f..00000000000 --- a/apps/Gateway/Gateway/Thr_IO_Handler.cpp +++ /dev/null @@ -1,204 +0,0 @@ -#include "Thr_IO_Handler.h" -// $Id$ - -#include "IO_Handler_Connector.h" - -#if defined (ACE_HAS_THREADS) -Thr_Consumer_Handler::Thr_Consumer_Handler (Consumer_Map *consumer_map, - IO_Handler_Connector *ioc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : Consumer_Handler (consumer_map, ioc, thr_mgr, socket_queue_size) -{ -} - -// This method should be called only when the peer shuts down -// unexpectedly. This method marks the IO_Handler as having failed and -// deactivates the ACE_Message_Queue (to wake up the thread blocked on -// <dequeue_head> in svc()). Thr_Output_Handler::handle_close () will -// eventually try to reconnect... - -int -Thr_Consumer_Handler::handle_input (ACE_HANDLE h) -{ - this->Consumer_Handler::handle_input (h); - ACE_Service_Config::reactor ()->remove_handler (h, - ACE_Event_Handler::RWE_MASK - | ACE_Event_Handler::DONT_CALL); - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - return 0; -} - -// Initialize the threaded Consumer_Handler object and spawn a new -// thread. - -int -Thr_Consumer_Handler::open (void *) -{ - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Register ourselves to receive input events (which indicate that - // the Peer has shut down unexpectedly). - if (ACE_Service_Config::reactor ()->register_handler (this, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "register_handler"), -1); - - if (this->initialize_connection ()) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "initialize_connection"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH_STRATEGY>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // messages to peers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// ACE_Queue up a message for transmission (must not block since all -// Supplier_Handlers are single-threaded). - -int -Thr_Consumer_Handler::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - // Perform non-blocking enqueue. - return this->msg_queue ()->enqueue_tail (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Transmit messages to the peer (note simplification resulting from -// threads...) - -int -Thr_Consumer_Handler::svc (void) -{ - for (;;) - { - ACE_DEBUG ((LM_DEBUG, "(%t) connected! Thr_Consumer_Handler's fd = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread it is OK to block on - // output. - - for (ACE_Message_Block *mb = 0; - this->msg_queue ()->dequeue_head (mb) != -1; ) - if (this->send (mb) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "send failed")); - - ACE_ASSERT (errno == ESHUTDOWN); - - ACE_DEBUG ((LM_DEBUG, "(%t) shutting down threaded Consumer_Handler %d on handle %d\n", - this->id (), this->get_handle ())); - - this->peer ().close (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->connector_->initiate_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", - tv.sec ())); - ACE_OS::sleep (tv); - } - } - - return 0; -} - -Thr_Supplier_Handler::Thr_Supplier_Handler (Consumer_Map *consumer_map, - IO_Handler_Connector *ioc, - ACE_Thread_Manager *thr_mgr, - int socket_queue_size) - : Supplier_Handler (consumer_map, ioc, thr_mgr, socket_queue_size) -{ -} - -int -Thr_Supplier_Handler::open (void *) -{ - // Set the size of the socket queue. - this->socket_queue_size (); - - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - if (this->initialize_connection ()) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", - "initialize_connection"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH_STRATEGY>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // messages to peers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// Receive messages from a Peer in a separate thread (note reuse of -// existing code!). - -int -Thr_Supplier_Handler::svc (void) -{ - for (;;) - { - ACE_DEBUG ((LM_DEBUG, "(%t) connected! Thr_Supplier_Handler's fd = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread and processes - // messages for one connection it is OK to block on input and - // output. - - while (this->handle_input () != -1) - continue; - - ACE_DEBUG ((LM_DEBUG, - "(%t) shutting down threaded Supplier_Handler %d on handle %d\n", - this->id (), - this->get_handle ())); - - this->peer ().close (); - - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->connector_->initiate_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", tv.sec ())); - ACE_OS::sleep (tv); - } - } - return 0; -} - -#endif /* ACE_HAS_THREADS */ diff --git a/apps/Gateway/Gateway/Thr_IO_Handler.h b/apps/Gateway/Gateway/Thr_IO_Handler.h deleted file mode 100644 index ee056b35361..00000000000 --- a/apps/Gateway/Gateway/Thr_IO_Handler.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Thr_IO_Handler.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_THR_IO_HANDLER) -#define _THR_IO_HANDLER - -#include "IO_Handler.h" - -#if defined (ACE_HAS_THREADS) -class Thr_Consumer_Handler : public Consumer_Handler - // = TITLE - // Runs each Output IO_Handler in a separate thread. -{ -public: - Thr_Consumer_Handler (Consumer_Map *, - IO_Handler_Connector *, - ACE_Thread_Manager *, - int socket_queue_size); - - virtual int open (void *); - // Initialize the threaded Consumer_Handler object and spawn a new - // thread. - - virtual int handle_input (ACE_HANDLE); - // Called when Peer shutdown unexpectedly. - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - // Send a message to a peer. - - virtual int svc (void); - // Transmit peer messages. -}; - -class Thr_Supplier_Handler : public Supplier_Handler - // = TITLE - // Runs each Input IO_Handler in a separate thread. -{ -public: - Thr_Supplier_Handler (Consumer_Map *, - IO_Handler_Connector *, - ACE_Thread_Manager *, - int socket_queue_size); - - virtual int open (void *); - // Initialize the object and spawn a new thread. - - virtual int svc (void); - // Transmit peer messages. -}; -#endif /* ACE_HAS_THREADS */ -#endif /* _THR_IO_HANDLER */ diff --git a/apps/Gateway/Gateway/Thr_Proxy_Handler.cpp b/apps/Gateway/Gateway/Thr_Proxy_Handler.cpp deleted file mode 100644 index f316e4e82bf..00000000000 --- a/apps/Gateway/Gateway/Thr_Proxy_Handler.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// $Id$ - -#include "Event_Channel.h" -#include "Thr_Proxy_Handler.h" - -#if defined (ACE_HAS_THREADS) -Thr_Consumer_Proxy::Thr_Consumer_Proxy (ACE_Event_Channel &ec, - const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - ACE_INT32 conn_id) - : Consumer_Proxy (ec, remote_addr, local_addr, conn_id) -{ -} - -// This method should be called only when the Consumer shuts down -// unexpectedly. This method marks the Proxy_Handler as having failed -// and deactivates the ACE_Message_Queue (to wake up the thread -// blocked on <dequeue_head> in svc()). -// Thr_Output_Handler::handle_close () will eventually try to -// reconnect... - -int -Thr_Consumer_Proxy::handle_input (ACE_HANDLE h) -{ - // Call down to the <Consumer_Proxy> to handle this first. - this->Consumer_Proxy::handle_input (h); - - ACE_Service_Config::reactor ()->remove_handler - (h, ACE_Event_Handler::ALL_EVENTS_MASK | ACE_Event_Handler::DONT_CALL); - - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - return 0; -} - -// Initialize the threaded Consumer_Proxy object and spawn a new -// thread. - -int -Thr_Consumer_Proxy::open (void *) -{ - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Call back to the <Event_Channel> to complete our initialization. - else if (this->event_channel_.complete_proxy_connection (this) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "complete_proxy_connection"), -1); - - // Register ourselves to receive input events (which indicate that - // the Consumer has shut down unexpectedly). - else if (ACE_Service_Config::reactor ()->register_handler - (this, ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "register_handler"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - else if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH_STRATEGY>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // events to Consumers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// Queue up an event for transmission (must not block since -// Supplier_Proxys may be single-threaded). - -int -Thr_Consumer_Proxy::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - // Perform non-blocking enqueue. - return this->msg_queue ()->enqueue_tail - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Transmit events to the peer (note simplification resulting from -// threads...) - -int -Thr_Consumer_Proxy::svc (void) -{ - - for (;;) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) connected! Thr_Consumer_Proxy's handle = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread it is OK to block on - // output. - - for (ACE_Message_Block *mb = 0; - this->msg_queue ()->dequeue_head (mb) != -1; - ) - { - if (this->send (mb) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "send failed")); - } - - ACE_ASSERT (errno == ESHUTDOWN); - - ACE_DEBUG ((LM_DEBUG, - "(%t) shutting down threaded Consumer_Proxy %d on handle %d\n", - this->id (), this->get_handle ())); - - this->peer ().close (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->event_channel_.initiate_proxy_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", - tv.sec ())); - - ACE_OS::sleep (tv); - } - } - - return 0; -} - -Thr_Supplier_Proxy::Thr_Supplier_Proxy (ACE_Event_Channel &ec, - const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - ACE_INT32 conn_id) - : Supplier_Proxy (ec, remote_addr, local_addr, conn_id) -{ -} - -int -Thr_Supplier_Proxy::open (void *) -{ - // Turn off non-blocking I/O. - if (this->peer ().disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "enable"), -1); - - // Call back to the <Event_Channel> to complete our initialization. - else if (this->event_channel_.complete_proxy_connection (this) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "complete_proxy_connection"), -1); - - // Reactivate message queue. If it was active then this is the - // first time in and we need to spawn a thread, otherwise the queue - // was inactive due to some problem and we've already got a thread. - else if (this->msg_queue ()->activate () == ACE_Message_Queue<SYNCH_STRATEGY>::WAS_ACTIVE) - { - ACE_DEBUG ((LM_DEBUG, "(%t) spawning new thread\n")); - // Become an active object by spawning a new thread to transmit - // events to peers. - return this->activate (THR_NEW_LWP | THR_DETACHED); - } - else - { - ACE_DEBUG ((LM_DEBUG, "(%t) reusing existing thread\n")); - return 0; - } -} - -// Receive events from a Peer in a separate thread (note reuse of -// existing code!). - -int -Thr_Supplier_Proxy::svc (void) -{ - for (;;) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) connected! Thr_Supplier_Proxy's handle = %d\n", - this->peer ().get_handle ())); - - // Since this method runs in its own thread and processes events - // for one connection it is OK to call down to the - // <Supplier_Proxy::handle_input> method, which blocks on input. - - while (this->handle_input () != -1) - continue; - - ACE_DEBUG ((LM_DEBUG, - "(%t) shutting down threaded Supplier_Proxy %d on handle %d\n", - this->id (), this->get_handle ())); - - this->peer ().close (); - - // Deactivate the queue while we try to get reconnected. - this->msg_queue ()->deactivate (); - - for (this->timeout (1); - // Default is to reconnect synchronously. - this->event_channel_.initiate_proxy_connection (this) == -1; ) - { - ACE_Time_Value tv (this->timeout ()); - ACE_ERROR ((LM_ERROR, - "(%t) reattempting connection, sec = %d\n", - tv.sec ())); - ACE_OS::sleep (tv); - } - } - return 0; -} - -#endif /* ACE_HAS_THREADS */ diff --git a/apps/Gateway/Gateway/Thr_Proxy_Handler.h b/apps/Gateway/Gateway/Thr_Proxy_Handler.h deleted file mode 100644 index 275bc87b320..00000000000 --- a/apps/Gateway/Gateway/Thr_Proxy_Handler.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Thr_Proxy_Handler.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_THR_IO_HANDLER) -#define _THR_IO_HANDLER - -#include "Proxy_Handler.h" - -#if defined (ACE_HAS_THREADS) -class Thr_Consumer_Proxy : public Consumer_Proxy - // = TITLE - // Runs each Output Proxy_Handler in a separate thread. -{ -public: - Thr_Consumer_Proxy (ACE_Event_Channel &, - const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - ACE_INT32 conn_id); - - virtual int open (void *); - // Initialize the threaded Consumer_Proxy object and spawn a new - // thread. - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - // Send a message to a peer. - -protected: - virtual int handle_input (ACE_HANDLE); - // Called when Peer shutdown unexpectedly. - - virtual int svc (void); - // Transmit peer messages. -}; - -class Thr_Supplier_Proxy : public Supplier_Proxy - // = TITLE - // Runs each Input Proxy_Handler in a separate thread. -{ -public: - Thr_Supplier_Proxy (ACE_Event_Channel &, - const ACE_INET_Addr &remote_addr, - const ACE_INET_Addr &local_addr, - ACE_INT32 conn_id); - - virtual int open (void *); - // Initialize the object and spawn a new thread. - -protected: - virtual int svc (void); - // Transmit peer messages. -}; -#endif /* ACE_HAS_THREADS */ -#endif /* _THR_IO_HANDLER */ diff --git a/apps/Gateway/Gateway/cc_config b/apps/Gateway/Gateway/cc_config deleted file mode 100644 index 96f9ebdedd7..00000000000 --- a/apps/Gateway/Gateway/cc_config +++ /dev/null @@ -1,10 +0,0 @@ -# Conn ID Hostname Remote Port Direction Max Retry Delay Local Port -# ------- -------- ---- --------- --------------- ---------- - 1 tango.cs 10004 I 32 20000 -# 2 tango.cs 10004 O 32 - 3 merengue.cs 10004 O 32 20001 -# 4 mambo.cs 10004 O 32 20000 -# 5 lambada.cs 10004 O 32 20000 -# 6 tango.cs 10004 O 32 20000 -# 7 tango.cs 5001 I 32 -# 8 tango.cs 5002 O 32 diff --git a/apps/Gateway/Gateway/proxy_config b/apps/Gateway/Gateway/proxy_config index 54343cb0e73..e0784e4038e 100644 --- a/apps/Gateway/Gateway/proxy_config +++ b/apps/Gateway/Gateway/proxy_config @@ -35,7 +35,7 @@ # ID Port Role Timeout Port # ---- -------- ------ ------ ---------- ----- -------- 1 merengue.cs 10010 S 32 0 1 - 2 flamenco.cs 10010 C 32 0 1 + 2 tango.cs 10010 C 32 0 1 # 3 mambo.cs 10002 C 32 0 1 # 4 lambada.cs 10002 C 32 0 1 # 5 lambada.cs 10002 C 32 0 1 diff --git a/apps/Gateway/Gateway/rt_config b/apps/Gateway/Gateway/rt_config deleted file mode 100644 index e951a0f09be..00000000000 --- a/apps/Gateway/Gateway/rt_config +++ /dev/null @@ -1,7 +0,0 @@ -# Conn ID Logical ID Payload Destinations -# ------- ---------- ------- ------------ -# 1 1 0 3,4,5 - 1 1 0 3 - 3 1 0 3 -# 4 1 0 4 -# 5 1 0 5 diff --git a/apps/Gateway/Peer/Event.h b/apps/Gateway/Peer/Event.h deleted file mode 100644 index 5e288edf910..00000000000 --- a/apps/Gateway/Peer/Event.h +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// apps -// -// = FILENAME -// Event.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (EVENT) -#define EVENT - -#include "ace/OS.h" - -// This is the unique connection identifier that denotes a particular -// Proxy_Handler in the Gateway. -typedef ACE_INT32 ACE_INT32; - -class Event_Key - // = TITLE - // Address used to identify the source/destination of an event. - // - // = DESCRIPTION - // This is really a "virtual forwarding address" thatis used to - // decouple the filtering and forwarding logic of the Event - // Channel from the format of the data. -{ -public: - Event_Key (ACE_INT32 cid = -1, - u_char sid = 0, - u_char type = 0) - : conn_id_ (cid), - supplier_id_ (sid), - type_ (type) {} - - int operator== (const Event_Key &event_addr) const - { - return this->conn_id_ == event_addr.conn_id_ - && this->supplier_id_ == event_addr.supplier_id_ - && this->type_ == event_addr.type_; - } - - ACE_INT32 conn_id_; - // Unique connection identifier that denotes a particular - // Proxy_Handler. - - ACE_INT32 supplier_id_; - // Logical ID. - - ACE_INT32 type_; - // Event type. -}; - -class Event_Header - // = TITLE - // Fixed sized header. - // - // = DESCRIPTION - // This is designed to have a sizeof (16) to avoid alignment - // problems on most platforms. -{ -public: - typedef ACE_INT32 SUPPLIER_ID; - // Type used to forward events from gatewayd. - - enum - { - INVALID_ID = -1 // No peer can validly use this number. - }; - - void decode (void) - { - this->len_ = ntohl (this->len_); - this->supplier_id_ = ntohl (this->supplier_id_); - this->type_ = ntohl (this->type_); - this->priority_ = ntohl (this->priority_); - } - // Decode from network byte order to host byte order. - - void encode (void) - { - this->len_ = htonl (this->len_); - this->supplier_id_ = htonl (this->supplier_id_); - this->type_ = htonl (this->type_); - this->priority_ = htonl (this->priority_); - } - // Encode from host byte order to network byte order. - - size_t len_; - // Length of the data_ payload, in bytes. - - SUPPLIER_ID supplier_id_; - // Source ID. - - ACE_INT32 type_; - // Event type. - - ACE_INT32 priority_; - // Event priority. -}; - -class Event - // = TITLE - // Variable-sized event (data_ may be variable-sized between - // 0 and MAX_PAYLOAD_SIZE). -{ -public: - enum { MAX_PAYLOAD_SIZE = 1024 }; - // The maximum size of an Event. - - Event_Header header_; - // Event header. - - char data_[MAX_PAYLOAD_SIZE]; - // Event data. -}; - -#endif /* EVENT */ diff --git a/apps/Gateway/Peer/Gateway_Handler.cpp b/apps/Gateway/Peer/Gateway_Handler.cpp deleted file mode 100644 index cfc9a7dad6f..00000000000 --- a/apps/Gateway/Peer/Gateway_Handler.cpp +++ /dev/null @@ -1,652 +0,0 @@ -#include "ace/Get_Opt.h" -// $Id$ - - -#include "Gateway_Handler.h" - -Gateway_Handler::Gateway_Handler (ACE_Thread_Manager *) - : routing_id_ (0), - msg_frag_ (0), - total_bytes_ (0) -{ - this->msg_queue ()->high_water_mark (Gateway_Handler::QUEUE_SIZE); -} - -int -Gateway_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) %S\n", signum)); - - // Shut down the main event loop. - ACE_Service_Config::end_reactor_event_loop (); - return 0; -} - -// Cache a binding to the HANDLER_MAP. - -void -Gateway_Handler::map (HANDLER_MAP *m) -{ - this->map_ = m; -} - -// Upcall from the ACE_Acceptor::handle_input() that turns control -// over to our application-specific Gateway handler. - -int -Gateway_Handler::open (void *a) -{ - ACE_DEBUG ((LM_DEBUG, "Gateway handler's fd = %d\n", - this->peer ().get_handle ())); - - // Call down to the base class to activate and register this - // handler. - if (this->inherited::open (a) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); - - if (this->peer ().enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enable"), -1); - - Gateway_Handler *this_ = this; - - // Add ourselves to the map so we can be removed later on. - if (this->map_->bind (this->get_handle (), this_) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "bind"), -1); - - char *to = ACE_OS::getenv ("TIMEOUT"); - int timeout = to == 0 ? 100000 : ACE_OS::atoi (to); - - // Schedule the time between disconnects. This should really be a - // "tunable" parameter. - if (ACE_Service_Config::reactor ()->schedule_timer (this, 0, timeout) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "schedule_timer")); - - // If there are messages left in the queue, make sure we - // enable the ACE_Reactor appropriately to get them sent out. - if (this->msg_queue ()->is_empty () == 0 - && ACE_Service_Config::reactor ()->schedule_wakeup (this, - ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_wakeup"), -1); - - // First action is to wait to be notified of our routing id. - this->do_action_ = &Gateway_Handler::await_route_id; - return 0; -} - -// Read messages from stdin and send them to the gatewayd. - -int -Gateway_Handler::xmit_stdin (void) -{ - if (this->routing_id_ != -1) - { - ssize_t n; - ACE_Message_Block *mb; - - ACE_NEW_RETURN (mb, - ACE_Message_Block (sizeof (Event)), - -1); - - Event *peer_msg = (Event *) mb->rd_ptr (); - peer_msg->header_.routing_id_ = this->routing_id_; - - n = ACE_OS::read (ACE_STDIN, peer_msg->buf_, sizeof peer_msg->buf_); - - switch (n) - { - case 0: - ACE_DEBUG ((LM_DEBUG, "stdin closing down\n")); - - // Take stdin out of the ACE_Reactor so we stop trying to - // send messages. - if (ACE_Service_Config::reactor ()->remove_handler - (0, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "remove_handler")); - delete mb; - break; - case -1: - delete mb; - ACE_ERROR ((LM_ERROR, "%p\n", "read")); - break; - default: - peer_msg->header_.len_ = htonl (n); - mb->wr_ptr (sizeof (Peer_Header) + n); - - if (this->put (mb) == -1) - { - if (errno == EWOULDBLOCK) // The queue has filled up! - ACE_ERROR ((LM_ERROR, "%p\n", - "gateway is flow controlled, so we're dropping messages")); - else - ACE_ERROR ((LM_ERROR, "%p\n", "transmission failure in xmit_stdin")); - - // Caller is responsible for freeing a ACE_Message_Block - // if failures occur. - delete mb; - } - } - } - return 0; -} - -// Perform a non-blocking put() of message MB. If we are unable to -// send the entire message the remainder is re-Taskd at the *front* of -// the Message_List. - -int -Gateway_Handler::nonblk_put (ACE_Message_Block *mb) -{ - // Try to send the message. If we don't send it all (e.g., due to - // flow control), then re-ACE_Task the remainder at the head of the - // Message_List and ask the ACE_Reactor to inform us (via - // handle_output()) when it is possible to try again. - - ssize_t n; - - if ((n = this->send_peer (mb)) == -1) - return -1; - else if (errno == EWOULDBLOCK) // Didn't manage to send everything. - { - ACE_DEBUG ((LM_DEBUG, - "queueing activated on handle %d to routing id %d\n", - this->get_handle (), this->routing_id_)); - - // ACE_Queue in *front* of the list to preserve order. - if (this->msg_queue ()->enqueue_head - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enqueue_head"), -1); - - // Tell ACE_Reactor to call us back when we can send again. - if (ACE_Service_Config::reactor ()->schedule_wakeup - (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_wakeup"), -1); - return 0; - } - else - return n; -} - -// Finish sending a message when flow control conditions abate. This -// method is automatically called by the ACE_Reactor. - -int -Gateway_Handler::handle_output (ACE_HANDLE) -{ - ACE_Message_Block *mb = 0; - - ACE_DEBUG ((LM_DEBUG, "in handle_output\n")); - // The list had better not be empty, otherwise there's a bug! - - if (this->msg_queue ()->dequeue_head - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero) != -1) - { - switch (this->nonblk_put (mb)) - { - case 0: // Partial send. - ACE_ASSERT (errno == EWOULDBLOCK); - // Didn't write everything this time, come back later... - break; - - case -1: - // Caller is responsible for freeing a ACE_Message_Block if - // failures occur. - delete mb; - ACE_ERROR ((LM_ERROR, "%p\n", - "transmission failure in handle_output")); - - /* FALLTHROUGH */ - default: // Sent the whole thing. - - // If we succeed in writing the entire message (or we did - // not fail due to EWOULDBLOCK) then check if there are more - // messages on the Message_List. If there aren't, tell the - // ACE_Reactor not to notify us anymore (at least until - // there are new messages queued up). - - if (this->msg_queue ()->is_empty ()) - { - ACE_DEBUG ((LM_DEBUG, - "queue now empty on handle %d to routing id %d\n", - this->get_handle (), - this->routing_id_)); - - if (ACE_Service_Config::reactor ()->cancel_wakeup - (this, ACE_Event_Handler::WRITE_MASK) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "cancel_wakeup")); - } - } - } - else - ACE_ERROR ((LM_ERROR, "%p\n", "dequeue_head")); - return 0; -} - -// Send a message to a peer (may ACE_Task if necessary). - -int -Gateway_Handler::put (ACE_Message_Block *mb, ACE_Time_Value *) -{ - if (this->msg_queue ()->is_empty ()) - // Try to send the message *without* blocking! - return this->nonblk_put (mb); - else - // If we have queued up messages due to flow control then just - // enqueue and return. - return this->msg_queue ()->enqueue_tail - (mb, (ACE_Time_Value *) &ACE_Time_Value::zero); -} - -// Send an Peer message to gatewayd. - -int -Gateway_Handler::send_peer (ACE_Message_Block *mb) -{ - ssize_t n; - size_t len = mb->length (); - - if ((n = this->peer ().send (mb->rd_ptr (), len)) <= 0) - return errno == EWOULDBLOCK ? 0 : n; - else if (n < (ssize_t) len) - { - // Re-adjust pointer to skip over the part we did send. - mb->rd_ptr (n); - this->total_bytes_ += n; - } - else /* if (n == length) */ - { - // The whole message is sent, we can now safely deallocate the - // buffer. Note that this should decrement a reference count... - this->total_bytes_ += n; - delete mb; - errno = 0; - } - ACE_DEBUG ((LM_DEBUG, "sent %d bytes, total bytes sent = %d\n", - n, this->total_bytes_)); - return n; -} - -// Receive an Peer message from gatewayd. Handles fragmentation. - -int -Gateway_Handler::recv_peer (ACE_Message_Block *&mb) -{ - Event *peer_msg; - size_t len; - ssize_t n; - size_t offset = 0; - - if (this->msg_frag_ == 0) - { - ACE_NEW_RETURN (this->msg_frag_, - ACE_Message_Block (sizeof (Event)), - -1); - - // No existing fragment... - if (this->msg_frag_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, "out of memory\n"), -1); - - peer_msg = (Event *) this->msg_frag_->rd_ptr (); - - switch (n = this->peer ().recv (peer_msg, sizeof (Peer_Header))) - { - case sizeof (Peer_Header): - len = ntohl (peer_msg->header_.len_); - if (len <= sizeof peer_msg->buf_) - { - this->msg_frag_->wr_ptr (sizeof (Peer_Header)); - break; // The message is within the maximum size range. - } - else - ACE_ERROR ((LM_ERROR, "message too long = %d\n", len)); - /* FALLTHROUGH */ - default: - ACE_ERROR ((LM_ERROR, "invalid length = %d\n", n)); - n = -1; - /* FALLTHROUGH */ - case -1: - /* FALLTHROUGH */ - case 0: - // Make sure to free up memory on error returns. - delete this->msg_frag_; - this->msg_frag_ = 0; - return n; - } - } - else - { - offset = this->msg_frag_->length () - sizeof (Peer_Header); - len = peer_msg->header_.len_ - offset; - } - - switch (n = this->peer ().recv (peer_msg->buf_ + offset, len)) - { - case -1: - if (errno == EWOULDBLOCK) - { - // This shouldn't happen since the ACE_Reactor - // just triggered us to handle pending I/O! - ACE_DEBUG ((LM_DEBUG, "unexpected recv failure\n")); - // Since ACE_DEBUG might change errno, we need to reset it - // here. - errno = EWOULDBLOCK; - return -1; - } - else - /* FALLTHROUGH */; - - case 0: // EOF. - delete this->msg_frag_; - this->msg_frag_ = 0; - return n; - - default: - if (n != (ssize_t) len) - // Re-adjust pointer to skip over the part we've read. - { - this->msg_frag_->wr_ptr (n); - errno = EWOULDBLOCK; - // Inform caller that we didn't get the whole message. - return -1; - } - else - { - // Set the write pointer at 1 past the end of the message. - this->msg_frag_->wr_ptr (n); - - // Set the read pointer to the beginning of the message. - this->msg_frag_->rd_ptr (this->msg_frag_->base ()); - - mb = this->msg_frag_; - - // Reset the pointer to indicate we've got an entire - // message. - this->msg_frag_ = 0; - } - return n; - } -} - -// Receive various types of input (e.g., Peer message from the -// gatewayd, as well as stdio). - -int -Gateway_Handler::handle_input (ACE_HANDLE sd) -{ - ACE_DEBUG ((LM_DEBUG, "in handle_input, sd = %d\n", sd)); - if (sd == ACE_STDIN) // Handle message from stdin. - return this->xmit_stdin (); - else - // Perform the appropriate action depending on the state we are - // in. - return (this->*do_action_) (); -} - -// Action that receives the route id. - -int -Gateway_Handler::await_route_id (void) -{ - ssize_t n = this->peer ().recv (&this->routing_id_, - sizeof this->routing_id_); - - if (n != sizeof this->routing_id_) - { - if (n == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "gatewayd has closed down unexpectedly\n"), -1); - else - ACE_ERROR_RETURN ((LM_ERROR, - "%p, bytes received on handle %d = %d\n", - "recv", this->get_handle (), n), -1); - } - else - ACE_DEBUG ((LM_DEBUG, "assigned routing id %d\n", - this->routing_id_)); - - // Transition to the action that waits for Peer messages. - this->do_action_ = &Gateway_Handler::await_messages; - - // Reset standard input. - ACE_OS::rewind (stdin); - - // Register this handler to receive test messages on stdin. - if (ACE_Service_Config::reactor ()->register_handler - (ACE_STDIN, this, ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "register_handler"), -1); - return 0; -} - -// Action that receives messages. - -int -Gateway_Handler::await_messages (void) -{ - ACE_Message_Block *mb = 0; - ssize_t n = this->recv_peer (mb); - - switch (n) - { - case 0: - ACE_ERROR_RETURN ((LM_ERROR, "gatewayd has closed down\n"), -1); - /* NOTREACHED */ - case -1: - if (errno == EWOULDBLOCK) - // A short-read, we'll come back and finish it up later on! - return 0; - else - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "recv_peer"), -1); - /* NOTREACHED */ - default: - { - // We got a valid message, so let's process it now! At the - // moment, we just print out the message contents... - - Event *peer_msg = (Event *) mb->rd_ptr (); - this->total_bytes_ += mb->length (); - -#if defined (VERBOSE) - ACE_DEBUG ((LM_DEBUG, - "route id = %d, len = %d, payload = %*s", - peer_msg->header_.routing_id_, peer_msg->header_.len_, - peer_msg->header_.len_, peer_msg->buf_)); -#else - ACE_DEBUG ((LM_DEBUG, - "route id = %d, cur len = %d, total len = %d\n", - peer_msg->header_.routing_id_, - peer_msg->header_.len_, - this->total_bytes_)); -#endif - delete mb; - return 0; - } - } -} - -// Periodically send messages via ACE_Reactor timer mechanism. - -int -Gateway_Handler::handle_timeout (const ACE_Time_Value &, const void *) -{ - // Skip over deactivated descriptors. - if (this->get_handle () != -1) - { - // Unbind ourselves from the map. - if (this->map_->unbind (this->get_handle ()) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "unbind")); - - // Shut down the handler. - this->handle_close (); - } - return 0; -} - -// Handle shutdown of the Gateway_Handler object. - -int -Gateway_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) -{ - if (this->get_handle () != ACE_INVALID_HANDLE) - { - ACE_DEBUG ((LM_DEBUG, "shutting down Gateway_Handler on handle %d\n", - this->get_handle ())); - - // Explicitly remove ourselves for handle 0 (the ACE_Reactor - // removes this->handle (), note that - // ACE_Event_Handler::DONT_CALL instructs the ACE_Reactor *not* - // to call this->handle_close(), which would otherwise lead to - // recursion!). - if (ACE_Service_Config::reactor ()->remove_handler - (0, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR ((LM_ERROR, "handle = %d: %p\n", - 0, "remove_handler")); - - // Deregister this handler with the ACE_Reactor. - if (ACE_Service_Config::reactor ()->remove_handler - (this, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::RWE_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "handle = %d: %p\n", - this->get_handle (), "remove_handler"), -1); - - // Close down the peer. - this->peer ().close (); - } - return 0; -} - -Gateway_Acceptor::Gateway_Acceptor (Gateway_Handler *handler) - : gateway_handler_ (handler) -{ - this->gateway_handler_->map (&this->map_); -} - -// Note how this method just passes back the pre-allocated -// Gateway_Handler instead of having the ACE_Acceptor allocate a new -// one each time! - -Gateway_Handler * -Gateway_Acceptor::make_svc_handler (void) -{ - return this->gateway_handler_; -} - -int -Gateway_Acceptor::handle_signal (int signum, siginfo_t *, ucontext_t *) -{ - ACE_DEBUG ((LM_DEBUG, "signal %S occurred\n", signum)); - return 0; -} - -/* Returns information on the currently active service. */ - -int -Gateway_Acceptor::info (char **strp, size_t length) const -{ - char buf[BUFSIZ]; - char addr_str[BUFSIZ]; - - ACE_INET_Addr addr; - - if (this->acceptor ().get_local_addr (addr) == -1) - return -1; - else if (addr.addr_to_string (addr_str, sizeof addr) == -1) - return -1; - - ACE_OS::sprintf (buf, "%s\t %s/%s %s", - "Gateway peer daemon", addr_str, "tcp", - "# IRIDIUM SRP traffic generator and data sink\n"); - - if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) - return -1; - else - ACE_OS::strncpy (*strp, buf, length); - return ACE_OS::strlen (buf); -} - -// Hook called by the explicit dynamic linking facility to terminate -// the peer. - -int -Gateway_Acceptor::fini (void) -{ - HANDLER_ITERATOR mi (this->map_); - - for (MAP_ENTRY *me = 0; - mi.next (me) != 0; - mi.advance ()) - { - if (me->int_id_->get_handle () != -1) - { - ACE_DEBUG ((LM_DEBUG, "closing down handle %d\n", - me->int_id_->get_handle ())); - me->int_id_->handle_close (); - } - else - ACE_DEBUG ((LM_DEBUG, "already closed %d\n")); - me->int_id_->destroy (); // Will trigger a delete. - } - - this->gateway_handler_->destroy (); // Will trigger a delete. - return inherited::fini (); -} - -// Hook called by the explicit dynamic linking facility to initialize -// the peer. - -int -Gateway_Acceptor::init (int argc, char *argv[]) -{ - ACE_Get_Opt get_opt (argc, argv, "dp:", 0); - ACE_INET_Addr addr; - - for (int c; (c = get_opt ()) != -1; ) - { - switch (c) - { - case 'p': - addr.set (ACE_OS::atoi (get_opt.optarg)); - break; - case 'd': - break; - default: - break; - } - } - - if (ACE_Service_Config::reactor ()->register_handler (SIGPIPE, this) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "register_handler"), -1); - - if (this->open (addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); - else if (ACE_Service_Config::reactor ()->register_handler - (this, ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "registering service with ACE_Reactor\n"), -1); - - ACE_Sig_Set sig_set; - sig_set.sig_add (SIGINT); - sig_set.sig_add (SIGQUIT); - - // Register ourselves to receive SIGINT and SIGQUIT so we can shut - // down gracefully via signals. - - if (ACE_Service_Config::reactor ()->register_handler (sig_set, - this) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", "register_handler"), -1); - return 0; -} - -// Dynamically linked factory function that dynamically allocates a -// new Gateway_Acceptor object. - -ACE_Service_Object * -_alloc_peerd (void) -{ - // This function illustrates how we can associate a ACE_Svc_Handler - // with the ACE_Acceptor at initialization time. - Gateway_Handler *handler; - - ACE_NEW_RETURN (handler, Gateway_Handler, 0); - ACE_Service_Object *temp; - - ACE_NEW_RETURN (temp, Gateway_Acceptor (handler), 0); - return temp; -} diff --git a/apps/Gateway/Peer/Gateway_Handler.h b/apps/Gateway/Peer/Gateway_Handler.h deleted file mode 100644 index 6dc4539e6b7..00000000000 --- a/apps/Gateway/Peer/Gateway_Handler.h +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -/* These Gateway handler classes process Peer messages sent from the - communication gateway daemon (gatewayd) to its various peers, e.g., - CF and ETS, (represented collectively in this prototype as peerd). - . These classes works as follows: - - 1. Gateway_Acceptor creates a listener endpoint and waits passively - for gatewayd to connect with it. - - 2. When gatewayd connects, Gateway_Acceptor creates an - Gateway_Handler object that sends/receives messages from - gatewayd. - - 3. Gateway_Handler waits for gatewayd to inform it of its routing - ID, which is prepended to all outgoing messages send from peerd. - - 4. Once the routing ID is set, peerd periodically sends messages to - gatewayd. Peerd also receives and "processes" messages - forwarded to it from gatewayd. In this program, peerd - "processes" messages by writing them to stdout. */ - -#if !defined (GATEWAY_HANDLER) -#define GATEWAY_HANDLER - -#include "ace/Service_Config.h" -#include "ace/Svc_Handler.h" -#include "ace/Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/INET_Addr.h" -#include "ace/Map_Manager.h" -#include "Peer_Message.h" - -// Forward declaration. -class Gateway_Handler; - -// Maps a ACE_HANDLE onto a Gateway_Handler *. -typedef ACE_Map_Manager <ACE_HANDLE, Gateway_Handler *, ACE_Null_Mutex> HANDLER_MAP; -typedef ACE_Map_Iterator<ACE_HANDLE, Gateway_Handler *, ACE_Null_Mutex> HANDLER_ITERATOR; -typedef ACE_Map_Entry <ACE_HANDLE, Gateway_Handler *> MAP_ENTRY; - -// Handle Peer messages arriving as events. - -class Gateway_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> -{ -public: - Gateway_Handler (ACE_Thread_Manager * = 0); - - virtual int open (void * = 0); - // Initialize the handler (called by ACE_Acceptor::handle_input()) - - virtual int handle_input (ACE_HANDLE); - // Receive and process peer messages. - - virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0); - // Send a message to a gateway (may be queued if necessary). - - virtual int handle_output (ACE_HANDLE); - // Finish sending a message when flow control conditions abate. - - virtual int handle_timeout (const ACE_Time_Value &, - const void *arg); - // Periodically send messages via ACE_Reactor timer mechanism. - - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = ACE_Event_Handler::RWE_MASK); - // Perform object termination. - - void map (HANDLER_MAP *); - // Cache a binding to the HANDLER_MAP. - -protected: - typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> inherited; - - // We'll allow up to 16 megabytes to be queued per-output - // channel!!!! This is clearly a policy in search of refinement... - enum { QUEUE_SIZE = 1024 * 1024 * 16 }; - - int handle_signal (int signum, siginfo_t *, ucontext_t *); - - Peer_Header::ROUTING_ID routing_id_; - // Routing ID of the peer (obtained from gatewayd). - - virtual int nonblk_put (ACE_Message_Block *mb); - // Perform a non-blocking put(). - - virtual int recv_peer (ACE_Message_Block *&); - // Receive an Peer message from gatewayd. - - virtual int send_peer (ACE_Message_Block *); - // Send an Peer message to gatewayd. - - int xmit_stdin (void); - // Receive a message from stdin and send it to the gateway. - - int (Gateway_Handler::*do_action_) (void); - // Pointer-to-member-function for the current action to run in this state. - - int await_route_id (void); - // Action that receives the route id. - - int await_messages (void); - // Action that receives messages. - - ACE_Message_Block *msg_frag_; - // Keep track of message fragment to handle non-blocking recv's from gateway. - - size_t total_bytes_; - // The total number of bytes sent/received to the gateway. - - HANDLER_MAP *map_; - // Maps the ACE_HANDLE onto the Gateway_Handler *. -}; - -// A factory class that accept connections from gatewayd and -// dynamically creates a new Gateway_Handler object to do the dirty work. - -class Gateway_Acceptor : public ACE_Acceptor<Gateway_Handler, ACE_SOCK_ACCEPTOR> -{ -public: - // = Initialization methods, called when dynamically linked. - Gateway_Acceptor (Gateway_Handler *handler); - virtual int init (int argc, char *argv[]); - // Initialize the acceptor. - - virtual int info (char **, size_t) const; - // Return info about this service. - - virtual int fini (void); - // Perform termination. - - virtual Gateway_Handler *make_svc_handler (void); - // Factory method that creates the Gateway_Handler once. - - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); - // Handle various signals (e.g., SIGPIPE) - - HANDLER_MAP map_; - // Maps the ACE_HANDLE onto the Gateway_Handler *. - - Gateway_Handler *gateway_handler_; - // Pointer to memory allocated exactly once. - - typedef ACE_Acceptor<Gateway_Handler, ACE_SOCK_ACCEPTOR> inherited; -}; - -// Factory function that allocates a new Peer daemon. -extern "C" ACE_Service_Object *_alloc_peerd (void); - -#endif /* GATEWAY_HANDLER */ - diff --git a/apps/Gateway/Peer/Peer_Message.h b/apps/Gateway/Peer/Peer_Message.h deleted file mode 100644 index 67f57f148cb..00000000000 --- a/apps/Gateway/Peer/Peer_Message.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -// Define the Peer message schema (this may change). - -#if !defined (PEER_MESSAGE) -#define PEER_MESSAGE - -// Fixed sized header. - -class Peer_Header -{ -public: -// Type used to route messages from gatewayd. - typedef short ROUTING_ID; - - enum - { - INVALID_ID = -1 // No peer may use this number. - }; - - // Source ID. - ROUTING_ID routing_id_; - - // Length of the message in bytes. - size_t len_; -}; - -// Variable-sized message (buf_ may be variable-sized between -// 0 and MAX_PAYLOAD_SIZE). - -class Peer_Message -{ -public: - // The maximum size of an Peer message (see Peer protocol specs for exact #). - enum { MAX_PAYLOAD_SIZE = 1024 }; - - Peer_Header header_; - - // Message payload - char buf_[MAX_PAYLOAD_SIZE]; -}; - -#endif /* PEER_MESSAGE */ diff --git a/apps/JAWS/remora/app/Makefile b/apps/JAWS/remora/app/Makefile deleted file mode 100755 index 395684b2cb4..00000000000 --- a/apps/JAWS/remora/app/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -include stdmk - -EXE = test - -all: $(EXE) - -clean: - -rm -f core *~ *.o *_c.hh *_c.cc *_s.hh *_s.cc $(EXE) - -rm -rf Templates.DB - -remora_c.cc: remora.idl - $(ORBCC) remora.idl - -remora_s.cc: remora.idl - $(ORBCC) remora.idl - -test: remora_c.o test.o Remora_Import.o Remora_Export.o - $(CC) -o test test.o remora_c.o Remora_Import.o Remora_Export.o\ - $(LIBPATH) $(LIBORB) $(STDCC_LIBS) $(LIBACE) diff --git a/apps/JAWS/remora/app/Remora_Export.cc b/apps/JAWS/remora/app/Remora_Export.cc deleted file mode 100644 index 84fcf6511e0..00000000000 --- a/apps/JAWS/remora/app/Remora_Export.cc +++ /dev/null @@ -1,84 +0,0 @@ -#include "Remora_Export.h" - - -Remora_Export::Remora_Export(const char* label, int value, int max_value) - : remora_agent_(0) -{ - this->stat_.value_ = value; - this->stat_.label_ = label; - this->stat_.max_ = max_value; - - this->init(); -} - -Remora_Export::Remora_Export(const Remora_Export& export) - : remora_agent_(export.remora_agent_) -{ - this->stat_.value_ = export.stat_.value_; - this->stat_.label_ = export.stat_.label_; - this->stat_.max_ = export.stat_.max_; -} - -Remora_Export::~Remora_Export() -{ - try - { - if (this->remora_agent_ != 0) - { - this->remora_agent_->removeStatistic(this->stat_.label_); - this->remora_agent_->_release(); - } - } - catch(remora::Invalid_Statistic& excp) - { - } - catch(CORBA::SystemException& excp) - { - CORBA::release(this->remora_agent_); - } -} - -void -Remora_Export::init() -{ - try - { - int argc = 1; - char* argv[1]; - argv[0] = STATS_AGENT_NAME; - - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); - - this->remora_agent_ = - remora::Remora_Statistics_Agent::_bind(STATS_AGENT_NAME); - - this->remora_agent_->acceptNewStatistic(this->stat_); - } - catch(CORBA::Exception& excp) - { - cerr << excp << endl; - } -} - -void -Remora_Export::update_value(int new_value) -{ - this->stat_.value_ = new_value; - - try - { - if (this->remora_agent_ != 0 && (! this->remora_agent_->_non_existent())) - this->remora_agent_->updateStatistic(this->stat_); - } - catch(CORBA::SystemException& sysex) - { - cerr << sysex << endl; - this->remora_agent_->_release(); - this->remora_agent_ = 0; - } - catch(remora::Invalid_Statistic& excp) - { - cerr << excp << endl; - } -} - diff --git a/apps/JAWS/remora/app/Remora_Export.h b/apps/JAWS/remora/app/Remora_Export.h deleted file mode 100644 index 379f3bb1a82..00000000000 --- a/apps/JAWS/remora/app/Remora_Export.h +++ /dev/null @@ -1,85 +0,0 @@ -// $Id - -// =================================================================== -// -// = FILENAME -// Remora_Export.h -// -// = AUTHOR -// Seth Widoff -// -// =================================================================== - - -#ifndef REMORA_EXPORT_H -#define REMORA_EXPORT_H - -#include <bstring.h> -#include "remora_c.hh" - -#define MAX_VALUE 100 -#define NO_NAME "Unnamed Statistic" -#define STATS_AGENT_NAME "Remora Statistics Agent" - -class Remora_Export -{ -public: - - Remora_Export(const char* label = NO_NAME, int value = 0, - int max_value = MAX_VALUE); - - Remora_Export(const Remora_Export& export); - - ~Remora_Export(); - - void operator=(const int new_value); - void operator=(const Remora_Export& export); - - void operator+=(const int new_value); - void operator+=(const Remora_Export& export); - - void operator*=(const int new_value); - void operator*=(const Remora_Export& export); - - void operator/=(const int new_value); - void operator/=(const Remora_Export& export); - - void operator-=(const int new_value); - void operator-=(const Remora_Export& export); - - operator CORBA::Long() const; - operator CORBA::Long&(); - - friend int operator==(const Remora_Export& me, const int new_value); - friend int operator==(const Remora_Export& me, const Remora_Export& export); - - friend int operator!=(const Remora_Export& me, const int new_value); - friend int operator!=(const Remora_Export& me, const Remora_Export& export); - - friend int operator<=(const Remora_Export& me, const int new_value); - friend int operator<=(const Remora_Export& me, const Remora_Export& export); - - friend int operator>=(const Remora_Export& me, const int new_value); - friend int operator>=(const Remora_Export& me, const Remora_Export& export); - - friend int operator<(const Remora_Export& me, const int new_value); - friend int operator<(const Remora_Export& me, const Remora_Export& export); - - friend int operator>(const Remora_Export& me, const int new_value); - friend int operator>(const Remora_Export& me, const Remora_Export& export); - -private: - - void init(); - - void update_value(int new_value); - - remora::Statistic stat_; - - remora::Remora_Statistics_Agent_ptr remora_agent_; - -}; - -#include "Remora_Export.i" - -#endif diff --git a/apps/JAWS/remora/app/Remora_Export.i b/apps/JAWS/remora/app/Remora_Export.i deleted file mode 100644 index f4b158721d2..00000000000 --- a/apps/JAWS/remora/app/Remora_Export.i +++ /dev/null @@ -1,146 +0,0 @@ -// $Id - -inline void -Remora_Export::operator=(const int new_value) -{ - this->update_value(new_value); -} - -inline void -Remora_Export::operator=(const Remora_Export& export) -{ - this->update_value(export.stat_.value_); -} - -inline void -Remora_Export::operator+=(const int new_value) -{ - this->update_value(this->stat_.value_ + new_value); -} - -inline void -Remora_Export::operator+=(const Remora_Export& export) -{ - this->update_value(this->stat_.value_ + export.stat_.value_); -} - -inline void -Remora_Export::operator-=(const int new_value) -{ - this->update_value(this->stat_.value_ - new_value); -} - -inline void -Remora_Export::operator-=(const Remora_Export& export) -{ - this->update_value(this->stat_.value_ - export.stat_.value_); -} - -inline void -Remora_Export::operator*=(const int new_value) -{ - this->update_value(this->stat_.value_ * new_value); -} - -inline void -Remora_Export::operator*=(const Remora_Export& export) -{ - this->update_value(this->stat_.value_ * export.stat_.value_); -} - -inline void -Remora_Export::operator/=(const int new_value) -{ - this->update_value(this->stat_.value_ / new_value); -} - -inline void -Remora_Export::operator/=(const Remora_Export& export) -{ - this->update_value(this->stat_.value_ / export.stat_.value_); -} - -inline -Remora_Export::operator CORBA::Long() const -{ - return this->stat_.value_; -} - -inline -Remora_Export::operator CORBA::Long&() -{ - return this->stat_.value_; -} - -inline int -operator==(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ == new_value; -} - -inline int -operator==(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ == export.stat_.value_; -} - -inline int -operator!=(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ != new_value; -} - -inline int -operator!=(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ != export.stat_.value_; -} - -inline int -operator<=(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ <= new_value; -} - -inline int -operator<=(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ <= export.stat_.value_; -} - -inline int -operator>=(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ >= new_value; -} - -inline int -operator>=(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ >= export.stat_.value_; -} - -inline int -operator<(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ < new_value; -} - -inline int -operator<(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ < export.stat_.value_; -} - -inline int -operator>(const Remora_Export& me, const int new_value) -{ - return me.stat_.value_ > new_value; -} - -inline int -operator>(const Remora_Export& me, const Remora_Export& export) -{ - return me.stat_.value_ > export.stat_.value_; -} - diff --git a/apps/JAWS/remora/app/Remora_Import.cc b/apps/JAWS/remora/app/Remora_Import.cc deleted file mode 100644 index 369ca1eb7fd..00000000000 --- a/apps/JAWS/remora/app/Remora_Import.cc +++ /dev/null @@ -1,102 +0,0 @@ -// $Id - -#include "Remora_Import.h" - -Remora_Import::Remora_Import(const char* label, int value, - int min_value, int max_value) - : remora_agent_(0) -{ - this->control_.value_ = value; - this->control_.label_ = label; - this->control_.max_ = max_value; - this->control_.min_ = min_value; - - this->init(); -} - -Remora_Import::Remora_Import(const Remora_Import& import) - : remora_agent_(import.remora_agent_) -{ - this->control_.value_ = import.control_.value_; - this->control_.label_ = import.control_.label_; - this->control_.max_ = import.control_.max_; - this->control_.min_ = import.control_.min_; -} - -Remora_Import::~Remora_Import() -{ - try - { - if (this->remora_agent_ != 0) - { - this->remora_agent_->removeControl(this->control_.label_); - this->remora_agent_->_release(); - } - } - catch(remora::Invalid_Statistic& excp) - { - cerr << "Tried to remove invalid statistic."; - } - catch(CORBA::SystemException& excp) - { - CORBA::release(this->remora_agent_); - } -} - -void -Remora_Import::init() -{ - try - { - int argc = 1; - char* argv[1]; - argv[0] = CONTROL_AGENT_NAME; - - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); - - this->remora_agent_ = - remora::Remora_Controls_Agent::_bind(CONTROL_AGENT_NAME); - - this->remora_agent_->acceptNewControl(this->control_); - } - catch(CORBA::Exception& excp) - { - cerr << excp << endl; - } -} - -CORBA::Long -Remora_Import::grab_value(void) -{ - try - { - if (this->remora_agent_ != 0) - { - this->remora_agent_->getControlState(this->control_); - } - - // C++ exception handling needs a 'finally' construct - return this->control_.value_; - } - catch(CORBA::SystemException& sysex) - { - cerr << sysex << endl; - this->remora_agent_->_release(); - this->remora_agent_ = 0; - - return this->control_.value_; - } - catch(remora::Invalid_Control& excp) - { - try - { - this->remora_agent_->acceptNewControl(this->control_); - } - catch(CORBA::SystemException& sysex2) - { - return this->control_.value_; - } - - return this->control_.value_; - } -} diff --git a/apps/JAWS/remora/app/Remora_Import.h b/apps/JAWS/remora/app/Remora_Import.h deleted file mode 100644 index 8cfecd84ac4..00000000000 --- a/apps/JAWS/remora/app/Remora_Import.h +++ /dev/null @@ -1,69 +0,0 @@ -// $Id - -// =================================================================== -// -// = FILENAME -// Remora_Import.h -// -// = AUTHOR -// Seth Widoff -// -// =================================================================== - -#ifndef REMORA_IMPORT_H -#define REMORA_IMPORT_H - -#include <bstring.h> -#include "remora_c.hh" - -#define NO_NAME "Unnamed Statistic" -#define MAX_VALUE 100 -#define CONTROL_AGENT_NAME "Remora Controls Agent" - -class Remora_Import -{ -public: - - Remora_Import(const char * label = NO_NAME, int value = 0, - int min_value = 0, int max_value = MAX_VALUE); - - Remora_Import(const Remora_Import& import); - - ~Remora_Import(); - - CORBA::Long get(void); - - operator CORBA::Long(); - - friend int operator==( Remora_Import& me, int new_value); - friend int operator==( Remora_Import& me, Remora_Import& export); - - friend int operator!=( Remora_Import& me, int new_value); - friend int operator!=( Remora_Import& me, Remora_Import& export); - - friend int operator<=( Remora_Import& me, int new_value); - friend int operator<=( Remora_Import& me, Remora_Import& export); - - friend int operator>=( Remora_Import& me, int new_value); - friend int operator>=( Remora_Import& me, Remora_Import& export); - - friend int operator<( Remora_Import& me, int new_value); - friend int operator<( Remora_Import& me, Remora_Import& export); - - friend int operator>( Remora_Import& me, int new_value); - friend int operator>( Remora_Import& me, Remora_Import& export); - -private: - - void init(); - - CORBA::Long grab_value(); - - remora::Control control_; - - remora::Remora_Controls_Agent_ptr remora_agent_; - -}; - -#include "Remora_Import.i" -#endif diff --git a/apps/JAWS/remora/app/Remora_Import.i b/apps/JAWS/remora/app/Remora_Import.i deleted file mode 100644 index 48fc01f3ed7..00000000000 --- a/apps/JAWS/remora/app/Remora_Import.i +++ /dev/null @@ -1,85 +0,0 @@ -// $Id - -inline -Remora_Import::operator CORBA::Long() -{ - return this->grab_value(); -} - -inline CORBA::Long -Remora_Import::get(void) -{ - return this->grab_value(); -} - -inline int -operator==( Remora_Import& me, int new_value) -{ - return me.grab_value() == new_value; -} - -inline int -operator==( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() == import.grab_value(); -} - -inline int -operator!=( Remora_Import& me, int new_value) -{ - return me.grab_value() != new_value; -} - -inline int -operator!=( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() != import.grab_value(); -} - -inline int -operator<=( Remora_Import& me, int new_value) -{ - return me.grab_value() <= new_value; -} - -inline int -operator<=( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() <= import.grab_value(); -} - -inline int -operator>=( Remora_Import& me, int new_value) -{ - return me.grab_value() >= new_value; -} - -inline int -operator>=( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() >= import.grab_value(); -} - -inline int -operator<( Remora_Import& me, int new_value) -{ - return me.grab_value() < new_value; -} - -inline int -operator<( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() < import.grab_value(); -} - -inline int -operator>( Remora_Import& me, int new_value) -{ - return me.grab_value() > new_value; -} - -inline int -operator>( Remora_Import& me, Remora_Import& import) -{ - return me.grab_value() > import.grab_value(); -} diff --git a/apps/JAWS/remora/app/remora.idl b/apps/JAWS/remora/app/remora.idl deleted file mode 100644 index 4f6c8713099..00000000000 --- a/apps/JAWS/remora/app/remora.idl +++ /dev/null @@ -1,100 +0,0 @@ -// $Id - -// =================================================================== -// -// = FILENAME -// remora.idl -// -// = AUTHOR -// Seth Widoff -// -// =================================================================== - -// The IDL interface for the published Remora interfaces. - -module remora -{ - struct Statistic - { - string label_; - long value_; - long max_; - }; - - struct Control - { - string label_; - long value_; - long min_; - long max_; - }; - - typedef long Token; - typedef sequence<Statistic> Statistics_List; - typedef sequence<Control> Controls_List; - - exception Invalid_Statistic {}; - exception Invalid_Control {}; - - interface Statistics_Update - { - void acceptNewStatistic(in Statistic stat) raises (Invalid_Statistic); - - void updateStatistic(in Statistic stat) raises (Invalid_Statistic); - - void removeStatistic(in string label) raises (Invalid_Statistic); - }; - - interface Controls_Update - { - void acceptNewControl(in Control control) raises (Invalid_Control); - - void getControlState(inout Control control) raises (Invalid_Control); - - void removeControl(in string label) raises (Invalid_Control); - }; - - // Located in an applet, the client receives and displays - // statistics from the server. - interface Remora_Statistics_Client : Statistics_Update - { - oneway void acceptManyStatistics(in Statistics_List stats, in long length); - - oneway void updateManyStatistics(in Statistics_List stats, in long length); - // Update all statistics registered with the client - - oneway void shutdownStatistics(); - // Suggest that the client shut itself down - }; - - interface Remora_Controls_Client : Controls_Update - { - oneway void acceptManyControls(in Controls_List controls, in long length); - // Deliver many new controls to the client. - - oneway void shutdownControls(); - }; - - // Located on the server side, the Agent delivers statistics to - // registered clients. - interface Remora_Statistics_Agent : Statistics_Update - { - oneway void setFrequency(in long id, in long update_time); - // Set the frequency at which the Agent will transmit - // the statistics to the clients. - - long registerClient(in Remora_Statistics_Client client, in long update_time); - // Register a client for periodic updates. - - oneway void terminateRegistration(in long client_id); - // Unregister the client from the server. - }; - - interface Remora_Controls_Agent : Controls_Update - { - Token grabControlLock(in Remora_Controls_Client client); - - void releaseControlLock(in Token token); - }; -}; - diff --git a/apps/JAWS/remora/app/stdmk b/apps/JAWS/remora/app/stdmk deleted file mode 100755 index cc3f98edcae..00000000000 --- a/apps/JAWS/remora/app/stdmk +++ /dev/null @@ -1,40 +0,0 @@ -CC = CC -DEBUG = - -DOVE = /project/waltz/seth/doc/dove - -ACE_DIR = /project/waltz/seth/ACE_wrappers - -ORBELINEDIR = /project/waltz/Orbeline2.0 - -STL_DIR = /project/flamenco/irfan/STL/work-in-progress/Solaris-port.STL/Microsoft/STL - -ORBCC = $(ORBELINEDIR)/bin/orbeline -v _c -m _s - -CCINCLUDES = -I. -I$(ORBELINEDIR)/include -I$(STL_DIR) -I$(ACE_DIR) - -CCFLAGS = -g $(CCINCLUDES) $(DEBUG) - -LIBPATH = -L$(ORBELINEDIR)/lib -L$(ACE_DIR)/ace - -STDCC_LIBS = -lsocket -lnsl -ldl -mt - -LIBORB = -lorb - -LIBACE = -lACE - -.SUFFIXES: .C .o .h .hh .cc .cpp - -.C.o: - $(CC) $(CCFLAGS) -c -o $@ $< - -.cc.o: - $(CC) $(CCFLAGS) -c -o $@ $< - -.C.cpp: - $(CC) -E $(CCFLAGS) $< > $@ - -.cc.cpp: - $(CC) -E $(CCFLAGS) $< > $@ - - diff --git a/apps/JAWS/remora/app/test.cc b/apps/JAWS/remora/app/test.cc deleted file mode 100644 index 76158aac5a5..00000000000 --- a/apps/JAWS/remora/app/test.cc +++ /dev/null @@ -1,77 +0,0 @@ -// $Id - -#include <unistd.h> -#include <stdlib.h> -#include <iostream.h> -#include "ace/Signal.h" -#include "Remora_Export.h" -#include "Remora_Import.h" - -class Shutdown : public ACE_Event_Handler -{ -public: - Shutdown(int& cond) : cond_(cond) {} - - virtual int handle_signal(int, siginfo*, ucontext*) - { - this->cond_ = 0; - return 0; - } - -private: - - int& cond_; -}; - - -int -main(int argc, char** argv) -{ - int lcv = 1; - ACE_Sig_Handler shutdown; - - shutdown.register_handler(SIGINT, new Shutdown(lcv)); - - try - { - Remora_Export cpu("CPU Usage", 0, 100); - Remora_Export thread("Thread Count", 0, 24); - Remora_Export through("Throughput", 0, 150); - Remora_Export energy("Energy Levels", 0, 2084); - Remora_Export warp("Warp Drive Output", 0, 1023); - - Remora_Import in_threads("Threads", 1, 0, 24); - Remora_Import in_tachyon("Tachyon Emmissions", 25, 0, 100); - Remora_Import in_shields("Shield Integrity", 100, 0, 100); - Remora_Import in_phasers("Phaser Power", 421, 0, 1024); - - while (lcv) - { - cpu = rand() % 100; - thread = rand() % 24; - energy = rand() % 2084; - through = rand() % 150; - warp = rand() % 1023; - - cout << "Statistics: " << endl; - cout << "CPU: " << CORBA::Long(cpu) << endl; - cout << "Thread: " << CORBA::Long(thread) << endl; - cout << "Throughput: " << CORBA::Long(through) << endl; - cout << "Energy: " << CORBA::Long(energy) << endl; - cout << "Warp: " << CORBA::Long(cpu) << endl; - - cout << "Controls: " << endl; - cout << "Threads: " << CORBA::Long(in_threads) << endl; - cout << "Tachyon: " << CORBA::Long(in_tachyon) << endl; - cout << "Shields: " << CORBA::Long(in_shields) << endl; - cout << "Phasers: " << CORBA::Long(in_phasers) << endl; - - sleep(1); - } - } - catch(CORBA::SystemException& e) - { - - cerr << e << endl; - } -} diff --git a/apps/JAWS/server/ChangeLog b/apps/JAWS/server/ChangeLog index 03cd5224b06..800871337d0 100644 --- a/apps/JAWS/server/ChangeLog +++ b/apps/JAWS/server/ChangeLog @@ -1,53 +1,3 @@ -Fri May 23 00:45:24 1997 James C Hu <jxh@lambada.cs.wustl.edu> - - * JAWS/server: Debugged HTTP/0.9 GET requests, and HTTP/1.0 PUT - requests. Both work now, with minor problems: e.g. the - Content-type header doesn't really work (always sends text/html - as the content type). What it should do is see if the request - included a content type header, and use it, otherwise, resort to - some file suffix and mimetype matching algorithm. - - * Parse_Headers.h (complete_header_line): Added comments - explaining the new return values of -1, 0 and 1 (see comments - for Parse_Headers.cpp below). - - * Parse_Headers.cpp (complete_header_line): modified so that it - returns three values instead of two. -1 means that an end of - line was encountered, but nothing after it yet to verify if it - is really a complete header line. 0 means the read cut off in - the middle of a line (no end of line character found). 1 means - the line is verified to be a complete header line. - - * HTTP_Request.cpp (parse_request): Changed the test so that an - HTTP/0.9 request would be sent immediately after being issued. - This involved changes to Parse_Headers. - - * JAWS_File.cpp (acquire): Changes involved adding some debugging - statements to understand why PUT was not working. Discovered a - bug in how ACE_Mem_Map was being used. - - * HTTP_Request.cpp (content_length): Changed to extract value from - the headers, if available. - -Thu May 22 16:22:03 1997 James C. Hu <jxh@pride.cs.wustl.edu> - - * HTTP_Request.cpp (cgi_env): Added a cast so that a warning - generated by SGI C++ compiler goes away. - - * Makefile: Reordered the way the files are compiled/linked so - that useless warnings about object files not resolving any - symbols go away. - -Wed May 21 15:33:33 1997 James C Hu <jxh@polka.cs.wustl.edu> - - * JAWS_File.{h,cpp}: Added some comments. Will add a copy () - method soon, after I move my workspace over to lambada. - - * JAWS_Tilde.{h,cpp}: This class is being implemented but has not - been added to the repository yet, since JAWS as yet does not use - it, and it is still being developed. This will be a cache of - the expansions from ~foo to the home directory of foo. - Tue May 20 22:49:24 1997 James C Hu <jxh@polka.cs.wustl.edu> * JAWS_File.{h,cpp}: New class created to replace the old kludgy diff --git a/apps/JAWS/server/HTTP_Request.cpp b/apps/JAWS/server/HTTP_Request.cpp index 6dfa30c882b..5c1fa5e4772 100644 --- a/apps/JAWS/server/HTTP_Request.cpp +++ b/apps/JAWS/server/HTTP_Request.cpp @@ -60,21 +60,20 @@ HTTP_Request::parse_request (ACE_Message_Block &mb) // In Apache, they assume that each header line should not exceed 8K. - int result = this->headers_.complete_header_line (mb.rd_ptr ()); - if (result != 0) + if (this->headers_.complete_header_line (mb.rd_ptr ())) { if (!this->got_request_line ()) { this->parse_request_line (mb.rd_ptr ()); - while (this->headers_.complete_header_line (mb.rd_ptr ()) > 0) + while (this->headers_.complete_header_line (mb.rd_ptr ())) this->headers_.parse_header_line (mb.rd_ptr ()); } - else if (result > 0) + else do { this->headers_.parse_header_line (mb.rd_ptr ()); } - while (this->headers_.complete_header_line (mb.rd_ptr ()) > 0); + while (this->headers_.complete_header_line (mb.rd_ptr ())); } mb.wr_ptr (strlen(mb.rd_ptr ()) - mb.length ()); @@ -105,6 +104,8 @@ HTTP_Request::parse_request_line (char * const request_line) *ptr = '\0'; ptr += offset; + ACE_DEBUG ((LM_DEBUG, " (%t) request being parsed: %s\n", buf)); + char *lasts; // for strtok_r // Get the request type. @@ -131,7 +132,7 @@ HTTP_Request::parse_request_line (char * const request_line) this->method (), this->uri (), (this->version () ? this->version () : "HTTP/0.9"))); - ACE_OS::memmove (buf, ptr, ACE_OS::strlen (ptr)+1); + ACE_OS::memmove (buf, ptr, ACE_OS::strlen (ptr)); } int @@ -185,10 +186,10 @@ HTTP_Request::cgi (void) const return this->cgi_; } -const char ** +const char * const * HTTP_Request::cgi_env (void) const { - return (const char **)this->cgi_env_; + return this->cgi_env_; } const char * @@ -268,12 +269,7 @@ HTTP_Request::data_length (void) int HTTP_Request::content_length (void) { - if (this->content_length_ == -1) - { - const char * clv = this->headers_["Content-length"]; - this->content_length_ = (clv ? ACE_OS::atoi (clv) : 0); - } - return this->content_length_; + return content_length_; } int diff --git a/apps/JAWS/server/HTTP_Request.h b/apps/JAWS/server/HTTP_Request.h index 018cf2878f6..25d5c13e309 100644 --- a/apps/JAWS/server/HTTP_Request.h +++ b/apps/JAWS/server/HTTP_Request.h @@ -40,7 +40,7 @@ public: int cgi (void) const; const char * cgi_args (void) const; - const char ** cgi_env (void) const; + const char * const * cgi_env (void) const; const char * query_string (void) const; const char * path_info (void) const; diff --git a/apps/JAWS/server/JAWS_File.cpp b/apps/JAWS/server/JAWS_File.cpp index 8a32a6c4a82..a0d2d62567a 100644 --- a/apps/JAWS/server/JAWS_File.cpp +++ b/apps/JAWS/server/JAWS_File.cpp @@ -25,11 +25,10 @@ static const int READ_FLAGS = (FILE_FLAG_SEQUENTIAL_SCAN | static const int WRITE_FLAGS = (FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_OVERLAPPED | O_RDWR | - O_CREAT | - O_TRUNC); + O_CREAT); #else static const int READ_FLAGS = O_RDONLY; -static const int WRITE_FLAGS = O_RDWR | O_CREAT | O_TRUNC; +static const int WRITE_FLAGS = O_RDWR | O_CREAT; #endif /* ACE_WIN32 */ // static data members @@ -38,16 +37,18 @@ JAWS_File_Handle::vfs_ = JAWS_Virtual_Filesystem::instance (); JAWS_Virtual_Filesystem * JAWS_Virtual_Filesystem::cvf_ = 0; ACE_SYNCH_MUTEX JAWS_Virtual_Filesystem::lock_; -// this is how you make data opaque in C++ -// I'd like to do this with JAWS_File too, but Doug would pro'ly kill me class JAWS_Virtual_Filesystem_Singleton { public: JAWS_Virtual_Filesystem_Singleton (void) - { this->singleton_ = JAWS_Virtual_Filesystem::instance (); } + { + this->singleton_ = JAWS_Virtual_Filesystem::instance (); + } ~JAWS_Virtual_Filesystem_Singleton (void) - { delete this->singleton_; } + { + delete this->singleton_; + } private: JAWS_Virtual_Filesystem * singleton_; @@ -90,23 +91,18 @@ JAWS_File_Handle::~JAWS_File_Handle (void) { if (this->handle_ != ACE_INVALID_HANDLE) { - // this was dup ()'d ACE_OS::close (this->handle_); } - if (this->file_ != 0) { switch (this->file_->action ()) { case JAWS_File::WRITING: this->file_->release (); - // assert (this->file_->reference_count () == 0); - // put it into the CVF this->vfs_->replace (this->file_); break; case JAWS_File::WAITING: - // last one using a stale file is resposible for deleting it if (this->file_->release () == 0) delete this->file_; break; @@ -388,14 +384,13 @@ JAWS_File::acquire (void) this->handle_ = ACE_OS::open (this->tempname_, READ_FLAGS, R_MASK); if (this->handle_ == ACE_INVALID_HANDLE) { - this->error (JAWS_File::OPEN_FAILED, - "JAWS_File::acquire: open"); + this->error (JAWS_File::OPEN_FAILED, "JAWS_File::acquire"); } else if (this->mmap_.map (this->handle_, -1, - PROT_READ, MAP_PRIVATE) != 0) + PROT_READ, MAP_PRIVATE) != 0 + || this->mmap_.map (this->tempname_) != 0) { - this->error (JAWS_File::MEMMAP_FAILED, - "JAWS_File::acquire: map"); + this->error (JAWS_File::MEMMAP_FAILED, "JAWS_File::acquire"); ACE_OS::close (this->handle_); this->handle_ = ACE_INVALID_HANDLE; } @@ -406,28 +401,12 @@ JAWS_File::acquire (void) this->handle_ = ACE_OS::open (this->tempname_, WRITE_FLAGS, W_MASK); if (this->handle_ == ACE_INVALID_HANDLE) { - this->error (JAWS_File::OPEN_FAILED, - "JAWS_File::acquire: open"); - } - else if (ACE_OS::lseek (this->handle_, this->size_ - 1, SEEK_SET) - == -1) - { - this->error (JAWS_File::OPEN_FAILED, - "JAWS_File::acquire: lseek"); - ACE_DEBUG ((LM_DEBUG, "hey--> %d, %u, %d\n", this->handle_, this->size_, SEEK_SET)); - ACE_OS::close (this->handle_); - } - else if (ACE_OS::write (this->handle_, "", 1) != 1) - { - this->error (JAWS_File::WRITE_FAILED, - "JAWS_File::acquire: write"); - ACE_OS::close (this->handle_); + this->error (JAWS_File::OPEN_FAILED, "JAWS_File::acquire"); } else if (this->mmap_.map (this->handle_, this->size_, PROT_RDWR, MAP_SHARED) != 0) { - this->error (JAWS_File::MEMMAP_FAILED, - "JAWS_File::acquire: map"); + this->error (JAWS_File::MEMMAP_FAILED, "JAWS_File::acquire"); ACE_OS::close (this->handle_); } break; @@ -518,7 +497,7 @@ JAWS_File::error (void) const int JAWS_File::error (int error_value, const char * s) { - ACE_ERROR ((LM_ERROR, "%p.\n", s)); + ACE_ERROR ((LM_ERROR, "%p memory mapping for read.\n", s)); return (this->error_ = error_value); } diff --git a/apps/JAWS/server/JAWS_File.h b/apps/JAWS/server/JAWS_File.h index a327b57c444..318f408e0fc 100644 --- a/apps/JAWS/server/JAWS_File.h +++ b/apps/JAWS/server/JAWS_File.h @@ -35,7 +35,7 @@ class JAWS_File_Handle // E.g. 1, // { // JAWS_File_Handle foo("foo.html"); - // this->peer ().send (foo.address (), foo.size ()); + // this->peer ().send (foo.file ().map (), foo.file ().size ()); // } // E.g. 2, @@ -47,7 +47,7 @@ class JAWS_File_Handle // E.g. 3, // { // JAWS_File_Handle foo("foo.html", content_length); - // this->peer ().recv (foo.address (), content_length); + // this->peer ().recv (foo.map (), content_length); // } { public: @@ -142,8 +142,7 @@ private: class JAWS_File // = TITLE // Abstraction over a real file. This is what the Virtual Filesystem - // contains. This class is not intended for general consumption. - // Please consult a physician before attempting to use this class. + // contains. { public: diff --git a/apps/JAWS/server/Parse_Headers.cpp b/apps/JAWS/server/Parse_Headers.cpp index 545843938b3..6c20f671b09 100644 --- a/apps/JAWS/server/Parse_Headers.cpp +++ b/apps/JAWS/server/Parse_Headers.cpp @@ -60,10 +60,6 @@ Headers::complete_header_line (char * const header_line) // Else, if the next character is printable, we have a complete header line. // Else, presumably the next character is '\0', so the header is incomplete. - // return -1 if end of line but not complete header line - // return 0 if no end of line marker - // return 1 if complete header line - ptr = header_line; if (! this->end_of_line (ptr, offset)) return 0; @@ -87,7 +83,7 @@ Headers::complete_header_line (char * const header_line) default: if (isalpha (ptr[offset])) return 1; - else return -1; + else return 0; } } while (this->end_of_line (ptr, offset)); diff --git a/apps/JAWS/server/Parse_Headers.h b/apps/JAWS/server/Parse_Headers.h index e06cde86a16..2baec2862f9 100644 --- a/apps/JAWS/server/Parse_Headers.h +++ b/apps/JAWS/server/Parse_Headers.h @@ -78,11 +78,7 @@ public: void recognize (const char * const header); void parse_header_line (char * const header_line); - int complete_header_line (char * const header_line); - // -1 -> end of line but not complete header line - // 0 -> no end of line marker - // 1 -> complete header line int end_of_headers (void) const; diff --git a/examples/IOStream/client/iostream_client.cpp b/examples/IOStream/client/iostream_client.cpp index f544aa391b3..1d909d17853 100644 --- a/examples/IOStream/client/iostream_client.cpp +++ b/examples/IOStream/client/iostream_client.cpp @@ -3,11 +3,10 @@ int main (int argc, char *argv[]) { -#if !defined (ACE_LACKS_ACE_IOSTREAM) char *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST; u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT; - ACE_IOStream_T<ACE_SOCK_Stream> server; + ACE_IOStream<ACE_SOCK_Stream> server; ACE_SOCK_Connector connector; ACE_INET_Addr addr (server_port, server_host); @@ -40,16 +39,11 @@ int main (int argc, char *argv[]) if (server.close () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1); -#else - ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n")); -#endif /* !ACE_LACKS_ACE_IOSTREAM */ return 0; } -#if !defined (ACE_LACKS_ACE_IOSTREAM) #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_IOStream_T <ACE_SOCK_Stream>; -template class ACE_Streambuf_T <ACE_SOCK_Stream>; +template class ACE_IOStream <ACE_SOCK_Stream>; +template class ACE_Streambuf <ACE_SOCK_Stream>; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ -#endif /* !ACE_LACKS_ACE_IOSTREAM */ diff --git a/examples/IOStream/server/iostream_server.cpp b/examples/IOStream/server/iostream_server.cpp index 3bd7c6482f3..149d5a61eb7 100644 --- a/examples/IOStream/server/iostream_server.cpp +++ b/examples/IOStream/server/iostream_server.cpp @@ -1,5 +1,5 @@ -// This is a simple example of using the ACE_IOStream_T and -// ACE_Streambuf_T templates to create an object based on ACE_*_Stream +// This is a simple example of using the ACE_IOStream and +// ACE_streambuf templates to create an object based on ACE_*_Stream // classes which mimic a C++ iostream. #include "ace/Acceptor.h" @@ -7,13 +7,11 @@ #include "ace/Service_Config.h" #include "ace/IOStream.h" -#if !defined (ACE_LACKS_ACE_IOSTREAM) - // Declare a new type which will case an ACE_SOCK_Stream to behave // like an iostream. The new type (ACE_SOCK_IOStream) can be used // anywhere an ACE_SOCK_Stream is used. -typedef ACE_IOStream_T<ACE_SOCK_Stream> ACE_SOCK_IOStream ; +typedef ACE_IOStream<ACE_SOCK_Stream> ACE_SOCK_IOStream ; // Create a service handler object based on our new // iostream/SOCK_Stream hybrid. @@ -103,12 +101,10 @@ public: // create handler objects for us. typedef ACE_Acceptor<Handler, ACE_SOCK_ACCEPTOR> Logging_Acceptor; -#endif /* !ACE_LACKS_ACE_IOSTREAM */ int main (int argc, char *argv []) { -#if !defined (ACE_LACKS_ACE_IOSTREAM) ACE_Service_Config daemon; // Create an adapter to end the event loop. @@ -138,18 +134,13 @@ main (int argc, char *argv []) ACE_DEBUG ((LM_DEBUG, " (%P|%t) shutting down server daemon\n")); -#else - ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n")); -#endif /* !ACE_LACKS_ACE_IOSTREAM */ return 0; } -#if !defined (ACE_LACKS_ACE_IOSTREAM) #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) template class ACE_Acceptor <Handler, ACE_SOCK_ACCEPTOR>; -template class ACE_IOStream_T <ACE_SOCK_Stream>; -template class ACE_Streambuf_T <ACE_SOCK_Stream>; +template class ACE_IOStream <ACE_SOCK_Stream>; +template class ACE_Streambuf <ACE_SOCK_Stream>; template class ACE_Svc_Handler <ACE_SOCK_IOStream, ACE_INET_Addr, ACE_NULL_SYNCH>; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ -#endif /* !ACE_LACKS_ACE_IOSTREAM */ diff --git a/examples/Reactor/Misc/Makefile b/examples/Reactor/Misc/Makefile index 21e1a449821..07a7e1a548a 100644 --- a/examples/Reactor/Misc/Makefile +++ b/examples/Reactor/Misc/Makefile @@ -12,6 +12,7 @@ BIN = pingpong \ notification \ test_demuxing \ test_event_handler_t \ + test_handle_set \ test_reactors \ test_signals_1 \ test_signals_2 \ @@ -292,6 +293,20 @@ include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU $(WRAPPER_ROOT)/ace/Log_Record.i \ $(WRAPPER_ROOT)/ace/ACE.i \ $(WRAPPER_ROOT)/ace/Event_Handler.i +.obj/test_handle_set.o .shobj/test_handle_set.so: test_handle_set.cpp \ + $(WRAPPER_ROOT)/ace/Handle_Set.h \ + $(WRAPPER_ROOT)/ace/ACE.h \ + $(WRAPPER_ROOT)/ace/OS.h \ + $(WRAPPER_ROOT)/ace/config.h \ + $(WRAPPER_ROOT)/ace/stdcpp.h \ + $(WRAPPER_ROOT)/ace/OS.i \ + $(WRAPPER_ROOT)/ace/Trace.h \ + $(WRAPPER_ROOT)/ace/Log_Msg.h \ + $(WRAPPER_ROOT)/ace/Log_Record.h \ + $(WRAPPER_ROOT)/ace/Log_Priority.h \ + $(WRAPPER_ROOT)/ace/Log_Record.i \ + $(WRAPPER_ROOT)/ace/ACE.i \ + $(WRAPPER_ROOT)/ace/Handle_Set.i .obj/test_reactors.o .shobj/test_reactors.so: test_reactors.cpp \ $(WRAPPER_ROOT)/ace/Reactor.h \ $(WRAPPER_ROOT)/ace/Handle_Set.h \ diff --git a/examples/Reactor/Misc/signal_tester.cpp b/examples/Reactor/Misc/signal_tester.cpp deleted file mode 100644 index 37613f14f38..00000000000 --- a/examples/Reactor/Misc/signal_tester.cpp +++ /dev/null @@ -1,221 +0,0 @@ -// Perform an extensive test of the ACE_Reactor's event dispatching -// $Id$ - -// mechanisms. These mechanisms illustrate how signals, I/O, and -// timeout events can all be handled within the same framework. In -// addition, this example illustrates how to use the ACE_Reactor for -// devices that perform I/O via signals (such as SVR4 message queues). - - -#include "ace/Service_Config.h" - -// Used to shut down the event loop. -static sig_atomic_t done = 0; - -// This class illustrates how to handle signal-driven I/O using the -// ACE_Reactor framework. Note that signals may be caught and -// processed without requiring the use of global signal handler -// functions or global signal handler data. - -class Sig_Handler : public ACE_Event_Handler -{ -public: - Sig_Handler (void); - virtual ACE_HANDLE get_handle (void) const; - virtual int handle_input (ACE_HANDLE); - virtual int shutdown (ACE_HANDLE, ACE_Reactor_Mask); - virtual int handle_signal (ACE_HANDLE signum, siginfo_t * = 0, - ucontext_t * = 0); - -private: - ACE_HANDLE handle_; -}; - -// A dummy_handle is required to reserve a slot in the ACE_Reactor's -// descriptor table. - -Sig_Handler::Sig_Handler (void) -{ - // Assign the Sig_Handler a dummy I/O descriptor. Note that even - // though we open this file "Write Only" we still need to use the - // ACE_Event_Handler::NULL_MASK when registering this with the - // ACE_Reactor (see below). - this->handle_ = ACE_OS::open (ACE_DEV_NULL, O_WRONLY); - ACE_ASSERT (this->handle_ != -1); - - // Register signal handler object. Note that NULL_MASK is used to - // keep the ACE_Reactor from calling us back on the "/dev/null" - // descriptor. - if (ACE_Service_Config::reactor ()->register_handler - (this, ACE_Event_Handler::NULL_MASK) == -1) - ACE_ERROR ((LM_ERROR, "%p\n%a", "register_handler", 1)); - - // Create a sigset_t corresponding to the signals we want to catch. - ACE_Sig_Set sig_set; - - sig_set.sig_add (SIGINT); - sig_set.sig_add (SIGQUIT); - sig_set.sig_add (SIGALRM); - - // Register the signal handler object to catch the signals. - if (ACE_Service_Config::reactor ()->register_handler (sig_set, this) == -1) - ACE_ERROR ((LM_ERROR, "%p\n%a", "register_handler", 1)); -} - -// Called by the ACE_Reactor to extract the fd. - -ACE_HANDLE -Sig_Handler::get_handle (void) const -{ - return this->handle_; -} - -// In a real application, this method would be where the read on the -// signal-driven I/O device would occur asynchronously. For now we'll -// just print a greeting to let you know that everything is working -// properly! - -int -Sig_Handler::handle_input (ACE_HANDLE) -{ - ACE_DEBUG ((LM_DEBUG, "handling asynchonrous input...\n")); - return 0; -} - -// In a real application, this method would do any cleanup activities -// required when shutting down the I/O device. - -int -Sig_Handler::shutdown (ACE_HANDLE, ACE_Reactor_Mask) -{ - ACE_DEBUG ((LM_DEBUG, "closing down Sig_Handler...\n")); - return 0; -} - -// This method handles all the signals that are being caught by this -// object. In our simple example, we are simply catching SIGALRM, -// SIGINT, and SIGQUIT. Anything else is logged and ignored. -// -// There are several advantages to using this approach. First, -// the behavior triggered by the signal is handled in the main event -// loop, rather than in the signal handler. Second, the ACE_Reactor's -// signal handling mechanism eliminates the need to use global signal -// handler functions and data. - -int -Sig_Handler::handle_signal (int signum, siginfo_t *, ucontext_t *) -{ - ACE_DEBUG ((LM_DEBUG, "received signal %S\n", signum)); - - switch (signum) - { - case SIGALRM: - // Rearm the alarm. - ACE_OS::alarm (4); - break; - case SIGINT: - // Tell the ACE_Reactor to enable the ready bit for - // this->handle_. The ACE_Reactor will subsequently call the - // Sig_Handler::handle_input method from within its event loop. - return ACE_Service_Config::reactor ()->ready_ops - (this->handle_, ACE_Event_Handler::READ_MASK, ACE_Reactor::ADD_MASK); - case SIGQUIT: - ACE_DEBUG ((LM_DEBUG, "%S: shutting down signal tester\n", signum)); - ACE_Service_Config::end_reactor_event_loop (); - break; - default: - ACE_DEBUG ((LM_DEBUG, - "%S: not handled, returning to program\n", signum)); - break; - } - return 0; -} - -// This class illustrates that the ACE_Reactor can handle signals, -// STDIO, and timeouts using the same mechanisms. - -class STDIN_Handler : public ACE_Event_Handler -{ -public: - STDIN_Handler (void); - virtual int handle_input (ACE_HANDLE); - virtual int handle_timeout (const ACE_Time_Value &, - const void *arg); -}; - -STDIN_Handler::STDIN_Handler (void) -{ - if (ACE::register_stdin_handler (this, - ACE_Service_Config::reactor (), - ACE_Service_Config::thr_mgr ()) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "register_stdin_handler")); - - // Register the STDIN_Handler to be dispatched once every second. - else if (ACE_Service_Config::reactor ()->schedule_timer - (this, 0, ACE_Time_Value (1), ACE_Time_Value (1)) == -1) - ACE_ERROR ((LM_ERROR, "%p\n%a", "schedule_timer", 1)); -} - -int -STDIN_Handler::handle_timeout (const ACE_Time_Value &tv, - const void *) -{ - ACE_DEBUG ((LM_DEBUG, "timeout occurred at %d sec, %d usec\n", - tv.sec (), tv.usec ())); - return 0; -} - -// Read from input descriptor and write to stdout descriptor. - -int -STDIN_Handler::handle_input (ACE_HANDLE handle) -{ - ssize_t n; - char buf[BUFSIZ]; - - switch (n = ACE_OS::read (handle, buf, sizeof buf)) - { - case -1: - if (errno == EINTR) - return 0; - /* NOTREACHED */ - else - ACE_ERROR ((LM_ERROR, "%p\n", "read")); - /* FALLTHROUGH */ - case 0: - ACE_Service_Config::end_reactor_event_loop (); - break; - default: - { - ssize_t result = ACE::write_n (ACE_STDOUT, buf, n); - - if (result != n) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "write"), - result == -1 && errno == EINTR ? 0 : -1); - } - } - return 0; -} - -int -main (int argc, char *argv[]) -{ - ACE_Service_Config daemon (argv [0]); - - // Signal handler. - Sig_Handler sh; - - // Define an I/O handler object. - STDIN_Handler ioh; - - // Optionally start the alarm. - if (argc > 1) - ACE_OS::alarm (4); - - // Loop handling signals and I/O events until SIGQUIT occurs. - - while (daemon.reactor_event_loop_done () == 0) - daemon.run_reactor_event_loop (); - - return 0; -} diff --git a/examples/Reactor/Misc/test_handle_set.cpp b/examples/Reactor/Misc/test_handle_set.cpp new file mode 100644 index 00000000000..cfd4791f6e8 --- /dev/null +++ b/examples/Reactor/Misc/test_handle_set.cpp @@ -0,0 +1,73 @@ + +// $Id$ + +#include "ace/Handle_Set.h" + +void +test1 (int count) +{ + int duplicates = 0; + int sets = 0; + int clears = 0; + + ACE_Handle_Set handle_set; + + ACE_OS::srand (ACE_OS::time (0L)); + + for (int j = 0; j < count; j++) + { + int i = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE); + + if (ACE_ODD (i)) + { + if (handle_set.is_set (i)) + duplicates++; + + handle_set.set_bit (i); + sets++; + } + else + { + if (handle_set.is_set (i)) + duplicates--; + + handle_set.clr_bit (i); + clears++; + } + } + + ACE_DEBUG ((LM_DEBUG, "count = %d, set_size = %d, duplicates = %d\n", + count, handle_set.num_set (), (sets - clears) == duplicates)); +} + +void +test2 (void) +{ + ACE_Handle_Set handle_set; + ACE_HANDLE handle; + + handle_set.set_bit (0); + handle_set.set_bit (1); + handle_set.set_bit (32); + handle_set.set_bit (63); + handle_set.set_bit (64); + handle_set.set_bit (65); + handle_set.set_bit (122); + handle_set.set_bit (129); + handle_set.set_bit (245); + handle_set.set_bit (255); + + for (ACE_Handle_Set_Iterator fi (handle_set); + (handle = fi ()) != -1; + ++fi) + ACE_DEBUG ((LM_DEBUG, "handle = %d\n", handle)); +} + +int +main (int argc, char *argv[]) +{ + int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE; + test1 (count); + test2 (); +} + diff --git a/examples/Reactor/Misc/test_signals.cpp b/examples/Reactor/Misc/test_signals.cpp deleted file mode 100644 index 6493667de12..00000000000 --- a/examples/Reactor/Misc/test_signals.cpp +++ /dev/null @@ -1,226 +0,0 @@ -// Test the ability of the Reactor/Signal_Handler to register multiple -// $Id$ - -// handler per-signal. - -/* This test works as follows: - - 1. To test the "original" semantics of ACE (i.e., only one - ACE_Event_Handler can be registered per signal), you don't - need to do anything special. Existing programs work the - same since giving the Reactor's constructor a 0 value - (which is the default argument, BTW) instructs it to behave - as before. When a 0 is given, the ACE_Reactor's - constructor/open method creates an instance of - ACE_Sig_Handler and assigns this to an internal pointer. - This pointer is then used to dispatch all signal-related - methods within the Reactor. The default ACE_Sig_Handler - only allows *one* ACE_Event_Handler to be registered - per-signal. - - To run this version of the test do the following: - - % ./test-signal - ./test_signals - waiting for SIGINT or SIGQUIT - ^C - signal Interrupt occurred in Sig_Handler_2 (fruity, 0, 0) with count = 1 - waiting for SIGINT or SIGQUIT - ^\ - signal Quit occurred in Sig_Handler_2 (fruity, 0, 0) with count = 2 - shutting down SIGQUIT in Sig_Handler_2 (fruity, 0, 0) - waiting for SIGINT or SIGQUIT - ^C - signal Interrupt occurred in Sig_Handler_2 (fruity, 0, 0) with count = 3 - waiting for SIGINT or SIGQUIT - ^\Quit (core dumped) - - Note that in this test only one handler (the last one -- - "Sig_Handler_2 (fruity)") is actually registered. BTW, the - core dump is the expected behavior since the default - disposition is restored when there are no more handlers - (see the code below). - - 2. To test the "multiple handlers per-signal semantics", you - need to pass the constructor/open method of the ACE_Reactor - a pointer to a an instance of ACE_Sig_Handlers (note the - plural "s"). ACE_Sig_Handlers is a class that derives from - ACE_Sig_Handler. The difference between these two classes - is that (1) ACE_Sig_Handlers::register_signal allows - multiple ACE_Event_Handlers to be registered per-signal and - (2) it enables SA_RESTART by default. This class also - implements Detlef Becker's algorithm for integrating ACE - signal handling with 3rd party libraries. - - To run this version of the test do the following: - - % ./test_signals 1 - - waiting for SIGINT or SIGQUIT - ^C - signal Interrupt occurred in external handler! - signal Interrupt occurred in Sig_Handler_1 (howdy, 3, 1) with count = 1 - shutting down SIGINT in Sig_Handler_1 (howdy, 3, 1) - signal Interrupt occurred in Sig_Handler_1 (doody, 5, 4) with count = 1 - shutting down SIGINT in Sig_Handler_1 (doody, 5, 4) - signal Interrupt occurred in Sig_Handler_2 (tutty, 7, 6) with count = 1 - signal Interrupt occurred in Sig_Handler_2 (fruity, 9, 8) with count = 1 - waiting for SIGINT or SIGQUIT - ^\ - signal Quit occurred in Sig_Handler_1 (howdy, 3, 1) with count = 2 - shutting down SIGQUIT in Sig_Handler_1 (howdy, 3, 1) - signal Quit occurred in Sig_Handler_1 (doody, 5, 4) with count = 2 - shutting down SIGQUIT in Sig_Handler_1 (doody, 5, 4) - signal Quit occurred in Sig_Handler_2 (tutty, 7, 6) with count = 2 - shutting down SIGQUIT in Sig_Handler_2 (tutty, 7, 6) - signal Quit occurred in Sig_Handler_2 (fruity, 9, 8) with count = 2 - shutting down SIGQUIT in Sig_Handler_2 (fruity, 9, 8) - waiting for SIGINT or SIGQUIT - ^C - signal Interrupt occurred in external handler! - signal Interrupt occurred in Sig_Handler_2 (tutty, 7, 6) with count = 3 - signal Interrupt occurred in Sig_Handler_2 (fruity, 9, 8) with count = 3 - waiting for SIGINT or SIGQUIT - ^\Quit (core dumped) - - When this test begins all four handlers are registered and - dispatched when a SIGINT or SIGQUIT occurs. After the - first SIGINT, the handle_signal method of the Sig_Handler_1 - objects unregister themselves. At that point there are 4 - SIGQUIT handlers left, but only 2 of our SIGINT handlers - left (and the 1 external handler). After the first - SIGQUIT, there are no SIGQUIT handlers left since they all - deregister themselves (which restores the "SIG_DFL" - disposition). On the second SIGINT there are only 3 - handlers left (2 of ours and 1 external). Finally, on the - second SIGQUIT we exit and dump core since that's what - happens with the default disposition for SIGQUIT. */ - -#include "ace/Log_Msg.h" -#include "ace/Reactor.h" - -class Sig_Handler_1 : public ACE_Event_Handler -{ -public: - Sig_Handler_1 (ACE_Reactor &reactor, char *msg) - : msg_ (msg), - count_ (0), - reactor_ (reactor) - { - // Register the signal handlers. - this->quit_sigkey_ = reactor.register_handler (SIGQUIT, this); - this->int_sigkey_ = reactor.register_handler (SIGINT, this); - - if (this->quit_sigkey_ == -1 || this->int_sigkey_ == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "register_handler")); - } - - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *) - { - this->count_++; - ACE_DEBUG ((LM_DEBUG, - "\nsignal %S occurred in Sig_Handler_1 (%s, %d, %d) with count = %d", - signum, this->msg_, this->int_sigkey_, this->quit_sigkey_, this->count_)); - if (this->count_ != 1 && signum == SIGQUIT) - { - if (this->reactor_.remove_handler (SIGQUIT, 0, 0, - this->quit_sigkey_) == -1) - ACE_ERROR ((LM_ERROR, "\n%p", "remove_handler")); - else - ACE_DEBUG ((LM_DEBUG, "\nshutting down SIGQUIT in Sig_Handler_1 (%s, %d, %d)", - this->msg_, this->int_sigkey_, this->quit_sigkey_)); - } - else if (this->count_ != 2 && signum == SIGINT) - { - if (this->reactor_.remove_handler (SIGINT, 0, 0, - this->int_sigkey_) == -1) - ACE_ERROR ((LM_ERROR, "\n%p", "remove_handler")); - else - ACE_DEBUG ((LM_DEBUG, "\nshutting down SIGINT in Sig_Handler_1 (%s, %d, %d)", - this->msg_, this->int_sigkey_, this->quit_sigkey_)); - } - return 0; - } - -protected: - char *msg_; - int count_; - int int_sigkey_; - int quit_sigkey_; - ACE_Reactor &reactor_; -}; - -class Sig_Handler_2 : public Sig_Handler_1 -{ -public: - Sig_Handler_2 (ACE_Reactor &reactor, char *msg) - : Sig_Handler_1 (reactor, msg) - { - } - - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *) - { - this->count_++; - ACE_DEBUG ((LM_DEBUG, - "\nsignal %S occurred in Sig_Handler_2 (%s, %d, %d) with count = %d", - signum, this->msg_, this->int_sigkey_, this->quit_sigkey_, this->count_)); - if (this->count_ != 0 && signum == SIGQUIT) - { - if (this->reactor_.remove_handler (SIGQUIT, 0, 0, - this->quit_sigkey_) == -1) - ACE_ERROR ((LM_ERROR, "\n%p", "remove_handler")); - else - 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; - } -}; - -static void -external_handler (int signum) -{ - ACE_DEBUG ((LM_DEBUG, "\nsignal %S occurred in external handler!", signum)); -} - -#if !defined (HPUX) -int -main (int argc, char *argv) -{ - // If argc > 1 then allow multiple handlers per-signal, else just - // allow 1 handler per-signal. - ACE_Sig_Handlers multi_handlers; - - ACE_Reactor reactor (argc > 1 ? &multi_handlers: 0); - - if (argc > 1) - { - // 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); - - sa.register_action (SIGINT); - } - - // Create a bevy of handlers. - Sig_Handler_1 h1 (reactor, "howdy"), h2 (reactor, "doody"); - Sig_Handler_2 h3 (reactor, "tutty"), h4 (reactor, "fruity"); - - // Wait for user to type SIGINT and SIGQUIT. - - for (;;) - { - ACE_DEBUG ((LM_DEBUG, "\nwaiting for SIGINT or SIGQUIT\n")); - reactor.handle_events (); - } - return 0; -} -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, "The HP C++ compiler is too lame to support this feature\n"), -1); -} -#endif /* HPUX */ diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp deleted file mode 100644 index b7fe34725e7..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Client.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "Semaphore_Test.h" -// $Id$ - -#include "ace/SV_Shared_Memory.h" -#include "ace/SV_Semaphore_Simple.h" - -int -main (void) -{ - ACE_SV_Shared_Memory shm_client (SHM_KEY, - SHMSZ, - ACE_SV_Shared_Memory::ACE_OPEN); - ACE_SV_Semaphore_Simple sem (SEM_KEY_1, - ACE_SV_Semaphore_Simple::ACE_OPEN, 0, 2); - - char *s = (char *) shm_client.get_segment_ptr (); - - if (sem.acquire (0) < 0) - ACE_OS::perror ("client sem.acquire"), ACE_OS::exit (1); - - while (*s != '\0') - putchar (*s++); - - putchar ('\n'); - - if (sem.release (1) < 0) - ACE_OS::perror ("client sem.release"), ACE_OS::exit (1); - - return 0; -} - diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp deleted file mode 100644 index f9931705c26..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Server.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// $Id$ - - -#include "ace/SV_Shared_Memory.h" -#include "ace/SV_Semaphore_Simple.h" -#include "ace/Signal.h" -#include "Semaphore_Test.h" - -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); - -extern "C" void -cleanup (int) -{ - if (shm_server.remove () < 0 || sem.remove () < 0) - ACE_ERROR ((LM_ERROR, "%p\n%a", "remove", 1)); - ACE_OS::exit (0); -} - -int -main (void) -{ - // Register a signal handler. - ACE_Sig_Action sa ((ACE_SignalHandler) cleanup, SIGINT); - - char *s = (char *) shm_server.get_segment_ptr (); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (sem.release (0) < 0) - ESD ("server sem.release", done); - - if (sem.acquire (1) < 0) - ESD ("server sem.acquire", done); - -done: - cleanup (); - return 0; -} diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h b/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h deleted file mode 100644 index 72aab815ff8..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphore_Test.h +++ /dev/null @@ -1,11 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -#include "ace/Log_Msg.h" - -#define SHMSZ 27 -#define SEM_KEY_1 2345 -#define SEM_KEY_2 4321 -#define SHM_KEY 5678 - -#define ESD(MSG,LABEL) do { ACE_ERROR ((LM_ERROR, MSG)); goto LABEL; } while (0) diff --git a/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp b/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp deleted file mode 100644 index b98c664883b..00000000000 --- a/examples/System_V_IPC/SV_Semaphores/Semaphores.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Illustrates the use of the Semaphore_Complex class. Note that it -// $Id$ - -// doesn't matter whether the parent or the child creates the -// semaphore since Semaphore_Complex will correctly serialize the -// intialization of the mutex and synch objects. -#include "ace/Malloc.h" -#include "ace/SV_Semaphore_Complex.h" -#include "Semaphore_Test.h" - -ACE_Malloc<ACE_Shared_Memory_Pool, ACE_SV_Semaphore_Simple> allocator; -ACE_SV_Semaphore_Complex *mutex = 0; -ACE_SV_Semaphore_Complex *synch = 0; - -/* Pointer to memory shared by both the client and server. */ -static char *shm; - -static int -do_parent (void) -{ - char *s = shm; - - mutex = new ACE_SV_Semaphore_Complex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - synch = new ACE_SV_Semaphore_Complex (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - if (mutex->release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p", "server mutex.release"), 1); - - if (synch->acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p", "server synch.acquire"), 1); - return 0; -} - -static int -do_child (void) -{ - mutex = new ACE_SV_Semaphore_Complex (SEM_KEY_1, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - synch = new ACE_SV_Semaphore_Complex (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0); - - while (mutex->tryacquire () == -1) - if (errno == EAGAIN) - ACE_DEBUG ((LM_DEBUG, "spinning in client!\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "client mutex.tryacquire"), 1); - - for (char *s = (char *) shm; *s != '\0'; s++) - putchar (*s); - - putchar ('\n'); - - if (synch->release () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "client synch.release"), 1); - return 0; -} - -int -main (void) -{ - shm = (char *) allocator.malloc (27); - - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "fork failed\n"), -1); - /* NOTREACHED */ - case 0: - return do_child (); - default: - { - int result = do_parent (); - - if (wait (0) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "wait"), -1); - - allocator.remove (); - - if (mutex->remove () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "mutex.remove"), -1); - else if (synch->remove () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "synch.remove"), -1); - return result; - } - } -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Malloc<ACE_Shared_Memory_Pool, ACE_SV_Semaphore_Simple>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - diff --git a/examples/Threads/test_auto_event.cpp b/examples/Threads/test_auto_event.cpp deleted file mode 100644 index 4f83d50db71..00000000000 --- a/examples/Threads/test_auto_event.cpp +++ /dev/null @@ -1,113 +0,0 @@ -// $Id$ - -// This test shows the use of an ACE_Auto_Event as a signaling -// mechanism. Two threads are created (one a reader, the other a -// writer). The reader waits till the writer has completed -// calculations. Upon waking up the reader prints the data calculated -// by the writer. The writer thread calculates the value and signals -// the reader when the calculation completes. - -#include "ace/Service_Config.h" -#include "ace/Synch.h" -#include "ace/Singleton.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_HAS_THREADS) -// Shared event between reader and writer. The ACE_Thread_Mutex is -// necessary to make sure that only one ACE_Auto_Event is created. -// The default constructor for ACE_Auto_Event sets it initially into -// the non-signaled state. - -typedef ACE_Singleton <ACE_Auto_Event, ACE_Thread_Mutex> EVENT; - -// work time for writer -static int work_time; - -// Reader thread. -static void * -reader (void *arg) -{ - // Shared data via a reference. - int& data = *(int *) arg; - - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - - // Wait for writer to complete. - - ACE_DEBUG ((LM_DEBUG, "(%t) reader: waiting...... \n")); - - if (EVENT::instance ()->wait () == -1) - { - ACE_ERROR ((LM_ERROR, "thread wait failed")); - ACE_OS::exit (0); - } - - // Read shared data. - ACE_DEBUG ((LM_DEBUG, "(%t) reader: value of data is: %d \n", data)); - - return 0; -} - -// Writer thread. -static void * -writer (void *arg) -{ - int& data = *(int *) arg; - - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - - // Calculate (work). - ACE_DEBUG ((LM_DEBUG, "(%t) writer: working for %d secs\n", work_time)); - ACE_OS::sleep (work_time); - - // Write shared data. - data = 42; - - // Wake up reader. - ACE_DEBUG ((LM_DEBUG, "(%t) writer: calculation complete, waking reader\n")); - - if (EVENT::instance ()->signal () == -1) - { - ACE_ERROR ((LM_ERROR, "thread wait failed")); - ACE_OS::exit (0); - } - - return 0; -} - -int -main (int argc, char **argv) -{ - // Shared data: set by writer, read by reader. - int data; - - // Work time for writer. - work_time = argc == 2 ? atoi (argv[1]) : 5; - - // threads manager - ACE_Thread_Manager& tm = *ACE_Service_Config::thr_mgr (); - - // Create reader thread. - if (tm.spawn (reader, (void *) &data) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "thread create for reader failed"), -1); - - // Create writer thread. - if (tm.spawn (writer, (void *) &data) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "thread create for writer failed"), -1); - - // Wait for both. - if (tm.wait () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "thread wait failed"), -1); - else - ACE_DEBUG ((LM_ERROR, "graceful exit\n")); - - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_barrier1.cpp b/examples/Threads/test_barrier1.cpp deleted file mode 100644 index 6b213819ca0..00000000000 --- a/examples/Threads/test_barrier1.cpp +++ /dev/null @@ -1,84 +0,0 @@ -// This test program illustrates how the ACE barrier synchronization -// $Id$ - -// mechanisms work. - - -#include "ace/Synch.h" -#include "ace/Thread_Manager.h" -#include "ace/Service_Config.h" - -#if defined (ACE_HAS_THREADS) - -struct Tester_Args - // = TITLE - // These arguments are passed into each test thread. -{ - Tester_Args (ACE_Barrier &tb, int i) - : tester_barrier_ (tb), - n_iterations_ (i) {} - - ACE_Barrier &tester_barrier_; - // Reference to the tester barrier. This controls each miteration of - // the tester function running in every thread. - - int n_iterations_; - // Number of iterations to run. -}; - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -static void * -tester (Tester_Args *args) -{ - // Keeps track of thread exit. - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - - for (int iterations = 1; - iterations <= args->n_iterations_; - iterations++) - { - ACE_DEBUG ((LM_DEBUG, "(%t) in iteration %d\n", iterations)); - - // Block until all other threads have waited, then continue. - args->tester_barrier_.wait (); - } - - return 0; -} - -// Default number of threads to spawn. -static const int DEFAULT_ITERATIONS = 5; - -int -main (int argc, char *argv[]) -{ - ACE_Service_Config daemon (argv[0]); - - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_THREADS; - int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_ITERATIONS; - - ACE_Barrier tester_barrier (n_threads); - - Tester_Args args (tester_barrier, n_iterations); - - if (ACE_Service_Config::thr_mgr ()->spawn_n - (n_threads, ACE_THR_FUNC (tester), - (void *) &args, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn_n"), 1); - - // Wait for all the threads to reach their exit point. - ACE_Service_Config::thr_mgr ()->wait (); - - ACE_DEBUG ((LM_DEBUG, "(%t) done\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_barrier2.cpp b/examples/Threads/test_barrier2.cpp deleted file mode 100644 index 30190ace443..00000000000 --- a/examples/Threads/test_barrier2.cpp +++ /dev/null @@ -1,269 +0,0 @@ -// $Id$ - -// generic_worker_task.cpp -// -// This test program illustrates how the ACE task workers/barrier -// synchronization mechanisms work in conjunction with the ACE_Task -// and the ACE_Thread_Manager. The manual flag not set simulates -// user input, if set input comes from stdin until RETURN only is -// entered which stops all workers via a message block of length -// 0. This is an alernative shutdown of workers compared to queue -// deactivate. The delay_put flag simulates a delay between the -// shutdown puts. All should work with this flag disabled! The -// BARRIER_TYPE is supposed to enable/disable barrier sync on each svc -// a worker has done. - -#include <iostream.h> -#include "ace/Task.h" -#include "ace/Service_Config.h" - -#if defined (ACE_HAS_THREADS) - -#define BARRIER_TYPE ACE_Null_Barrier -//#define BARRIER_TYPE ACE_Barrier -//#ifdef delay_put -//#define manual - -template <class BARRIER> -class Worker_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - - Worker_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int inp_serialize = 1); - - virtual int Producer (void); - // produce input for workers - - virtual int input (ACE_Message_Block *mb); - // Fill one message block via a certain input strategy. - - virtual int output (ACE_Message_Block *mb); - // Forward one message block via a certain output strategy to the - // next task if any. - - virtual int service (ACE_Message_Block *mb, int iter); - // Perform one message block dependant service. - -private: - virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv=0); - - virtual int svc (void); - // Iterate <n_iterations> time printing off a message and "waiting" - // for all other threads to complete this iteration. - - // = Not needed for this test. - virtual int open (void *) { return 0; } - virtual int close (u_long) {ACE_DEBUG ((LM_DEBUG,"(%t) in close of worker\n")); return 0; } - - int nt_; - // Number of worker threads to run. - int inp_serialize_; - - BARRIER barrier_; -}; - -template <class BARRIER> -Worker_Task<BARRIER>::Worker_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int inp_serialize) - : ACE_Task<ACE_MT_SYNCH> (thr_mgr), - barrier_ (n_threads) -{ - nt_ = n_threads; - // Create worker threads. - inp_serialize_ = inp_serialize; - - // Use the task's message queue for serialization (default) or run - // service in the context of the caller thread. - - if (nt_ > 0 && inp_serialize == 1) - if (this->activate (THR_NEW_LWP, n_threads) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); -} - -// Simply enqueue the Message_Block into the end of the queue. - -template <class BARRIER> int -Worker_Task<BARRIER>::put (ACE_Message_Block *mb, ACE_Time_Value *tv) -{ - int result; - if (this->inp_serialize_) - result = this->putq (mb, tv); - else - { - static int iter = 0; - result = this->service (mb, iter++); - - if (this->output (mb) < 0) - ACE_DEBUG ((LM_DEBUG, "(%t) output not connected!\n")); - - delete mb; - } - return result; -} - -template <class BARRIER> int -Worker_Task<BARRIER>::service (ACE_Message_Block *mb, int iter) -{ - int length = mb->length (); - - if (length > 0) - { - ACE_DEBUG ((LM_DEBUG,"(%t) in iteration %d len=%d text got:\n",iter,length)); - ACE_OS::write (ACE_STDOUT, mb->rd_ptr (), length); - ACE_DEBUG ((LM_DEBUG,"\n")); - } - return 0; -} - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -template <class BARRIER> int -Worker_Task<BARRIER>::svc (void) -{ - // Note that the ACE_Task::svc_run () method automatically adds us - // to the Thread_Manager when the thread begins. - - // Keep looping, reading a message out of the queue, until we get a - // message with a length == 0, which signals us to quit. - - for (int iter = 1; ;iter++) - { - ACE_Message_Block *mb = 0; - - int result = this->getq (mb); - - if (result == -1) - { - ACE_ERROR ((LM_ERROR, - "(%t) in iteration %d\n", "error waiting for message in iteration", iter)); - break; - } - - int length = mb->length (); - this->service (mb,iter); - - if (length == 0) - { - ACE_DEBUG ((LM_DEBUG, "(%t) in iteration %d got quit, exit!\n", iter)); - delete mb; - break; - } - - this->barrier_.wait (); - this->output (mb); - - delete mb; - } - - // Note that the ACE_Task::svc_run () method automatically removes - // us from the Thread_Manager when the thread exits. - - return 0; -} - -template <class BARRIER> int -Worker_Task<BARRIER>::Producer (void) -{ - // Keep reading stdin, until we reach EOF. - - for (;;) - { - // Allocate a new message. - ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ); - - if (this->input (mb) == -1) - return -1; - } - - return 0; -} - -template <class BARRIER>int -Worker_Task<BARRIER>::output (ACE_Message_Block *mb) -{ - return this->put_next (mb); -} - -template <class BARRIER>int -Worker_Task<BARRIER>::input (ACE_Message_Block *mb) -{ - ACE_Message_Block *mb1; - -#ifndef manual - static int l= 0; - char str[]="kalle"; - strcpy (mb->rd_ptr (),str); - int n=strlen (str); - if (l==1000) - n=1; - l++; - if (l==0 || (l%100 == 0)) ACE_OS::sleep (5); - if (n <= 1) -#else - ACE_DEBUG ((LM_DEBUG,"(%t) press chars and enter to put a new message into task queue ...\n")); - if ((n = read (0, mb->rd_ptr (), mb->size ())) <= 1) -#endif // manual - { - // Send a shutdown message to the waiting threads and exit. - // cout << "\nvor loop, dump of task msg queue:\n" << endl; - // this->msg_queue ()->dump (); - for (int i=0;i<nt_;i++) - { - ACE_DEBUG ((LM_DEBUG,"(%t) eof, sending block for thread=%d\n",i+1)); - mb1 = new ACE_Message_Block (2); - mb1->length (0); - if (this->put (mb1) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put")); -#ifdef delay_put - ACE_OS::sleep (1); // this sleep helps to shutdown correctly -> was an error! -#endif /* delay_put */ - } - // cout << "\nnach loop, dump of task msg queue:\n" << endl; - // this->msg_queue ()->dump (); - return (-1); - } - else - { - // Send a normal message to the waiting threads and continue producing. - mb->wr_ptr (n); - if (this->put (mb) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put")); - } - return 0; -} - -int -main (int argc, char *argv[]) -{ - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_THREADS; - - ACE_DEBUG ((LM_DEBUG,"(%t) worker threads running=%d\n",n_threads)); - - - Worker_Task<BARRIER_TYPE> *worker_task = - new Worker_Task<BARRIER_TYPE> (ACE_Service_Config::thr_mgr (), - /*n_threads*/ 0,0); - - worker_task->Producer (); - - // Wait for all the threads to reach their exit point. - ACE_DEBUG ((LM_DEBUG,"(%t) waiting with thread manager ...\n")); - ACE_Service_Config::thr_mgr ()->wait (); - ACE_DEBUG ((LM_DEBUG,"(%t) delete worker task ...\n")); - - delete worker_task; - ACE_DEBUG ((LM_DEBUG,"(%t) done correct!\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_cancel.cpp b/examples/Threads/test_cancel.cpp deleted file mode 100644 index a9d12bea579..00000000000 --- a/examples/Threads/test_cancel.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Test out the cooperative thread cancellation mechanisms provided by -// $Id$ - -// the ACE_Thread_Manager. - -#include "ace/Service_Config.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_HAS_THREADS) - -static void * -worker (int iterations) -{ - for (int i = 0; i < iterations; i++) - { - if ((i % 10) == 0 - && (ACE_Service_Config::thr_mgr ()->testcancel (ACE_Thread::self ()) != 0)) - { - ACE_DEBUG ((LM_DEBUG, "(%t) has been cancelled before iteration!\n", i)); - break; - } - } - - return 0; -} - -static const int DEFAULT_THREADS = ACE_DEFAULT_THREADS; -static const int DEFAULT_ITERATIONS = 100000; - -int -main (int argc, char *argv[]) -{ - ACE_Service_Config daemon; - - daemon.open (argv[0]); - - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_THREADS; - int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_ITERATIONS; - - ACE_Thread_Manager *thr_mgr = ACE_Service_Config::thr_mgr (); - - int grp_id = thr_mgr->spawn_n (n_threads, ACE_THR_FUNC (worker), - (void *) n_iterations, - THR_NEW_LWP | THR_DETACHED); - - // Wait for 2 seconds and then suspend every thread in the group. - ACE_OS::sleep (2); - thr_mgr->suspend_grp (grp_id); - - // Wait for 2 more seconds and then resume every thread in the - // group. - ACE_OS::sleep (ACE_Time_Value (2)); - thr_mgr->resume_grp (grp_id); - - // Wait for 2 more seconds and then send a SIGINT to every thread in - // the group. - ACE_OS::sleep (ACE_Time_Value (2)); - thr_mgr->kill_grp (grp_id, SIGINT); - - // Wait for 2 more seconds and then exit (which should kill all the - // threads)! - ACE_OS::sleep (ACE_Time_Value (2)); - - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR_RETURN ((LM_ERROR, "threads not supported on this platform\n"), -1); -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_future1.cpp b/examples/Threads/test_future1.cpp deleted file mode 100644 index 1c00a786295..00000000000 --- a/examples/Threads/test_future1.cpp +++ /dev/null @@ -1,420 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// Test_Future.cpp -// -// = DESCRIPTION -// This example tests the ACE Future. -// -// = AUTHOR -// Andres Kruse <Andres.Kruse@cern.ch> and Douglas C. Schmidt -// <schmidt@cs.wustl.edu> -// -// ============================================================================ - -#include <math.h> -#include "ace/Task.h" - -#include "ace/Synch.h" -#include "ace/Message_Queue.h" -#include "ace/Future.h" -#include "ace/Method_Object.h" -#include "ace/Activation_Queue.h" -#include "ace/Auto_Ptr.h" - -#if defined (ACE_HAS_THREADS) - -typedef ACE_Atomic_Op<ACE_Thread_Mutex, u_long> ATOMIC_INT; - -// a counter for the tasks.. -static ATOMIC_INT task_count (0); - -// a counter for the futures.. -static ATOMIC_INT future_count (0); -static ATOMIC_INT future_no (0); - -// a counter for the capsules.. -static ATOMIC_INT capsule_count (0); -static ATOMIC_INT capsule_no (0); - -// a counter for the method objects... -static ATOMIC_INT methodobject_count (0); -static ATOMIC_INT methodobject_no (0); - -class Scheduler : public ACE_Task<ACE_MT_SYNCH> - // = TITLE - // Active Object Scheduler. -{ - friend class Method_ObjectWork; -public: - Scheduler (const char *, Scheduler * = 0); - ~Scheduler (void); - - virtual int open (void *args = 0); - virtual int close (u_long flags = 0); - virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv = 0); - virtual int svc (void); - - ACE_Future<float> work (float param, int count); - ACE_Future<const char*> name (void); - void end (void); - - float work_i (float, int); - const char *name_i (void); - -private: - char *name_; - ACE_Activation_Queue activation_queue_; - Scheduler *scheduler_; - -}; - -class Method_Object_work : public ACE_Method_Object - // = TITLE - // Reification of the <work> method. -{ -public: - Method_Object_work (Scheduler *, float, int, ACE_Future<float> &); - ~Method_Object_work (void); - virtual int call (void); - -private: - Scheduler *scheduler_; - float param_; - int count_; - ACE_Future<float> future_result_; -}; - -Method_Object_work::Method_Object_work (Scheduler* new_Scheduler, - float new_param, - int new_count, - ACE_Future<float> &new_result) - : scheduler_ (new_Scheduler), - param_ (new_param), - count_ (new_count), - future_result_ (new_result) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) Method_Object_work created\n")); -} - -Method_Object_work::~Method_Object_work (void) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) Method_Object_work will be deleted.\n")); -} - - -int -Method_Object_work::call (void) -{ - return this->future_result_.set (this->scheduler_->work_i (this->param_, this->count_)); -} - -class Method_Object_name : public ACE_Method_Object - // = TITLE - // Reification of the <name> method. -{ -public: - Method_Object_name (Scheduler *, ACE_Future<const char*> &); - ~Method_Object_name (void); - virtual int call (void); - -private: - Scheduler *scheduler_; - ACE_Future<const char*> future_result_; -}; - -Method_Object_name::Method_Object_name (Scheduler *new_scheduler, - ACE_Future<const char*> &new_result) - : scheduler_ (new_scheduler), - future_result_ (new_result) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) Method_Object_name created\n")); -}; - -Method_Object_name::~Method_Object_name (void) -{ - ACE_DEBUG ((LM_DEBUG, - "(%t) Method_Object_name will be deleted.\n")); -} - -int -Method_Object_name::call (void) -{ - return future_result_.set (scheduler_->name_i ()); -} - -class Method_Object_end : public ACE_Method_Object - // = TITLE - // Reification of the <end> method. -{ -public: - Method_Object_end (Scheduler *new_Scheduler): scheduler_ (new_Scheduler) {} - ~Method_Object_end (void) {} - virtual int call (void) { this->scheduler_->close (); return -1; } - -private: - Scheduler *scheduler_; -}; - -// constructor -Scheduler::Scheduler (const char *newname, Scheduler *new_Scheduler) -{ - ACE_NEW (this->name_, char[ACE_OS::strlen (newname) + 1]); - ACE_OS::strcpy ((char *) this->name_, newname); - this->scheduler_ = new_Scheduler; - ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s created\n", this->name_)); -} - -// Destructor -Scheduler::~Scheduler (void) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s will be destroyed\n", this->name_)); -} - -// open -int -Scheduler::open (void *) -{ - task_count++; - ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s open\n", this->name_)); - return this->activate (THR_BOUND); -} - -// close -int -Scheduler::close (u_long) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s close\n", this->name_)); - task_count--; - return 0; -} - -// put... ?? -int -Scheduler::put (ACE_Message_Block *, ACE_Time_Value *) -{ - return 0; -} - -// service.. -int -Scheduler::svc (void) -{ - for (;;) - { - // Dequeue the next method object (we use an auto pointer in - // case an exception is thrown in the <call>). - auto_ptr<ACE_Method_Object> mo (this->activation_queue_.dequeue ()); - - ACE_DEBUG ((LM_DEBUG, "(%t) calling method object\n")); - // Call it. - if (mo->call () == -1) - break; - // Destructor automatically deletes it. - } - - /* NOTREACHED */ - return 0; -} - -void -Scheduler::end (void) -{ - this->activation_queue_.enqueue (new Method_Object_end (this)); -} - - -// Here's where the Work takes place. -float -Scheduler::work_i (float param, - int count) -{ - float x = 0, y = 0; - - // @@ We should probably do something fun here, like compute the - // Fibonacci sequence or something. - - for (int j = 0; j < count; j++) - { - x = x + param; - y = y + ::sin (x); - } - - return y; -} - -const char * -Scheduler::name_i (void) -{ - char *the_name; - - the_name = new char[ACE_OS::strlen (this->name_) + 1]; - ACE_OS::strcpy (the_name, this->name_); - - return the_name; -} - -ACE_Future<const char *> -Scheduler::name (void) -{ - if (this->scheduler_) - // Delegate to the Scheduler. - return this->scheduler_->name (); - else - { - ACE_Future<const char*> new_future; - - // @@ What happens if new fails here? - this->activation_queue_.enqueue - (new Method_Object_name (this, new_future)); - - return new_future; - } -} - -ACE_Future<float> -Scheduler::work (float newparam, int newcount) -{ - if (this->scheduler_) { - return this->scheduler_->work (newparam, newcount); - } - else { - ACE_Future<float> new_future; - - this->activation_queue_.enqueue - (new Method_Object_work (this, newparam, newcount, new_future)); - return new_future; - } -} - -// @@ These values should be set by the command line options! - -// Total number of iterations to <work> -static int n_iterations = 50000; - -// Total number of loops. -static int n_loops = 100; - -int -main (int, char *[]) -{ - Scheduler *andres, *peter, *helmut, *matias; - - // Create active objects.. - // @@ Should "open" be subsumed within the constructor of - // Scheduler()? - andres = new Scheduler ("andres"); - andres->open (); - peter = new Scheduler ("peter"); - peter->open (); - helmut = new Scheduler ("helmut"); - helmut->open (); - - // Matias passes all asynchronous method calls on to Andres... - matias = new Scheduler ("matias", andres); - matias->open (); - - for (int i = 0; i < n_loops; i++) - { - { - ACE_Future<float> fresulta, fresultb, fresultc, fresultd, fresulte; - ACE_Future<const char*> fname; - - ACE_DEBUG ((LM_DEBUG, "(%t) going to do a non-blocking call\n")); - - fresulta = andres->work (0.01, 100 + (n_iterations * (i % 2))); - fresultb = peter->work (0.01, 100 + (n_iterations * (i % 2))); - fresultc = helmut->work (0.01, 100 + (n_iterations * (i % 2))); - fresultd = matias->work (0.02, 100 + (n_iterations * (i % 2))); - fname = andres->name (); - - // see if the result is available... - if (fresulta.ready ()) - ACE_DEBUG ((LM_DEBUG, "(%t) wow.. work is ready.....\n")); - - ACE_DEBUG ((LM_DEBUG, "(%t) non-blocking call done... now blocking...\n")); - - // Save the result of fresulta. - - fresulte = fresulta; - - if (i % 3 == 0) - { - // Every 3rd time... disconnect the futures... - // but "fresulte" should still contain the result... - fresulta.cancel (10.0); - fresultb.cancel (20.0); - fresultc.cancel (30.0); - fresultd.cancel (40.0); - } - - float resulta = 0, resultb = 0, resultc = 0, resultd = 0, resulte = 0; - - fresulta.get (resulta); - fresultb.get (resultb); - fresultc.get (resultc); - fresultd.get (resultd); - fresulte.get (resulte); - - ACE_DEBUG ((LM_DEBUG, "(%t) result a %f\n", resulte)); - ACE_DEBUG ((LM_DEBUG, "(%t) result b %f\n", resulta)); - ACE_DEBUG ((LM_DEBUG, "(%t) result c %f\n", resultb)); - ACE_DEBUG ((LM_DEBUG, "(%t) result d %f\n", resultc)); - ACE_DEBUG ((LM_DEBUG, "(%t) result e %f\n", resultd)); - - const char *name; - - fname.get (name); - - ACE_DEBUG ((LM_DEBUG, "(%t) name %s\n", name)); - - } - - ACE_DEBUG ((LM_DEBUG, - "(%t) task_count %d future_count %d capsule_count %d methodobject_count %d\n", - (u_long) task_count, - (u_long) future_count, - (u_long) capsule_count, - (u_long) methodobject_count)); - } - - // Close things down. - andres->end (); - peter->end (); - helmut->end (); - matias->end (); - - ACE_OS::sleep (2); - - ACE_DEBUG ((LM_DEBUG, - "(%t) task_count %d future_count %d capsule_count %d methodobject_count %d\n", - (u_long) task_count, - (u_long) future_count, - (u_long) capsule_count, - (u_long) methodobject_count)); - - ACE_DEBUG ((LM_DEBUG,"(%t) th' that's all folks!\n")); - - ACE_OS::sleep (5); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Atomic_Op<ACE_Thread_Mutex, u_long>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_future2.cpp b/examples/Threads/test_future2.cpp deleted file mode 100644 index 3376008ab50..00000000000 --- a/examples/Threads/test_future2.cpp +++ /dev/null @@ -1,524 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// Test_Future.cpp -// -// = DESCRIPTION -// This example tests the ACE Future. -// -// = AUTHOR -// Andres Kruse <Andres.Kruse@cern.ch> and Douglas C. Schmidt -// <schmidt@cs.wustl.edu> -// -// Modification History -// Aug. 96; A.Kruse; dev. -// Aug. 96; D.Schmidt; complete workover -// 08/27/96; A.Kruse; - the friends of Scheduler are "Method_Object_name" -// and "Method_Object_work". -// - make the methods "work_i" and "name_i" private -// 09/2/96; D.Schmidt; Integrate with new ACE_Future API and rearrange -// the tests so they are more modular. -// ============================================================================ - -#include <math.h> -#include "ace/Task.h" - -#include "ace/Synch.h" -#include "ace/Message_Queue.h" -#include "ace/Future.h" -#include "ace/Method_Object.h" -#include "ace/Activation_Queue.h" -#include "ace/Auto_Ptr.h" - -#if defined (ACE_HAS_THREADS) - -typedef ACE_Atomic_Op<ACE_Thread_Mutex, u_long> ATOMIC_INT; - -// a counter for the tasks.. -static ATOMIC_INT scheduler_open_count (0); - -// forward declarations -class Method_Object_work; -class Method_Object_name; - -class Scheduler : public ACE_Task<ACE_MT_SYNCH> - // = TITLE - // Active Object Scheduler. -{ - // Every method object has to be able to access the private methods. - - friend class Method_Object_work; - friend class Method_Object_name; - friend class Method_Object_end; -public: - - Scheduler (const char *, Scheduler * = 0); - ~Scheduler (void); - - virtual int open (void *args = 0); - // The method that is used to start the active object. - - // = Here are the methods exported by the class. They return an - // <ACE_Future>. - ACE_Future<float> work (float param, int count); - ACE_Future<char*> name (void); - void end (void); - -private: - virtual int close (u_long flags = 0); - // Should not be accessible from outside... (use end () instead). - - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0) - { return 0; }; - // Doesn't have any use for this example. - - virtual int svc (void); - // Here the actual servicing of all requests is happening.. - - // = Implementation methods. - float work_i (float, int); - char *name_i (void); - - char *name_; - ACE_Activation_Queue activation_queue_; - Scheduler *scheduler_; -}; - -class Method_Object_work : public ACE_Method_Object - // = TITLE - // Reification of the <work> method. -{ -public: - Method_Object_work (Scheduler *, float, int, ACE_Future<float> &); - ~Method_Object_work (void); - virtual int call (void); - -private: - Scheduler *scheduler_; - float param_; - int count_; - ACE_Future<float> future_result_; -}; - -Method_Object_work::Method_Object_work (Scheduler* new_Scheduler, - float new_param, - int new_count, - ACE_Future<float> &new_result) - : scheduler_ (new_Scheduler), - param_ (new_param), - count_ (new_count), - future_result_ (new_result) -{ -} - -Method_Object_work::~Method_Object_work (void) -{ -} - -int -Method_Object_work::call (void) -{ - return this->future_result_.set (this->scheduler_->work_i (this->param_, this->count_)); -} - -class Method_Object_name : public ACE_Method_Object - // = TITLE - // Reification of the <name> method. -{ -public: - Method_Object_name (Scheduler *, ACE_Future<char*> &); - ~Method_Object_name (void); - virtual int call (void); - -private: - Scheduler *scheduler_; - ACE_Future<char*> future_result_; -}; - - -Method_Object_name::Method_Object_name (Scheduler *new_scheduler, - ACE_Future<char*> &new_result) - : scheduler_ (new_scheduler), - future_result_ (new_result) -{ - ACE_DEBUG ((LM_DEBUG, - " (%t) Method_Object_name created\n")); -}; - -Method_Object_name::~Method_Object_name (void) -{ - ACE_DEBUG ((LM_DEBUG, - " (%t) Method_Object_name will be deleted.\n")); -} - -int -Method_Object_name::call (void) -{ - return future_result_.set (scheduler_->name_i ()); -} - -class Method_Object_end : public ACE_Method_Object - // = TITLE - // Reification of the <end> method. -{ -public: - Method_Object_end (Scheduler *new_Scheduler): scheduler_ (new_Scheduler) {} - ~Method_Object_end (void) {} - virtual int call (void) { this->scheduler_->close (); return -1; } - -private: - Scheduler *scheduler_; -}; - -// constructor -Scheduler::Scheduler (const char *newname, Scheduler *new_Scheduler) -{ - ACE_NEW (this->name_, char[ACE_OS::strlen (newname) + 1]); - ACE_OS::strcpy ((char *) this->name_, newname); - this->scheduler_ = new_Scheduler; - ACE_DEBUG ((LM_DEBUG, " (%t) Scheduler %s created\n", this->name_)); -} - -// Destructor -Scheduler::~Scheduler (void) -{ - ACE_DEBUG ((LM_DEBUG, " (%t) Scheduler %s will be destroyed\n", this->name_)); -} - -int -Scheduler::open (void *) -{ - scheduler_open_count++; - ACE_DEBUG ((LM_DEBUG, " (%t) Scheduler %s open\n", this->name_)); - return this->activate (THR_BOUND); -} - -int -Scheduler::close (u_long) -{ - ACE_DEBUG ((LM_DEBUG, " (%t) Scheduler %s close\n", this->name_)); - scheduler_open_count--; - return 0; -} - -int -Scheduler::svc (void) -{ - // Main event loop for this active object. - for (;;) - { - // Dequeue the next method object (we use an auto pointer in - // case an exception is thrown in the <call>). - auto_ptr<ACE_Method_Object> mo (this->activation_queue_.dequeue ()); - - ACE_DEBUG ((LM_DEBUG, " (%t) calling method object\n")); - // Call it. - if (mo->call () == -1) - break; - // Smart pointer destructor automatically deletes mo. - } - - /* NOTREACHED */ - return 0; -} - -void -Scheduler::end (void) -{ - this->activation_queue_.enqueue (new Method_Object_end (this)); -} - -// Here's where the Work takes place. -float -Scheduler::work_i (float param, - int count) -{ - float x = 0, y = 0; - - for (int j = 0; j < count; j++) - { - x = x + param; - y = y + ::sin (x); - } - - return y; -} - -char * -Scheduler::name_i (void) -{ - char *the_name; - - the_name = new char[ACE_OS::strlen (this->name_) + 1]; - ACE_OS::strcpy (the_name, this->name_); - - return the_name; -} - -ACE_Future<char *> -Scheduler::name (void) -{ - if (this->scheduler_) - // Delegate to the other scheduler - return this->scheduler_->name (); - else - { - ACE_Future<char*> new_future; - - if (this->thr_count () == 0) - { - // This scheduler is inactive... so we execute the user - // request right away... - - auto_ptr<ACE_Method_Object> mo (new Method_Object_name (this, new_future)); - - mo->call (); - // Smart pointer destructor automatically deletes mo. - } - else - // @@ What happens if new fails here? - this->activation_queue_.enqueue - (new Method_Object_name (this, new_future)); - - return new_future; - } -} - -ACE_Future<float> -Scheduler::work (float newparam, int newcount) -{ - if (this->scheduler_) - return this->scheduler_->work (newparam, newcount); - else - { - ACE_Future<float> new_future; - - if (this->thr_count () == 0) - { - auto_ptr<ACE_Method_Object> mo - (new Method_Object_work (this, newparam, newcount, new_future)); - mo->call (); - // Smart pointer destructor automatically deletes it. - } - else - this->activation_queue_.enqueue - (new Method_Object_work (this, newparam, newcount, new_future)); - - return new_future; - } -} - -static int -determine_iterations (void) -{ - int n_iterations; - - ACE_DEBUG ((LM_DEBUG," (%t) determining the number of iterations...\n")); - Scheduler *worker_a = new Scheduler ("worker A"); - - ACE_Time_Value tstart (ACE_OS::gettimeofday ()); - ACE_Time_Value tend (ACE_OS::gettimeofday ()); - - // Determine the number of iterations... we want so many that the - // work () takes about 1 second... - - for (n_iterations = 1; - (tend.sec () - tstart.sec ()) < 1; - n_iterations *= 2) - { - tstart = ACE_OS::gettimeofday (); - - worker_a->work (0.1, n_iterations); - - tend = ACE_OS::gettimeofday (); - } - - ACE_DEBUG ((LM_DEBUG," (%t) n_iterations %d\n", - (u_long) n_iterations)); - - worker_a->end (); - // @@ Can we safely delete worker_a here? - return n_iterations; -} - -static void -test_active_object (int n_iterations) -{ - ACE_DEBUG ((LM_DEBUG," (%t) testing active object pattern...\n")); - // A simple example for the use of the active object pattern and - // futures to return values from an active object. - - Scheduler *worker_a = new Scheduler ("worker A"); - Scheduler *worker_b = new Scheduler ("worker B"); - - // Have worker_c delegate his work to worker_a. - Scheduler *worker_c = new Scheduler ("worker C", worker_a); - - // loop 0: - // test the Schedulers when they are not active. - // now the method objects will be created but since - // there is no active thread they will also be - // immediately executed, in the "main" thread. - // loop 1: - // do the same test but with the schedulers - // activated - for (int i = 0; i < 2; i++) - { - if (i == 1) - { - worker_a->open (); - worker_b->open (); - worker_c->open (); - } - - ACE_Future<float> fresulta = worker_a->work (0.01, n_iterations); - ACE_Future<float> fresultb = worker_b->work (0.02, n_iterations); - ACE_Future<float> fresultc = worker_c->work (0.03, n_iterations); - - if (i == 0) - { - if (!fresulta.ready ()) - ACE_DEBUG ((LM_DEBUG," (%t) ERROR: worker A is should be ready!!!\n")); - if (!fresultb.ready ()) - ACE_DEBUG ((LM_DEBUG," (%t) ERROR: worker B is should be ready!!!\n")); - if (!fresultc.ready ()) - ACE_DEBUG ((LM_DEBUG," (%t) ERROR: worker C is should be ready!!!\n")); - } - - // When the workers are active we will block here until the - // results are available. - - float resulta = fresulta; - float resultb = fresultb; - float resultc = fresultc; - - ACE_Future<char *> fnamea = worker_a->name (); - ACE_Future<char *> fnameb = worker_b->name (); - ACE_Future<char *> fnamec = worker_c->name (); - - char *namea = fnamea; - char *nameb = fnameb; - char *namec = fnamec; - - ACE_DEBUG ((LM_DEBUG, " (%t) result from %s %f\n", - namea, resulta)); - ACE_DEBUG ((LM_DEBUG, " (%t) result from %s %f\n", - nameb, resultb)); - ACE_DEBUG ((LM_DEBUG, " (%t) result from %s %f\n", - namec, resultc)); - } - - ACE_DEBUG ((LM_DEBUG, " (%t) scheduler_open_count %d before end ()\n", - (u_long) scheduler_open_count)); - - worker_a->end (); - worker_b->end (); - worker_c->end (); - - ACE_DEBUG ((LM_DEBUG, " (%t) scheduler_open_count %d immediately after end ()\n", - (u_long) scheduler_open_count)); - - ACE_OS::sleep (2); - - ACE_DEBUG ((LM_DEBUG, " (%t) scheduler_open_count %d after waiting\n", - (u_long) scheduler_open_count)); - // @@ Can we safely delete worker_a, worker_b, and worker_c? -} - -static void -test_cancellation (int n_iterations) -{ - ACE_DEBUG ((LM_DEBUG," (%t) testing cancellation of a future...\n")); - - // Now test the cancelling a future. - - Scheduler *worker_a = new Scheduler ("worker A"); - worker_a->open (); - - ACE_Future<float> fresulta = worker_a->work (0.01, n_iterations); - - // save the result by copying the future - ACE_Future<float> fresultb = fresulta; - - // now we cancel the first future.. but the - // calculation will still go on... - fresulta.cancel (10.0); - - if (!fresulta.ready ()) - ACE_DEBUG ((LM_DEBUG," (%t) ERROR: future A is should be ready!!!\n")); - - float resulta = fresulta; - - ACE_DEBUG ((LM_DEBUG, " (%t) cancelled result %f\n", resulta)); - - if (resulta != 10.0) - ACE_DEBUG ((LM_DEBUG, " (%t) cancelled result should be 10.0!!\n", resulta)); - - resulta = fresultb; - - ACE_DEBUG ((LM_DEBUG, " (%t) true result %f\n", resulta)); - - worker_a->end (); - // @@ Can we safely delete worker_a here? -} - -static void -test_timeout (int n_iterations) -{ - ACE_DEBUG ((LM_DEBUG," (%t) testing timeout on waiting for the result...\n")); - Scheduler *worker_a = new Scheduler ("worker A"); - worker_a->open (); - - ACE_Future<float> fresulta = worker_a->work (0.01, 2 * n_iterations); - - // Should immediately return... and we should see an error... - ACE_Time_Value *delay = new ACE_Time_Value (1); - - float resulta; - fresulta.get (resulta, delay); - - if (fresulta.ready ()) - ACE_DEBUG ((LM_DEBUG," (%t) ERROR: future A is should not be ready!!!\n")); - else - ACE_DEBUG ((LM_DEBUG," (%t) timed out on future A\n")); - - // now we wait until we are done... - fresulta.get (resulta); - ACE_DEBUG ((LM_DEBUG, " (%t) result %f\n", resulta)); - - worker_a->end (); - // @@ Can we safely delete worker_a here? -} - -int -main (int, char *[]) -{ - int n_iterations = determine_iterations (); - - test_active_object (n_iterations); - test_cancellation (n_iterations); - test_timeout (n_iterations); - - ACE_DEBUG ((LM_DEBUG," (%t) that's all folks!\n")); - - ACE_OS::sleep (5); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Atomic_Op<ACE_Thread_Mutex, u_long>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_manual_event.cpp b/examples/Threads/test_manual_event.cpp deleted file mode 100644 index 26d477fabc0..00000000000 --- a/examples/Threads/test_manual_event.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// The test shows the use of an ACE_Manual_Event to create a -// $Id$ - -// Pseudo_Barrier. Multiple threads are created which do the -// following: -// -// 1. work -// 2. synch with other threads -// 3. more work -// -// ACE_Manual_Event is use to synch with other -// threads. ACE_Manual_Event::signal() is used for broadcasting. - -#include "ace/Service_Config.h" -#include "ace/Synch.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_HAS_THREADS) -static ACE_Atomic_Op <ACE_Thread_Mutex, u_long> amount_of_work = (u_long) 0; - -class Pseudo_Barrier - // = TITLE - // A barrier class using ACE manual-reset events. - // - // = DESCRIPTION - // This is *not* a real barrier. - // Pseudo_Barrier is more like a ``one shot'' barrier. - // All waiters after the Nth waiter are allowed to go. - // The barrier does not reset after the Nth waiter. - // For an example of a real barrier, please see class ACE_Barrier. -{ -public: - Pseudo_Barrier (u_long count); - - int wait (void); - -private: - ACE_Atomic_Op <ACE_Thread_Mutex, u_long> counter_; - ACE_Manual_Event event_; -}; - -Pseudo_Barrier::Pseudo_Barrier (u_long count) - : counter_ (count) -{ -} - -int -Pseudo_Barrier::wait (void) -{ - if (--this->counter_ == 0) - return this->event_.signal (); - else - return this->event_.wait (); -} - -static void * -worker (void *arg) -{ - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - Pseudo_Barrier &barrier = *(Pseudo_Barrier *) arg; - - // work - ACE_DEBUG ((LM_DEBUG, "(%t) working (%d secs)\n", ++::amount_of_work)); - ACE_OS::sleep (::amount_of_work); - - // synch with everybody else - ACE_DEBUG ((LM_DEBUG, "(%t) waiting to synch with others \n")); - barrier.wait (); - - // more work - ACE_DEBUG ((LM_DEBUG, "(%t) more work (%d secs)\n", ++::amount_of_work)); - ACE_OS::sleep (amount_of_work); - - ACE_DEBUG ((LM_DEBUG, "(%t) dying \n")); - - return 0; -} - -int -main (int argc, char **argv) -{ - int n_threads = argc == 2 ? atoi (argv[1]) : 5; - - ACE_Thread_Manager &tm = *ACE_Service_Config::thr_mgr (); - - // synch object shared by all threads - Pseudo_Barrier barrier (n_threads); - - // create workers - if (tm.spawn_n (n_threads, worker, &barrier) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "thread creates for worker failed"), -1); - - // wait for all workers to exit - if (tm.wait () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "thread wait failed"), -1); - else - ACE_DEBUG ((LM_ERROR, "graceful exit\n")); - - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_process_mutex.cpp b/examples/Threads/test_process_mutex.cpp deleted file mode 100644 index fb23c8b73be..00000000000 --- a/examples/Threads/test_process_mutex.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// $Id$ - -// This program tests ACE_Process_Mutexes. To run it, open 3 or 4 -// windows and run this program in each window... - -#include "ace/Synch.h" -#include "ace/Signal.h" - -#if defined (ACE_HAS_THREADS) - -static sig_atomic_t done; - -extern "C" void -handler (int) -{ - done = 1; -} - -int -main (int argc, char *argv[]) -{ - char *name = argc > 1 ? argv[1] : "hello"; - int iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : 100; - - ACE_Process_Mutex pm (name); - - // 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) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "acquire failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquired\n")); - - ACE_OS::sleep (3); - - if (pm.release () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); - - if (pm.tryacquire () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "tryacquire failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = tryacquire\n")); - - if (pm.release () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); - } - - if (argc > 2) - pm.remove (); - return 0; -} -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "ACE doesn't support support threads on this platform (yet)\n"), - -1); -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_process_semaphore.cpp b/examples/Threads/test_process_semaphore.cpp deleted file mode 100644 index d7933897f8e..00000000000 --- a/examples/Threads/test_process_semaphore.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// $Id$ - -// This program tests ACE_Process_Semaphore. To run it, open 3 or 4 -// windows and run this program in each window... - -#include "ace/Synch.h" -#include "ace/Signal.h" - -static sig_atomic_t done; - -extern "C" void -handler (int) -{ - done = 1; -} - -int -main (int argc, char *argv[]) -{ - char *name = argc == 1 ? "hello" : argv[1]; - - ACE_Process_Semaphore pm (1, name); - - ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); - - for (int i = 0; i < 100 && !done; i++) - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquiring\n")); - if (pm.acquire () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "acquire failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquired\n")); - - ACE_OS::sleep (3); - - if (pm.release () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); - - if (pm.tryacquire () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "tryacquire failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = tryacquire\n")); - - if (pm.release () == -1) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); - } - - if (argc > 2) - pm.remove (); - return 0; -} - diff --git a/examples/Threads/test_reader_writer.cpp b/examples/Threads/test_reader_writer.cpp deleted file mode 100644 index ef888133d83..00000000000 --- a/examples/Threads/test_reader_writer.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// This test program verifies the functionality of the ACE_OS -// $Id$ - -// implementation of readers/writer locks on Win32 and Posix pthreads. - - -#include "ace/Synch.h" -#include "ace/Thread.h" -#include "ace/Thread_Manager.h" -#include "ace/Get_Opt.h" - -#if defined (ACE_HAS_THREADS) - -// Default number of iterations. -static size_t n_iterations = 1000; - -// Default number of loops. -static size_t n_loops = 100; - -// Default number of readers. -static size_t n_readers = 6; - -// Default number of writers. -static size_t n_writers = 2; - -// Thread id of last writer. -volatile static int shared_data; - -// Lock for shared_data. -static ACE_RW_Mutex rw_mutex; - -// Count of the number of readers and writers. -ACE_Atomic_Op<ACE_Thread_Mutex, int> current_readers, current_writers; - -// Thread manager -static ACE_Thread_Manager thr_mgr; - -// Explain usage and exit. -static void -print_usage_and_die (void) -{ - ACE_DEBUG ((LM_DEBUG, - "usage: %n [-r n_readers] [-w n_writers] [-n iteration_count]\n")); - ACE_OS::exit (1); -} - -// Parse the command-line arguments and set options. -static void -parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opt (argc, argv, "r:w:n:l:"); - - int c; - - while ((c = get_opt ()) != -1) - switch (c) - { - case 'r': - n_readers = ACE_OS::atoi (get_opt.optarg); - break; - case 'w': - n_writers = ACE_OS::atoi (get_opt.optarg); - break; - case 'n': - n_iterations = ACE_OS::atoi (get_opt.optarg); - break; - case 'l': - n_loops = ACE_OS::atoi (get_opt.optarg); - break; - default: - print_usage_and_die (); - break; - } -} - -// Iterate <n_iterations> each time checking that nobody modifies the data -// while we have a read lock. - -static void * -reader (void *) -{ - ACE_Thread_Control tc (&thr_mgr); - ACE_DEBUG ((LM_DEBUG, "(%t) reader starting\n")); - - for (int iterations = 1; iterations <= n_iterations; iterations++) - { - ACE_Read_Guard<ACE_RW_Mutex> g(rw_mutex); - int n = ++current_readers; - //ACE_DEBUG ((LM_DEBUG, "(%t) I'm reader number %d\n", n)); - - if (current_writers > 0) - ACE_DEBUG ((LM_DEBUG, "(%t) writers found!!!\n")); - - int data = shared_data; - - for (int loop = 1; loop <= n_loops; loop++) - { - ACE_Thread::yield(); - if (shared_data != data) - ACE_DEBUG ((LM_DEBUG, - "(%t) somebody changed %d to %d\n", - data, shared_data)); - } - - --current_readers; - //ACE_DEBUG ((LM_DEBUG, "(%t) done with reading guarded data\n")); - - ACE_Thread::yield (); - } - return 0; -} - -// Iterate <n_iterations> each time modifying the global data -// and checking that nobody steps on it while we can write it. - -static void * -writer (void *) -{ - ACE_Thread_Control tc (&thr_mgr); - ACE_DEBUG ((LM_DEBUG, "(%t) writer starting\n")); - - for (int iterations = 1; iterations <= n_iterations; iterations++) - { - ACE_Write_Guard<ACE_RW_Mutex> g(rw_mutex); - - ++current_writers; - //ACE_DEBUG ((LM_DEBUG, "(%t) writing to guarded data\n")); - - if (current_writers > 1) - ACE_DEBUG ((LM_DEBUG, "(%t) other writers found!!!\n")); - - if (current_readers > 0) - ACE_DEBUG ((LM_DEBUG, "(%t) readers found!!!\n")); - - int self = (int) ACE_Thread::self (); - shared_data = self; - - for (int loop = 1; loop <= n_loops; loop++) - { - ACE_Thread::yield(); - if (shared_data != self) - ACE_DEBUG ((LM_DEBUG, "(%t) somebody wrote on my data %d\n", shared_data)); - } - - --current_writers; - - //ACE_DEBUG ((LM_DEBUG, "(%t) done with guarded data\n")); - ACE_Thread::yield (); - } - return 0; -} - -// Spawn off threads. - -int main (int argc, char *argv[]) -{ - ACE_LOG_MSG->open (argv[0]); - parse_args (argc, argv); - - current_readers = 0; // Possibly already done - current_writers = 0; // Possibly already done - - ACE_DEBUG ((LM_DEBUG, "(%t) main thread starting\n")); - - if (thr_mgr.spawn_n (n_readers, reader, 0, THR_NEW_LWP) == -1 || - thr_mgr.spawn_n (n_writers, writer, 0, THR_NEW_LWP) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn_n"), 1); - - thr_mgr.wait (); - - ACE_DEBUG ((LM_DEBUG, "(%t) exiting main thread\n")); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Atomic_Op<ACE_Thread_Mutex, int>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ - diff --git a/examples/Threads/test_recursive_mutex.cpp b/examples/Threads/test_recursive_mutex.cpp deleted file mode 100644 index 1cc2892b2a8..00000000000 --- a/examples/Threads/test_recursive_mutex.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// $Id$ - -// This test program verifies the functionality of the ACE_OS -// implementation of recursive mutexes on Win32 and Posix pthreads. - -#include "ace/Service_Config.h" -#include "ace/Get_Opt.h" -#include "ace/Synch.h" - -#if defined (ACE_HAS_THREADS) - -// Total number of iterations. -static size_t n_iterations = 1000; -static size_t n_threads = 4; - -// Explain usage and exit. -static void -print_usage_and_die (void) -{ - ACE_DEBUG ((LM_DEBUG, - "usage: %n [-t n_threads] [-n iteration_count]\n")); - ACE_OS::exit (1); -} - -// Parse the command-line arguments and set options. - -static void -parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opt (argc, argv, "n:t:"); - - int c; - - while ((c = get_opt ()) != -1) - switch (c) - { - case 'n': - n_iterations = ACE_OS::atoi (get_opt.optarg); - break; - case 't': - n_threads = ACE_OS::atoi (get_opt.optarg); - break; - default: - print_usage_and_die (); - break; - } -} - -static void -recursive_worker (size_t nesting_level, - ACE_Recursive_Thread_Mutex *rm) -{ - if (nesting_level < n_iterations) - { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) = trying to acquire, nesting = %d, thread id = %u\n", - rm->get_nesting_level (), rm->get_thread_id ())); - { - // This illustrates the use of the ACE_Guard<LOCK> with an - // ACE_Recursive_Thread_Mutex. - ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, *rm); - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) = acquired, nesting = %d, thread id = %u\n", - rm->get_nesting_level (), rm->get_thread_id ())); - - recursive_worker (nesting_level + 1, rm); - } - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) = released, nesting = %d, thread id = %u\n", - rm->get_nesting_level (), rm->get_thread_id ())); - } -} - -static void * -worker (void *arg) -{ - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - - ACE_Recursive_Thread_Mutex *rm = (ACE_Recursive_Thread_Mutex *) arg; - - recursive_worker (0, rm); - return 0; -} - -int -main (int argc, char *argv[]) -{ - ACE_Service_Config daemon (argv[0]); - - parse_args (argc, argv); - ACE_Recursive_Thread_Mutex rm; - - ACE_Service_Config::thr_mgr ()->spawn_n (n_threads, - ACE_THR_FUNC (worker), - (void *) &rm); - - ACE_Service_Config::thr_mgr ()->wait (); - return 0; -} -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "ACE doesn't support support process mutexes on this platform (yet)\n"), - -1); -} -#endif /* ACE_WIN32 */ diff --git a/examples/Threads/test_task.cpp b/examples/Threads/test_task.cpp deleted file mode 100644 index 7cd7976d2bb..00000000000 --- a/examples/Threads/test_task.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// This test program illustrates how the ACE barrier synchronization -// $Id$ - -// mechanisms work in conjunction with the ACE_Task and the -// ACE_Thread_Manager. It is instructive to compare this with the -// test_barrier.cpp test to see how they differ. - -#include "ace/Task.h" -#include "ace/Service_Config.h" -#include "ace/Log_Msg.h" - -#if defined (ACE_HAS_THREADS) - -#include "ace/Task.h" - -class Barrier_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Barrier_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations); - - virtual int svc (void); - // Iterate <n_iterations> time printing off a message and "waiting" - // for all other threads to complete this iteration. - -private: - ACE_Barrier barrier_; - // Reference to the tester barrier. This controls each - // iteration of the tester function running in every thread. - - int n_iterations_; - // Number of iterations to run. - - // = Not needed for this test. - virtual int open (void *) { return 0; } - virtual int close (u_long) { return 0; } - virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; } -}; - -Barrier_Task::Barrier_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations) - : ACE_Task<ACE_MT_SYNCH> (thr_mgr), - barrier_ (n_threads), - n_iterations_ (n_iterations) -{ - // Create worker threads. - if (this->activate (THR_NEW_LWP, n_threads) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); -} - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -int -Barrier_Task::svc (void) -{ - // Note that the ACE_Task::svc_run() method automatically adds us to - // the Thread_Manager when the thread begins. - - for (int iterations = 1; - iterations <= this->n_iterations_; - iterations++) - { - ACE_DEBUG ((LM_DEBUG, "(%t) in iteration %d\n", iterations)); - - // Block until all other threads have waited, then continue. - this->barrier_.wait (); - } - - // Note that the ACE_Task::svc_run() method automatically removes us - // from the Thread_Manager when the thread exits. - - return 0; -} - -// Default number of threads to spawn. -static const int DEFAULT_ITERATIONS = 5; - -int -main (int argc, char *argv[]) -{ - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_THREADS; - int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_ITERATIONS; - - Barrier_Task barrier_task (ACE_Service_Config::thr_mgr (), - n_threads, - n_iterations); - - // Wait for all the threads to reach their exit point. - ACE_Service_Config::thr_mgr ()->wait (); - - ACE_DEBUG ((LM_DEBUG, "(%t) done\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_task_four.cpp b/examples/Threads/test_task_four.cpp deleted file mode 100644 index 64209cb3430..00000000000 --- a/examples/Threads/test_task_four.cpp +++ /dev/null @@ -1,248 +0,0 @@ -// $Id$ - -// The following test was written by Hamutal Yanay & Ari Erev's -// (Ari_Erev@comverse.com). -// -// This test program test enhancements to the thread_manager and task -// classes. The purpose of these enhancements was to allow the -// thread_manager to recognize the concept of an ACE_Task and to be -// able to group ACE_Tasks in groups. -// -// There are two main ACE_Tasks in this sample: -// -// Invoker_Task - is run from main (). It's purpose is to run a number of -// ACE_Tasks of type Worker_Task. The number can be specified -// on the command line. -// After starting the tasks, the Invoker_Task groups all the tasks -// in one group and then uses the -// num_tasks_in_group () to find out if the real number of tasks -// that are now running (should be the same as the number of tasks -// started). -// It also, suspends and resumes all the threads in the group to -// test the suspend_grp () and resume_grp () methods. -// Then it waits for all the tasks to end. -// Worker_Task - ACE_Tasks that are started by the Invoker_Task. -// Each Worker_Task can start a number of threads. -// The Worker_Task threads perform some work (iteration). The number -// of the iterations can be specified on the command line. -// -// The command line syntax is: -// -// test_task [num_tasks] [num_threads] [num_iterations] - -#include "ace/Task.h" -#include "ace/Service_Config.h" - - -#if defined (ACE_HAS_THREADS) - -#include "ace/Task.h" - -class Invoker_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Invoker_Task (ACE_Thread_Manager *thr_mgr, - int n_tasks, - int n_threads, - int n_iterations); - virtual int svc (void); - // creats <n_tasks> and wait for them to finish - -private: - int n_tasks_; - // Number of tasks to start. - int n_threads_; - // Number of threads per task. - int n_iterations_; - // Number of iterations per thread. - - // = Not needed for this test. - virtual int open (void *) { return 0; } - virtual int close (u_long) { return 0; } - virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; } -}; - -class Worker_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Worker_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations); - virtual int svc (void); - // Does a small work... - virtual int open (void * = NULL); -private: - static int workers_count_; - int index_; - int n_threads_; - int n_iterations_; - - // = Not needed for this test. - virtual int close (u_long) { return 0; } - virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; } -}; - -int Worker_Task::workers_count_ = 1; - -Worker_Task::Worker_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations) - : n_threads_ (n_threads), - n_iterations_ (n_iterations), - ACE_Task<ACE_MT_SYNCH> (thr_mgr) -{ - index_ = workers_count_++; -} - -int -Worker_Task::open (void *) -{ - // Create worker threads. - int rc = this->activate (THR_NEW_LWP, n_threads_, 0, 0, -1, this); - - if (rc == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); - - return rc; -} - -int -Worker_Task::svc (void) -{ - ACE_DEBUG ((LM_DEBUG, " (%t) in worker %d\n", index_)); - - for (int iterations = 1; - iterations <= this->n_iterations_; - iterations++) - { - ACE_DEBUG ((LM_DEBUG, " (%t) in iteration %d\n", iterations)); - ACE_OS::sleep (0); - } - - ACE_DEBUG ((LM_DEBUG, " (%t) worker %d ends\n", index_)); - - return 0; -} - -Invoker_Task::Invoker_Task (ACE_Thread_Manager *thr_mgr, - int n_tasks, - int n_threads, - int n_iterations) - : n_tasks_ (n_tasks), - n_threads_ (n_threads), - n_iterations_ (n_iterations), - ACE_Task<ACE_MT_SYNCH> (thr_mgr) -{ - // Create worker threads. - if (this->activate (THR_NEW_LWP, 1, 0, 0, -1, this) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); -} - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -int -Invoker_Task::svc (void) -{ - // Note that the ACE_Task::svc_run () method automatically adds us to - // the Thread_Manager when the thread begins. - - ACE_Thread_Manager *thr_mgr = ACE_Service_Config::thr_mgr (); - Worker_Task **pTask = new Worker_Task* [n_tasks_]; - - for (int task = 0; - task < this->n_tasks_; - task++) - { - ACE_DEBUG ((LM_DEBUG, " (%t) in task %d\n", task+1)); - pTask[task] = new Worker_Task (thr_mgr, n_threads_, n_iterations_); - pTask[task]->open (); - } - - // Set all tasks to be one group - ACE_DEBUG ((LM_DEBUG, " (%t) setting tasks group id\n")); - for (task = 0; - task < this->n_tasks_; - task++) - if (thr_mgr->set_grp (pTask[task], 1) == -1) - ACE_ERROR ((LM_DEBUG, " (%t) %p\n", "set_grp")); - - int nTasks = thr_mgr->num_tasks_in_group (1); - cout << "Number of tasks in group 1: " << nTasks << endl; - - // Wait for 1 second and then suspend every thread in the group. - ACE_OS::sleep (1); - ACE_DEBUG ((LM_DEBUG, " (%t) suspending group\n")); - if (thr_mgr->suspend_grp (1) == -1) - ACE_ERROR ((LM_DEBUG, " (%t) %p\n", "suspend_grp")); - - // Wait for 5 more second and then resume every thread in the - // group. - ACE_OS::sleep (ACE_Time_Value (5)); - - // @QTSK This ACE_DEBUG statement blows us away! can't understand why - ACE_DEBUG ((LM_DEBUG, " (%t) resuming group\n")); - if (thr_mgr->resume_grp (1) == -1) - ACE_ERROR ((LM_DEBUG, " (%t) %p\n", "resume_grp")); - - - // Wait for all the tasks to reach their exit point. - thr_mgr->wait (); - - // Note that the ACE_Task::svc_run () method automatically removes us - // from the Thread_Manager when the thread exits. - - return 0; -} - -// Default number of tasks and iterations. -static const int DEFAULT_TASKS = 4; -static const int DEFAULT_ITERATIONS = 5; - -int -main (int argc, char *argv[]) -{ - int n_tasks = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_TASKS; - int n_threads = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_THREADS; - int n_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : DEFAULT_ITERATIONS; - - // Since ACE_Thread_Manager can only wait for all threads, we'll have - // special manager for the Invoker_Task. - ACE_Thread_Manager invoker_manager; - - Invoker_Task invoker (&invoker_manager, - n_tasks, - n_threads, - n_iterations); - - // Wait for 1 second and then suspend the invoker task - ACE_OS::sleep (1); - ACE_DEBUG ((LM_DEBUG, " (%t) suspending invoker task\n")); - - if (invoker_manager.suspend_task (&invoker) == -1) - ACE_ERROR ((LM_DEBUG, " (%t) %p\n", "suspend_task")); - - // Wait for 5 more second and then resume the invoker task. - ACE_OS::sleep (ACE_Time_Value (5)); - - // @QTSK This ACE_DEBUG statement blows us away! can't understand why - ACE_DEBUG ((LM_DEBUG, " (%t) resuming invoker task\n")); - if (invoker_manager.resume_task (&invoker) == -1) - ACE_ERROR ((LM_DEBUG, " (%t) %p\n", "resume_task")); - - - // Wait for all the threads to reach their exit point. - invoker_manager.wait (); - - // @QTSK This ACE_DEBUG statement blows us away! can't understand why - ACE_DEBUG ((LM_DEBUG, " (%t) done\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_task_one.cpp b/examples/Threads/test_task_one.cpp deleted file mode 100644 index d0a8a12e6c4..00000000000 --- a/examples/Threads/test_task_one.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// This test program illustrates how the ACE barrier synchronization -// $Id$ - -// mechanisms work in conjunction with the ACE_Task and the -// ACE_Thread_Manager. It is instructive to compare this with the -// test_barrier.cpp test to see how they differ. - -#include "ace/Task.h" -#include "ace/Service_Config.h" - - -#if defined (ACE_HAS_THREADS) - -#include "ace/Task.h" - -class Barrier_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Barrier_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations); - - virtual int svc (void); - // Iterate <n_iterations> time printing off a message and "waiting" - // for all other threads to complete this iteration. - -private: - ACE_Barrier barrier_; - // Reference to the tester barrier. This controls each - // iteration of the tester function running in every thread. - - int n_iterations_; - // Number of iterations to run. - - // = Not needed for this test. - virtual int open (void *) { return 0; } - virtual int close (u_long) { return 0; } - virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; } -}; - -Barrier_Task::Barrier_Task (ACE_Thread_Manager *thr_mgr, - int n_threads, - int n_iterations) - : ACE_Task<ACE_MT_SYNCH> (thr_mgr), - barrier_ (n_threads), - n_iterations_ (n_iterations) -{ - // Create worker threads. - if (this->activate (THR_NEW_LWP, n_threads) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); -} - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -int -Barrier_Task::svc (void) -{ - // Note that the ACE_Task::svc_run() method automatically adds us to - // the Thread_Manager when the thread begins. - - for (int iterations = 1; - iterations <= this->n_iterations_; - iterations++) - { - ACE_DEBUG ((LM_DEBUG, "(%t) in iteration %d\n", iterations)); - - // Block until all other threads have waited, then continue. - this->barrier_.wait (); - } - - // Note that the ACE_Task::svc_run() method automatically removes us - // from the Thread_Manager when the thread exits. - - return 0; -} - -// Default number of threads to spawn. -static const int DEFAULT_ITERATIONS = 5; - -int -main (int argc, char *argv[]) -{ - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_THREADS; - int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_ITERATIONS; - - Barrier_Task barrier_task (ACE_Service_Config::thr_mgr (), - n_threads, - n_iterations); - - // Wait for all the threads to reach their exit point. - ACE_Service_Config::thr_mgr ()->wait (); - - ACE_DEBUG ((LM_DEBUG, "(%t) done\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_task_three.cpp b/examples/Threads/test_task_three.cpp deleted file mode 100644 index c6ad69511b5..00000000000 --- a/examples/Threads/test_task_three.cpp +++ /dev/null @@ -1,230 +0,0 @@ -// $Id$ - -// Exercise more tests for the ACE Tasks. This also shows off some -// Interesting uses of the ACE Log_Msg's ability to print to ostreams. -// BTW, make sure that you set the out_stream in *every* thread that -// you want to have write to the output file, i.e.: -// -// -// if (out_stream) -// { -// ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); -// ACE_LOG_MSG->msg_ostream (out_stream); -// } - -#include <fstream.h> -#include "ace/Reactor.h" -#include "ace/Service_Config.h" -#include "ace/Task.h" - - -#if defined (ACE_HAS_THREADS) - -static ofstream *out_stream = 0; - -static const int NUM_INVOCATIONS = 100; -static const int TASK_COUNT = 130; - -class Test_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Test_Task (void); - ~Test_Task (void); - - virtual int open (void *args = 0); - virtual int close (u_long flags = 0); - virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0); - virtual int svc (void); - - virtual int handle_input (ACE_HANDLE fd); - - ACE_Reactor *r_; - int handled_; - static int current_count_; - static int done_cnt_; -}; - -int Test_Task::current_count_ = 0; -int Test_Task::done_cnt_ = 0; - -static ACE_Thread_Mutex lock_; - -Test_Task::Test_Task (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - this->handled_ = 0; - Test_Task::current_count_++; - ACE_DEBUG ((LM_DEBUG, - "Test_Task constructed, current_count_ = %d\n", - Test_Task::current_count_)); -} - -Test_Task::~Test_Task (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - ACE_DEBUG ((LM_DEBUG, "Test_Task destroyed, current_count_ = %d\n", - Test_Task::current_count_)); -} - -int -Test_Task::open (void *args) -{ - r_ = (ACE_Reactor *) args; - return ACE_Task<ACE_MT_SYNCH>::activate (THR_NEW_LWP); -} - -int -Test_Task::close (u_long) -{ - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock_, -1); - - Test_Task::current_count_--; - ACE_DEBUG ((LM_DEBUG, "Test_Task::close () current_count_ = %d.\n", - Test_Task::current_count_)); - return 0; -} - -int -Test_Task::put (ACE_Message_Block *, ACE_Time_Value *) -{ - return 0; -} - -Test_Task::svc (void) -{ - // Every thread must register the same stream to write to file. - if (out_stream) - { - ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); - ACE_LOG_MSG->msg_ostream (out_stream); - } - - for (int index = 0; index < NUM_INVOCATIONS; index++) - { - ACE_OS::thr_yield (); - - if (r_->notify (this, ACE_Event_Handler::READ_MASK)) - { - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock_, -1); - - ACE_DEBUG ((LM_DEBUG, "Test_Task: error notifying reactor!\n")); - } - } - - ACE_DEBUG ((LM_DEBUG, " (%t) returning from svc ()\n")); - return 0; -} - -int -Test_Task::handle_input (ACE_HANDLE) -{ - this->handled_++; - - if (this->handled_ == NUM_INVOCATIONS) - { - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock_, -1); - Test_Task::done_cnt_++; - ACE_DEBUG ((LM_DEBUG, - " (%t) Test_Task: handle_input! done_cnt_ = %d.\n", - Test_Task::done_cnt_)); - } - - ACE_OS::thr_yield (); - return -1; -} - -static void * -dispatch (void *arg) -{ - // every thread must register the same stream to write to file - if (out_stream) - { - ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); - ACE_LOG_MSG->msg_ostream (out_stream); - } - - ACE_DEBUG ((LM_DEBUG, " (%t) Dispatcher Thread started!\n")); - ACE_Reactor *r = (ACE_Reactor *) arg; - int result; - - r->owner (ACE_OS::thr_self ()); - - while (1) - { - result = r->handle_events (); - if (result <= 0) - ACE_DEBUG ((LM_DEBUG, "Dispatch: handle_events (): %d", result)); - } - - return 0; -} - -extern "C" void -handler (int) -{ - *out_stream << flush; - out_stream->close (); - ACE_OS::exit (42); -} - -int -main (int argc, char **argv) -{ - if (argc > 1) - { - // Send output to file. - 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); - } - - // Register a signal handler. - ACE_Sig_Action sa (ACE_SignalHandler (handler), SIGINT); - - ACE_Reactor *reactor1 = ACE_Service_Config::reactor (); - ACE_Reactor *reactor2 = new ACE_Reactor (); - - Test_Task t1[TASK_COUNT]; - Test_Task t2[TASK_COUNT]; - - ACE_Thread::spawn (ACE_THR_FUNC (dispatch), reactor2); - - reactor1->owner (ACE_OS::thr_self ()); - - for (int index = 0; index < TASK_COUNT; index++) - { - t1[index].open (reactor1); - t2[index].open (reactor2); - } - - ACE_OS::sleep (3); - - for (;;) - { - ACE_Time_Value timeout (2); - - if (reactor1->handle_events (timeout) <= 0) - { - if (errno == ETIME) - { - ACE_DEBUG ((LM_DEBUG, "no activity within 2 seconds, shutting down\n")); - break; - } - else - ACE_ERROR ((LM_ERROR, "%p error handling events\n", "main")); - } - } - - return 0; -} - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_task_two.cpp b/examples/Threads/test_task_two.cpp deleted file mode 100644 index 9f25962c795..00000000000 --- a/examples/Threads/test_task_two.cpp +++ /dev/null @@ -1,156 +0,0 @@ -// $Id$ - -// Exercise more tests for the ACE Tasks. This test can spawn off -// zillions of tasks and then wait for them using both polling and the -// ACE Thread Manager. - -#include "ace/Task.h" - -#include "ace/Service_Config.h" -#include "ace/Synch.h" - -#if defined (ACE_HAS_THREADS) - -typedef ACE_Atomic_Op<ACE_Thread_Mutex, u_long> ATOMIC_INT; - -static u_long zero = 0; -static ATOMIC_INT task_count (zero); -static ATOMIC_INT max_count (zero); -static ATOMIC_INT wait_count (zero); - -static u_long n_threads = 0; - -// Default number of tasks. -static const int default_threads = ACE_DEFAULT_THREADS; - -// Default number of times to run the test. -static const int default_iterations = 1000; - -class Task_Test : public ACE_Task<ACE_MT_SYNCH> -{ -public: - virtual int open (void *args = 0); - virtual int close (u_long flags = 0); - virtual int put (ACE_Message_Block *, ACE_Time_Value *tv = 0); - virtual int svc (void); - -private: - static ACE_Thread_Mutex lock_; -}; - -ACE_Thread_Mutex Task_Test::lock_; - -int -Task_Test::open (void *) -{ - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Task_Test::lock_, -1); - - task_count++; - ACE_DEBUG ((LM_DEBUG, "(%t) creating Task_Test, task count = %d\n", - (u_long) task_count)); - - return this->activate (THR_BOUND); -} - -int -Task_Test::close (u_long) -{ - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Task_Test::lock_, -1); - - task_count--; - ACE_DEBUG ((LM_DEBUG, "(%t) destroying Task_Test, task count = %d\n", - (u_long) task_count)); - wait_count--; -// delete this; - return 0; -} - -int -Task_Test::put (ACE_Message_Block *, - ACE_Time_Value *) -{ - return 0; -} - -int -Task_Test::svc (void) -{ - wait_count++; - max_count++; - - ACE_DEBUG ((LM_DEBUG, "(%t) svc: waiting\n")); - - for (;;) - if (max_count >= n_threads) - break; - else - ACE_Thread::yield (); - - ACE_DEBUG ((LM_DEBUG, "(%t) svc: finished waiting\n")); - return 0; -} - -int -main (int argc, char *argv[]) -{ - n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : default_threads; - int n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : default_iterations; - - Task_Test **task_array = new Task_Test *[n_threads]; - - for (int i = 1; i <= n_iterations; i++) - { - ACE_DEBUG ((LM_DEBUG, "(%t) iteration = %d, max_count %d\n", - i, (u_long) max_count)); - max_count = 0; - - ACE_DEBUG ((LM_DEBUG, "(%t) starting %d task%s\n", - n_threads, n_threads == 1 ? "" : "s")); - - // Launch the new tasks. - for (int j = 0; j < n_threads; j++) - { - task_array[j] = new Task_Test; - // Activate the task, i.e., make it an active object. - task_array[j]->open (); - } - - // Wait for initialization to kick in. - while (max_count == 0) - ACE_Thread::yield (); - - ACE_DEBUG ((LM_DEBUG, "(%t) waiting for threads to finish\n")); - - // Wait for the threads to finish this iteration. - while (max_count != n_threads && wait_count != 0) - ACE_Thread::yield (); - - ACE_DEBUG ((LM_DEBUG, "(%t) iteration %d finished, max_count %d, wait_count %d, waiting for tasks to exit\n", - i, (u_long) max_count, (u_long) wait_count)); - - // Wait for all the tasks to exit. - ACE_Service_Config::thr_mgr ()->wait (); - - // Delete the existing tasks. - for (int k = 0; k < n_threads; k++) - delete task_array[k]; - } - - delete [] task_array; - - ACE_DEBUG ((LM_DEBUG, "(%t) shutting down the test\n")); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_Atomic_Op<ACE_Thread_Mutex, u_long>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_thread_manager.cpp b/examples/Threads/test_thread_manager.cpp deleted file mode 100644 index 73029d70d88..00000000000 --- a/examples/Threads/test_thread_manager.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// $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. - -#include "ace/Service_Config.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_HAS_THREADS) - -extern "C" void -handler (int signum) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) received signal %d\n", signum)); -} - -static void * -worker (int iterations) -{ - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - - for (int i = 0; i < iterations; i++) - { - if ((i % 1000) == 0) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) checking cancellation before iteration %d!\n", - i)); - - if (ACE_Service_Config::thr_mgr ()->testcancel (ACE_Thread::self ()) != 0) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) has been cancelled before iteration %d!\n", - i)); - break; - } - } - } - - // Destructor removes thread from Thread_Manager. - return 0; -} - -static const int DEFAULT_THREADS = ACE_DEFAULT_THREADS; -static const int DEFAULT_ITERATIONS = 100000; - -int -main (int argc, char *argv[]) -{ - ACE_Service_Config daemon; - - daemon.open (argv[0]); - - // Register a signal handler. - ACE_Sig_Action sa ((ACE_SignalHandler) 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; - - ACE_Thread_Manager *thr_mgr = ACE_Service_Config::thr_mgr (); - - int grp_id = thr_mgr->spawn_n (n_threads, ACE_THR_FUNC (worker), - (void *) n_iterations, - THR_NEW_LWP | THR_DETACHED); - - // Wait for 1 second and then suspend every thread in the group. - ACE_OS::sleep (1); - ACE_DEBUG ((LM_DEBUG, "(%t) suspending group\n")); - if (thr_mgr->suspend_grp (grp_id) == -1) - ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "suspend_grp")); - - // Wait for 1 more second and then resume every thread in the - // group. - ACE_OS::sleep (ACE_Time_Value (1)); - ACE_DEBUG ((LM_DEBUG, "(%t) resuming group\n")); - if (thr_mgr->resume_grp (grp_id) == -1) - ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "resume_grp")); - - // Wait for 1 more second and then send a SIGINT to every thread in - // the group. - ACE_OS::sleep (ACE_Time_Value (1)); - ACE_DEBUG ((LM_DEBUG, "(%t) signaling group\n")); - if (thr_mgr->kill_grp (grp_id, SIGINT) == -1) - ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "kill_grp")); - - // Wait for 1 more second and then cancel all the threads. - ACE_OS::sleep (ACE_Time_Value (1)); - ACE_DEBUG ((LM_DEBUG, "(%t) cancelling group\n")); - if (thr_mgr->cancel_grp (grp_id) == -1) - ACE_ERROR ((LM_DEBUG, "(%t) %p\n", "cancel_grp")); - - // Perform a barrier wait until all the threads have shut down. - thr_mgr->wait (); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR_RETURN ((LM_ERROR, "threads not supported on this platform\n"), -1); -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_thread_pool.cpp b/examples/Threads/test_thread_pool.cpp deleted file mode 100644 index 68741156b83..00000000000 --- a/examples/Threads/test_thread_pool.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// This test program illustrates how the ACE task synchronization -// $Id$ - -// mechanisms work in conjunction with the ACE_Task and the -// ACE_Thread_Manager. If the manual flag is not set input comes from -// stdin until the user enters a return only. This stops all workers -// via a message block of length 0. This is an alternative shutdown of -// workers compared to queue deactivate. -// -// This code is original based on a test program written by Karlheinz -// Dorn. It was modified to utilize more "ACE" features by Doug Schmidt. - -#include "ace/Task.h" -#include "ace/Service_Config.h" - -#include "ace/Task.h" - -#if defined (ACE_HAS_THREADS) - -// Number of iterations to run the test. -static size_t n_iterations = 100; - -class Thread_Pool : public ACE_Task<ACE_MT_SYNCH> -{ -public: - Thread_Pool (ACE_Thread_Manager *thr_mgr, int n_threads); - - virtual int svc (void); - // Iterate <n_iterations> time printing off a message and "waiting" - // for all other threads to complete this iteration. - - virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv=0); - // This allows the producer to pass messages to the <Thread_Pool>. - -private: - virtual int close (u_long); - - // = Not needed for this test. - virtual int open (void *) { return 0; } -}; - -int -Thread_Pool::close (u_long) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) close of worker\n")); - return 0; -} - -Thread_Pool::Thread_Pool (ACE_Thread_Manager *thr_mgr, - int n_threads) - : ACE_Task<ACE_MT_SYNCH> (thr_mgr) -{ - // Create worker threads. - if (this->activate (THR_NEW_LWP, n_threads) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "activate failed")); -} - -// Simply enqueue the Message_Block into the end of the queue. - -int -Thread_Pool::put (ACE_Message_Block *mb, ACE_Time_Value *tv) -{ - return this->putq (mb, tv); -} - -// Iterate <n_iterations> time printing off a message and "waiting" -// for all other threads to complete this iteration. - -int -Thread_Pool::svc (void) -{ - // Note that the ACE_Task::svc_run () method automatically adds us to - // the Thread_Manager when the thread begins. - - int result = 0; - int count = 1; - - // Keep looping, reading a message out of the queue, until we get a - // message with a length == 0, which signals us to quit. - - for (;; count++) - { - ACE_Message_Block *mb; - - ACE_DEBUG ((LM_DEBUG, "(%t) in iteration %d before getq ()\n", count)); - - if (this->getq (mb) == -1) - { - ACE_ERROR ((LM_ERROR, - "(%t) in iteration %d, got result -1, exiting\n", count)); - break; - } - - int length = mb->length (); - - if (length > 0) - ACE_DEBUG ((LM_DEBUG, - "(%t) in iteration %d, length = %d, text = \"%*s\"\n", - count, length, length - 1, mb->rd_ptr ())); - - // We're responsible for deallocating this. - delete mb; - - if (length == 0) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) in iteration %d, got NULL message, exiting\n", - count)); - break; - } - } - - // Note that the ACE_Task::svc_run () method automatically removes - // us from the Thread_Manager when the thread exits. - return 0; -} - -static void -produce (Thread_Pool &thread_pool) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) producer start, dumping the Thread_Pool\n")); - thread_pool.dump (); - - for (int n;;) - { - // Allocate a new message. - ACE_Message_Block *mb = new ACE_Message_Block (BUFSIZ); - -#if defined (manual) - ACE_DEBUG ((LM_DEBUG, - "(%t) press chars and enter to put a new message into task queue...")); - n = ACE_OS::read (ACE_STDIN, mb->rd_ptr (), mb->size ()); -#else // Automatically generate messages. - static int count = 0; - - ACE_OS::sprintf (mb->rd_ptr (), "%d\n", count); - - n = ACE_OS::strlen (mb->rd_ptr ()); - - if (count == n_iterations) - n = 1; // Indicate that we need to shut down. - else - count++; - - if (count == 0 || (count % 20 == 0)) - ACE_OS::sleep (1); -#endif /* manual */ - if (n > 1) - { - // Send a normal message to the waiting threads and continue - // producing. - mb->wr_ptr (n); - - // Pass the message to the Thread_Pool. - if (thread_pool.put (mb) == -1) - ACE_ERROR ((LM_ERROR, " (%t) %p\n", "put")); - } - else - { - // Send a shutdown message to the waiting threads and exit. - ACE_DEBUG ((LM_DEBUG, "\n(%t) start loop, dump of task:\n")); - thread_pool.dump (); - - for (int i = thread_pool.thr_count (); i > 0; i--) - { - ACE_DEBUG ((LM_DEBUG, - "(%t) EOF, enqueueing NULL block for thread = %d\n", - i)); - - // Enqueue a NULL message to flag each consumer to - // shutdown. - if (thread_pool.put (new ACE_Message_Block) == -1) - ACE_ERROR ((LM_ERROR, " (%t) %p\n", "put")); - } - - ACE_DEBUG ((LM_DEBUG, "\n(%t) end loop, dump of task:\n")); - thread_pool.dump (); - break; - } - } -} - -int -main (int argc, char *argv[]) -{ - int n_threads = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_THREADS; - n_iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : n_iterations; - - ACE_DEBUG ((LM_DEBUG, "(%t) argc = %d, threads = %d\n", - argc, n_threads)); - - // Create the worker tasks. - Thread_Pool thread_pool (ACE_Service_Config::thr_mgr (), - n_threads); - - // Create work for the worker tasks to process in their own threads. - produce (thread_pool); - - // Wait for all the threads to reach their exit point. - - ACE_DEBUG ((LM_DEBUG, "(%t) waiting with thread manager...\n")); - ACE_Service_Config::thr_mgr ()->wait (); - - ACE_DEBUG ((LM_DEBUG, "(%t) destroying worker tasks and exiting...\n")); - return 0; -} -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_thread_specific.cpp b/examples/Threads/test_thread_specific.cpp deleted file mode 100644 index f7a4f6dccf3..00000000000 --- a/examples/Threads/test_thread_specific.cpp +++ /dev/null @@ -1,219 +0,0 @@ -#include "ace/Service_Config.h" -// $Id$ - -#include "ace/Synch.h" - -#if defined (ACE_HAS_THREADS) - -// Define a class that will be stored in thread-specific data. Note -// that as far as this class is concerned it's just a regular C++ -// class. The ACE_TSS wrapper transparently ensures that -// objects of this class will be placed in thread-specific storage. -// All calls on ACE_TSS::operator->() are delegated to the -// appropriate method in the Errno class. - -class Errno -{ -public: - int error (void) { return this->errno_; } - void error (int i) { this->errno_ = i; } - - int line (void) { return this->lineno_; } - void line (int l) { this->lineno_ = l; } - - // Errno::flags_ is a static variable, so we've got to protect it - // with a mutex since it isn't kept in thread-specific storage. - int flags (void) - { - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1); - - return Errno::flags_; - } - - void flags (int f) - { - ACE_GUARD (ACE_Thread_Mutex, ace_mon, Errno::lock_); - - Errno::flags_ = f; - } - -private: - // = errno_ and lineno_ will be thread-specific data so they don't - // need a lock. - int errno_; - int lineno_; - - static int flags_; -#if defined (ACE_HAS_THREADS) - // flags_ needs a lock. - static ACE_Thread_Mutex lock_; -#endif /* ACE_HAS_THREADS */ -}; - -// Static variables. -ACE_MT (ACE_Thread_Mutex Errno::lock_); -int Errno::flags_; - -// This is our thread-specific error handler... -static ACE_TSS<Errno> TSS_Error; - -#if defined (ACE_HAS_THREADS) -// Serializes output via cout. -static ACE_Thread_Mutex lock; - -typedef ACE_TSS_Guard<ACE_Thread_Mutex> GUARD; -#else -// Serializes output via cout. -static ACE_Null_Mutex lock; - -typedef ACE_Guard<ACE_Null_Mutex> GUARD; -#endif /* ACE_HAS_THREADS */ - -static void -cleanup (void *ptr) -{ - ACE_DEBUG ((LM_DEBUG, "(%t) in cleanup, ptr = %x\n", ptr)); - - delete ptr; -} - -// This worker function is the entry point for each thread. - -static void * -worker (void *c) -{ - ACE_Thread_Control tc (ACE_Service_Config::thr_mgr ()); - int count = int (c); - - ACE_thread_key_t key = 0; - int *ip = 0; - - // Make one key that will be available when the thread exits so that - // we'll have something to cleanup! - - if (ACE_OS::thr_keycreate (&key, cleanup) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_keycreate")); - - ip = new int; - - if (ACE_OS::thr_setspecific (key, (void *) ip) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - for (int i = 0; i < count; i++) - { - if (ACE_OS::thr_keycreate (&key, cleanup) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_keycreate")); - - ip = new int; - - ACE_DEBUG ((LM_DEBUG, "(%t) in worker 1, key = %d, ip = %x\n", key, ip)); - - if (ACE_OS::thr_setspecific (key, (void *) ip) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - if (ACE_OS::thr_getspecific (key, (void **) &ip) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - if (ACE_OS::thr_setspecific (key, (void *) 0) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - delete ip; - - if (ACE_OS::thr_keyfree (key) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_keyfree")); - - // Cause an error. - ACE_OS::read (ACE_INVALID_HANDLE, 0, 0); - - // The following two lines set the thread-specific state. - TSS_Error->error (errno); - TSS_Error->line (__LINE__); - - // This sets the static state (note how C++ makes it easy to do - // both). - TSS_Error->flags (count); - - { - // Use the guard to serialize access to cout... - ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, lock, 0); - - cout << "(" << ACE_Thread::self () - << ") errno = " << TSS_Error->error () - << ", lineno = " << TSS_Error->line () - << ", flags = " << TSS_Error->flags () - << endl; - } - key = 0; - - if (ACE_OS::thr_keycreate (&key, cleanup) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_keycreate")); - - ip = new int; - - ACE_DEBUG ((LM_DEBUG, "(%t) in worker 2, key = %d, ip = %x\n", key, ip)); - - if (ACE_OS::thr_setspecific (key, (void *) ip) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - if (ACE_OS::thr_getspecific (key, (void **) &ip) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - if (ACE_OS::thr_setspecific (key, (void *) 0) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_setspecific")); - - delete ip; - - if (ACE_OS::thr_keyfree (key) == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_OS::thr_keyfree")); - } - - ACE_DEBUG ((LM_DEBUG, "(%t) exiting\n")); - return 0; -} - -extern "C" void -handler (int signum) -{ - ACE_DEBUG ((LM_DEBUG, "signal = %S\n", signum)); - ACE_Service_Config::thr_mgr ()->exit (0); -} - -int -main (int argc, char *argv[]) -{ - // 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; - - // 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), - (void *) count, - THR_BOUND | THR_DETACHED) == -1) - ACE_OS::perror ("ACE_Thread_Manager::spawn_n"); - - ACE_Service_Config::thr_mgr ()->wait (); -#else - worker ((void *) count); -#endif /* ACE_HAS_THREADS */ - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_TSS<Errno>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "ACE doesn't support support threads on this platform (yet)\n"), - -1); -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_token.cpp b/examples/Threads/test_token.cpp deleted file mode 100644 index 5a51496d011..00000000000 --- a/examples/Threads/test_token.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// Test out the ACE Token class. -// $Id$ - -#include "ace/Token.h" -#include "ace/Task.h" - -#if defined (ACE_HAS_THREADS) - -class My_Task : public ACE_Task<ACE_MT_SYNCH> -{ -public: - My_Task (int n); - virtual int open (void *) { return 0; } - virtual int close (u_long) { return 0; } - virtual int put (ACE_Message_Block *, ACE_Time_Value *) { return 0; } - virtual int svc (void); - - static void sleep_hook (void *); - -private: - ACE_Token token_; -}; - -My_Task::My_Task (int n) -{ - // Make this Task into an Active Object. - this->activate (THR_BOUND | THR_DETACHED, n); - - // Wait for all the threads to exit. - this->thr_mgr ()->wait (); -} - -void -My_Task::sleep_hook (void *) -{ - cerr << '(' << ACE_Thread::self () << ')' - << " blocking, My_Task::sleep_hook () called" << endl; -} - -// Test out the behavior of the ACE_Token class. - -int -My_Task::svc (void) -{ - for (int i = 0; i < 10000; i++) - { - // Wait for up to 1 millisecond past the current time to get the token. - ACE_Time_Value timeout (ACE_OS::time (0), 1000); - - if (this->token_.acquire (&My_Task::sleep_hook, 0, &timeout) == 1) - { - this->token_.acquire (); - this->token_.renew (); - this->token_.release (); - this->token_.release (); - } - else - ACE_Thread::yield (); - } - return 0; -} - -int -main (int argc, char *argv[]) -{ - My_Task tasks (argc > 1 ? atoi (argv[1]) : 4); - - return 0; -} -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, "your platform doesn't support threads\n"), -1); -} -#endif /* */ diff --git a/examples/Threads/test_tss.cpp b/examples/Threads/test_tss.cpp deleted file mode 100644 index c81ca41c429..00000000000 --- a/examples/Threads/test_tss.cpp +++ /dev/null @@ -1,235 +0,0 @@ -// Torture test ACE thread-specific storage... -// $Id$ - - -#include "ace/Task.h" -#include "ace/Token.h" - -#if defined (ACE_HAS_THREADS) - -class TSS_Obj -{ -public: - - TSS_Obj (void); - ~TSS_Obj (void); - -private: - static int count_; - static ACE_Thread_Mutex lock_; -}; - -int TSS_Obj::count_ = 0; -ACE_Thread_Mutex TSS_Obj::lock_; - -TSS_Obj::TSS_Obj (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - count_++; - cout << "TO+ : " << count_ << endl; -} - -TSS_Obj::~TSS_Obj (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - count_--; - cout << "TO- : " << count_ << endl; -} - -class Test_Task -{ -public: - - Test_Task (void); - ~Test_Task (void); - - int open (void *arg); - - static void* svc (void *arg); - - static int wait_count_; - static int max_count_; - -private: - static int count_; -}; - -int Test_Task::count_ = 0; -int Test_Task::wait_count_ = 0; -int Test_Task::max_count_ = 0; -int num_threads_ = 0; - -ACE_Token token; - -Test_Task::Test_Task (void) -{ - ACE_GUARD (ACE_Token, ace_mon, token); - - count_++; - cout << "Test_Task+ : " - << count_ << " (" - << ACE_OS::thr_self () - << ")" << endl; -} - -Test_Task::~Test_Task (void) -{ - ACE_GUARD (ACE_Token, ace_mon, token); - - count_--; - cout << "Test_Task- : " - << count_ << " (" - << ACE_OS::thr_self () - << ")" << endl; - - wait_count_--; -} - -int Test_Task::open (void *arg) -{ - - ACE_Thread::spawn (Test_Task::svc, arg); - - return 0; -} - - -void * -Test_Task::svc (void *arg) -{ - ACE_TSS<TSS_Obj> tss (new TSS_Obj); - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - wait_count_++; - max_count_++; - cout << "svc: waiting (" << ACE_OS::thr_self () << ")" << endl; - } - - while (1) - { - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - if (max_count_ >= num_threads_) - break; - else - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - } - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - cout << "svc: waiting (" << ACE_OS::thr_self () << ") finished" << endl; - } - } - - delete (Test_Task *) arg; - - return 0; -} - -int -main (int argc, char **argv) -{ - if (argc != 2) - { - cout << "Missing parameters!" << endl; - return 1; - } - - int num_Tasks = atoi (argv[1]); - - num_threads_ = num_Tasks; - - Test_Task **task_arr = (Test_Task**) new char[sizeof (Test_Task*) * num_Tasks]; - - while (1) - { - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - cout << "ReseTest_Tasking Test_Task::max_count_ from: " - << Test_Task::max_count_ << endl; - - Test_Task::max_count_ = 0; - } - - for (int i = 0; i < num_Tasks; i++) - { - task_arr[i] = new Test_Task; - task_arr[i]->open (task_arr[i]); - } - - cout << "Waiting for first thread started..." << endl; - - for (;;) - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - if (Test_Task::max_count_ != 0 ) - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - break; - } - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - cout << "First thread started!" << endl - << "Waiting for all threads finished..." << endl; - } - - for (;;) - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - if (!(Test_Task::max_count_ == num_threads_ - && Test_Task::wait_count_ == 0)) - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - continue; - } - - cout << "Test_Task::max_count_ = " - << Test_Task::max_count_ - << " Test_Task::wait_count_ = " - << Test_Task::wait_count_ - << endl; - break; - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - cout << "All threads finished..." << endl; - } - - ACE_OS::sleep (2); - } - - return 0; -} - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_tss1.cpp b/examples/Threads/test_tss1.cpp deleted file mode 100644 index 7efdc9dc3ef..00000000000 --- a/examples/Threads/test_tss1.cpp +++ /dev/null @@ -1,164 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// TSS_Test.cpp -// -// = DESCRIPTION -// This program tests thread specific storage of data. The ACE_TSS -// wrapper transparently ensures that the objects of this class -// will be placed in thread-specific storage. All calls on -// ACE_TSS::operator->() are delegated to the appropriate method -// in the Errno class. -// -// = AUTHOR -// Detlef Becker -// -// ============================================================================ - -#include "ace/Service_Config.h" -#include "ace/Synch.h" -#include "ace/Task.h" - -#if defined (ACE_HAS_THREADS) - -static int iterations = 100; - -class Errno -{ -public: - int error (void) { return this->errno_; } - void error (int i) { this->errno_ = i; } - - int line (void) { return this->lineno_; } - void line (int l) { this->lineno_ = l; } - - // Errno::flags_ is a static variable, so we've got to protect it - // with a mutex since it isn't kept in thread-specific storage. - int flags (void) { - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_Mon, Errno::lock_, -1)); - - return Errno::flags_; - } - int flags (int f) - { - ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Errno::lock_, -1)); - - Errno::flags_ = f; - return 0; - } - -private: - // = errno_ and lineno_ will be thread-specific data so they don't - // need a lock. - int errno_; - int lineno_; - - static int flags_; -#if defined (ACE_HAS_THREADS) - // flags_ needs a lock. - static ACE_Thread_Mutex lock_; -#endif /* ACE_HAS_THREADS */ -}; - -// Static variables. -ACE_MT (ACE_Thread_Mutex Errno::lock_); -int Errno::flags_; - -// This is our thread-specific error handler... -static ACE_TSS<Errno> TSS_Error; - -#if defined (ACE_HAS_THREADS) -// Serializes output via cout. -static ACE_Thread_Mutex lock; - -typedef ACE_TSS_Guard<ACE_Thread_Mutex> GUARD; -#else -// Serializes output via cout. -static ACE_Null_Mutex lock; - -typedef ACE_Guard<ACE_Null_Mutex> GUARD; -#endif /* ACE_HAS_THREADS */ - -// Keeps track of whether Tester::close () has started. -static int close_started = 0; - -template <ACE_SYNCH_1> -class Tester: public ACE_Task<ACE_SYNCH_2> -{ -public: - Tester (void) {} - ~Tester (void) {} - - virtual int open (void *theArgs = 0); - virtual int close (u_long theArg = 0); - virtual int put (ACE_Message_Block *theMsgBlock, - ACE_Time_Value *theTimeVal = 0); - virtual int svc (void); -}; - -template <ACE_SYNCH_1> int -Tester<ACE_SYNCH_2>::open (void *) -{ - return this->activate (); -} - -template <ACE_SYNCH_1> -int Tester<ACE_SYNCH_2>::close (u_long) -{ - ACE_DEBUG ((LM_DEBUG, "close running\n!")); - close_started = 1; - ACE_OS::sleep (2); - ACE_DEBUG ((LM_DEBUG, "close: trying to log error code 7!\n")); - TSS_Error->error (7); - ACE_DEBUG ((LM_DEBUG, "close: logging succeeded!\n")); - return 0; -} - -template <ACE_SYNCH_1> int -Tester<ACE_SYNCH_2>::put (ACE_Message_Block *, ACE_Time_Value *) -{ - return 0; -} - -template <ACE_SYNCH_1> int -Tester<ACE_SYNCH_2>::svc (void) -{ - return 0; -} - -int -main (int, char *[]) -{ - Tester<ACE_MT_SYNCH> tester; - - tester.open (); - - while (!close_started) - continue; - - ACE_DEBUG ((LM_DEBUG, "main: trying to log error code 7!\n")); - - TSS_Error->error (3); - - ACE_DEBUG ((LM_DEBUG, "main: logging succeeded!\n")); - return 0; -} - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_TSS<Errno>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ - -#else -int -main (void) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "ACE doesn't support support threads on this platform (yet)\n"), - -1); -} -#endif /* ACE_HAS_THREADS */ diff --git a/examples/Threads/test_tss2.cpp b/examples/Threads/test_tss2.cpp deleted file mode 100644 index 24a8d958e91..00000000000 --- a/examples/Threads/test_tss2.cpp +++ /dev/null @@ -1,252 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// TSS_Test.cpp -// -// = DESCRIPTION -// This program tests thread specific storage of data. The ACE_TSS -// wrapper transparently ensures that the objects of this class -// will be placed in thread-specific storage. All calls on -// ACE_TSS::operator->() are delegated to the appropriate method -// in the Errno class. -// -// = AUTHOR -// Prashant Jain and Doug Schmidt -// -// ============================================================================ - -#include "ace/Task.h" -#include "ace/Token.h" - -#if defined (ACE_HAS_THREADS) - -class TSS_Obj -{ -public: - - TSS_Obj (void); - ~TSS_Obj (void); - -private: - static int count_; - static ACE_Thread_Mutex lock_; -}; - -int TSS_Obj::count_ = 0; -ACE_Thread_Mutex TSS_Obj::lock_; - -TSS_Obj::TSS_Obj (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - count_++; - cout << "TO+ : " << count_ << endl; -} - -TSS_Obj::~TSS_Obj (void) -{ - ACE_GUARD (ACE_Thread_Mutex, ace_mon, lock_); - - count_--; - cout << "TO- : " << count_ << endl; -} - -class Test_Task -{ -public: - - Test_Task (void); - ~Test_Task (void); - - int open (void *arg); - - static void *svc (void *arg); - static int wait_count_; - static int max_count_; - -private: - static int count_; -}; - -int Test_Task::count_ = 0; -int Test_Task::wait_count_ = 0; -int Test_Task::max_count_ = 0; -int num_threads_ = 0; - -ACE_Token token; - -Test_Task::Test_Task (void) -{ - ACE_GUARD (ACE_Token, ace_mon, token); - - count_++; - cout << "Test_Task+ : " - << count_ << " (" - << ACE_OS::thr_self () - << ")" << endl; -} - -Test_Task::~Test_Task (void) -{ - ACE_GUARD (ACE_Token, ace_mon, token); - - count_--; - cout << "Test_Task- : " - << count_ << " (" - << ACE_OS::thr_self () - << ")" << endl; - - wait_count_--; -} - -void * -Test_Task::svc (void *arg) -{ - ACE_TSS<TSS_Obj> tss (new TSS_Obj); - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - wait_count_++; - max_count_++; - cout << "svc: waiting (" << ACE_OS::thr_self () << ")" << endl; - } - - while (1) - { - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - if (max_count_ >= num_threads_) - break; - else - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - } - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, 0); - - cout << "svc: waiting (" << ACE_OS::thr_self () << ") finished" << endl; - } - } - - delete (Test_Task *) arg; - - return 0; -} - -int -Test_Task::open (void *arg) -{ - if (ACE_Thread::spawn (Test_Task::svc, arg) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Thread::spawn"), 0); - - return 0; -} - -int -main (int argc, char **argv) -{ - if (argc != 2) - { - cout << "Missing parameters!" << endl; - return 1; - } - - int num_Tasks = atoi (argv[1]); - - num_threads_ = num_Tasks; - - Test_Task **task_arr = (Test_Task**) new char[sizeof (Test_Task*) * num_Tasks]; - - while (1) - { - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - cout << "ReseTest_Tasking Test_Task::max_count_ from: " - << Test_Task::max_count_ << endl; - - Test_Task::max_count_ = 0; - } - - for (int i = 0; i < num_Tasks; i++) - { - task_arr[i] = new Test_Task; - task_arr[i]->open (task_arr[i]); - } - - cout << "Waiting for first thread started..." << endl; - - for (;;) - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - if (Test_Task::max_count_ != 0 ) - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - break; - } - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - cout << "First thread started!" << endl - << "Waiting for all threads finished..." << endl; - } - - for (;;) - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - - if (!(Test_Task::max_count_ == num_threads_ - && Test_Task::wait_count_ == 0)) - { - ace_mon.release (); - ACE_Thread::yield (); - ace_mon.acquire (); - continue; - } - - cout << "Test_Task::max_count_ = " - << Test_Task::max_count_ - << " Test_Task::wait_count_ = " - << Test_Task::wait_count_ - << endl; - break; - } - - { - ACE_GUARD_RETURN (ACE_Token, ace_mon, token, -1); - cout << "All threads finished..." << endl; - } - - ACE_OS::sleep (2); - } - - return 0; -} - -#else -int -main (int, char *[]) -{ - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); - return 0; -} -#endif /* ACE_HAS_THREADS */ diff --git a/include/makeinclude/platform_chorus.GNU b/include/makeinclude/platform_chorus.GNU index 973c7f90c67..92ad506784f 100644 --- a/include/makeinclude/platform_chorus.GNU +++ b/include/makeinclude/platform_chorus.GNU @@ -1,12 +1,11 @@ # Chorus 3.1b with GNU g++ 2.7.2 +# *not* using Orbix -include $(CLASSIXDIR)/dtool/htgt-cf.rf INC_DIR = $(CLASSIXDIR)/include BIN_DIR = LIB_DIR = $(CLASSIXDIR)/lib -#CC = gcc -#CXX = g++ -CXX = $(CC) +CC = gcc +CXX = g++ CFLAGS += $(DCFLAGS) -w -O2 CCFLAGS += $(CFLAGS) -fno-implicit-templates \ -fno-strict-prototypes \ @@ -18,24 +17,20 @@ INCLDIRS += -I$(INC_DIR)/posix \ -I$(INC_DIR)/stdc \ -I$(INC_DIR)/chorus/ \ -I$(INC_DIR)/chorus/iom \ - -I$(INC_DIR)/CC -DLD = -LD = $(CXX) + -I$(INC_DIR)/CC +DLD = +LD = $(CXX) LDFLAGS += -r -Ur -nostdlib \ -L$(LIB_DIR)/CC \ -L$(LIB_DIR)/classix -#LIBS += -lC -lcx.u +LIBS += -lC -lcx.u PIC = -fPIC -#AR = ar -AR = $(XDIR)/bin/ar -#ARFLAGS = rv -ARFLAGS = srv -#RANLIB = /bin/true -RANLIB = $(XDIR)/bin/ranlib +AR = ar +ARFLAGS = rv +RANLIB = /bin/true PRELIB = (echo "main() { }" > gcctemp.c && \ $(COMPILE.cc) -o gcctemp.o gcctemp.c && \ $(LD) $^ $(LDFLAGS) $(LIBS); \ status=$$?; rm -f gcctemp.* a.out; exit $$status) #### don't build shared objects: BUILD = $(VOBJS) $(VLIB) $(VBIN) - diff --git a/include/makeinclude/platform_sunos5_sunc++_orbix.GNU b/include/makeinclude/platform_sunos5_sunc++_orbix.GNU index 6647d397485..915029d7039 100644 --- a/include/makeinclude/platform_sunos5_sunc++_orbix.GNU +++ b/include/makeinclude/platform_sunos5_sunc++_orbix.GNU @@ -10,7 +10,7 @@ LD = $(CXX) INCLDIRS = -I$(ORBIX_ROOT)/include PIC = -PIC LDFLAGS += $(PIC) -L$(ORBIX_ROOT)/lib -R $(WRAPPER_ROOT)/ace -R $(ORBIX_ROOT)/lib -LIBS += -lorbixmt -lsocket -ldl -lnsl -lthread -lgen +LIBS += -orbixmt -lsocket -ldl -lnsl -lthread -lgen AR = CC ARFLAGS = -xar -o RANLIB = echo diff --git a/java/ImageProcessing/framework/BaseButton.java b/java/ImageProcessing/framework/BaseButton.java index 8071bc8671a..e7956dde646 100644 --- a/java/ImageProcessing/framework/BaseButton.java +++ b/java/ImageProcessing/framework/BaseButton.java @@ -154,15 +154,13 @@ class HelpButton extends BaseButton public HelpButton (String title, String desc, ImageApp parent) { super (title, desc, parent); - this.parent_ = parent; } public boolean action (Event e, Object arg) { - DialogManager.popDialog (DialogType.HELP, null, this.parent_); + System.out.println ("Help selected"); return true; } - ImageApp parent_ = null; } class ChoicePanel extends Panel @@ -208,7 +206,7 @@ class ChoicePanel extends Panel String displayString = null; String filterName = this.choice_.getSelectedItem (); - if (filterName.compareTo ("Filters:") == 0) + if (filterName.compareTo ("None") == 0) displayString = "No filter selected"; else { diff --git a/java/ImageProcessing/framework/DialogManager.java b/java/ImageProcessing/framework/DialogManager.java index eb8fac39940..e712a994b4a 100644 --- a/java/ImageProcessing/framework/DialogManager.java +++ b/java/ImageProcessing/framework/DialogManager.java @@ -2,19 +2,9 @@ package imaging.framework; import java.awt.*; import java.awt.image.*; -import java.applet.*; -import java.util.*; -import java.io.*; -import java.net.*; class DialogManager { - public static void popDialog (int type, String message, Applet parent) - { - codeBase_ = parent.getCodeBase ().toString (); - popDialog (type, message); - } - public static void popDialog (int type, String message) { Frame frame = null; @@ -24,9 +14,6 @@ class DialogManager case DialogType.ABOUT: frame = new AboutFrame (); break; - case DialogType.HELP: - frame = new HelpFrame (codeBase_); - break; case DialogType.MALFORMED_URL: case DialogType.NOT_SUPPORTED: case DialogType.URL_NOT_FOUND: @@ -41,7 +28,6 @@ class DialogManager (d.height - frame.size ().height)/2); frame.show (); } - private static String codeBase_ = ""; } class MessageFrame extends Frame @@ -98,7 +84,9 @@ class AboutFrame extends Frame public AboutFrame () { super ("About"); - this.resize (300,300); + this.setText (); + + this.resize (500,700); this.setLayout (new BorderLayout ()); Panel okButtonPanel = new Panel (); @@ -109,42 +97,17 @@ class AboutFrame extends Frame public void paint (Graphics g) { - int width = this.size ().width; - int height = this.size ().height; - - g.clearRect (0, 0, width, height); - this.setBackground (Color.cyan); - - // First draw the title - g.setFont (new Font ("TimesRoman", Font.BOLD | Font.ITALIC, 48)); - FontMetrics fontMetrics = g.getFontMetrics (); - int x = (width - fontMetrics.stringWidth (title_))/2; + g.clearRect (0, 0, this.size ().width, this.size ().height); + g.setFont (new Font ("TimesRoman", Font.PLAIN, 18)); + this.setBackground (Color.white); + int x = 20; int y = 100; - Color color = g.getColor (); - g.setColor (Color.orange); - g.drawString(title_, x+2, y+2); - g.setColor (color); - g.drawString(title_, x, y); - - // Then draw author's name - g.setFont (new Font ("TimesRoman", Font.ITALIC, 24)); - fontMetrics = g.getFontMetrics (); - x = (width - fontMetrics.stringWidth (by_))/2; - y += 50; - g.drawString(by_, x, y); - - x = (width - fontMetrics.stringWidth (author_))/2; - y += 50; - g.drawString(author_, x, y); - - // Finally draw other information -- version number etc. - g.setFont (new Font ("TimesRoman", Font.ITALIC, 18)); - fontMetrics = g.getFontMetrics (); - x = (width - fontMetrics.stringWidth (info_))/2; - y += 50; - g.drawString(info_, x, y); - + for (int i = 0; i < AboutFrame.MAXROWS; i++) + { + g.drawString(this.text_[i], x, y); + y += g.getFont ().getSize () + 5; + } } // Handle window destroy events @@ -173,97 +136,35 @@ class AboutFrame extends Frame return false; } - private String title_ = "MedJava"; - private String by_ = "by"; - private String author_ = "Prashant Jain"; - private String info_ = "Version 1.0"; - private Button okButton_ = new Button (" ok "); -} - -class HelpFrame extends Frame -{ - public HelpFrame (String codeBase) - { - super ("Help"); - this.setBackground (Color.cyan); - this.text_.setEditable (false); - Font defaultFont = new Font ("TimesRoman", Font.PLAIN, 14); - this.text_.setFont (defaultFont); - - try - { - URL url = new URL (codeBase + "../ImageProcessing/framework/help.conf"); - String delim = "\n"; - - // Get the input stream and pipe it to a DataInputStream - DataInputStream iStream = new DataInputStream (url.openStream ()); - - // Keep reading the data until we are done - String tempString = iStream.readLine (); - while (tempString != null) - { - if (tempString.startsWith ("<START>")) - delim = ""; - else if (tempString.startsWith ("<END>")) - delim = "\n"; - else if (tempString.startsWith ("<TAB>")) - this.text_.appendText ("\t"); - else if (tempString.startsWith ("<P>")) - this.text_.appendText ("\n"); - else - { - this.text_.appendText (tempString); - this.text_.appendText (delim); - } - tempString = iStream.readLine (); - } - } - catch (MalformedURLException e) - { - System.err.println (e); - } - catch (IOException e) - { - System.err.println (e); - } - - this.resize (600,700); - this.setLayout (new BorderLayout ()); - - Panel okButtonPanel = new Panel (); - okButtonPanel.add (this.okButton_); - this.add ("South", okButtonPanel); - this.add ("Center", this.text_); - } - - // Handle window destroy events - public boolean handleEvent (Event evt) - { - if (evt.id == Event.WINDOW_DESTROY) - { - this.dispose (); - return true; - } - return super.handleEvent (evt); - } - - // Handle all action events - public boolean action (Event e, Object arg) + private void setText () { - if (e.target instanceof Button) - { - if (e.target == this.okButton_) - { - this.dispose (); - } - return true; - } - else - return false; + text_[0] = "This is a prototype of a large scale distributed medical"; + text_[1] = "imaging system. It has been developed using Java, in"; + text_[2] = "particular, several components of Java ACE."; + text_[3] = ""; + text_[4] = "The prototype allows images to be downloaded across the"; + text_[5] = "network. It then provides several filters that can be"; + text_[6] = "used to do image processing. The image filters are"; + text_[7] = "configured into the system dynamically using the Service"; + text_[8] = "Configurator pattern. In the current implementation, the"; + text_[9] = "filters are specified via a configuration file located at"; + text_[10] = "server. The file can be modified at runtime to add"; + text_[11] = "additional filters or to remove some filters. This allows"; + text_[12] = "filters to be configured and reconfigured dynamically."; + text_[13] = ""; + text_[14] = "Currently, images can not be uploaded. This is mainly due"; + text_[15] = "to security restrictions imposed by current servers. Our"; + text_[16] = "goal is to use the prototpe in conjunction with JAWS, an"; + text_[17] = "adaptive web server we are currently developing in which we"; + text_[18] = "plan to provide support for image uploading."; + text_[19] = ""; + text_[20] = "For more information about this prototype, please contact"; + text_[21] = "Prashant Jain (pjain@cs.wustl.edu)."; } - private Vector helpInfo_ = new Vector (); + private final static int MAXROWS = 22; private Button okButton_ = new Button (" ok "); - private TextArea text_ = new TextArea (); + private TextArea textArea_ = null; + private String [] text_ = new String [AboutFrame.MAXROWS]; } diff --git a/java/ImageProcessing/framework/DialogType.java b/java/ImageProcessing/framework/DialogType.java index c95372c08e1..eddd7d0a4e2 100644 --- a/java/ImageProcessing/framework/DialogType.java +++ b/java/ImageProcessing/framework/DialogType.java @@ -6,6 +6,5 @@ public class DialogType public static final int MALFORMED_URL = 1; public static final int URL_NOT_FOUND = 2; public static final int NOT_SUPPORTED = 3; - public static final int HELP = 4; public static final int NOT_YET_IMPLEMENTED = 10; } diff --git a/java/ImageProcessing/framework/FilePanel.java b/java/ImageProcessing/framework/FilePanel.java index ac5589d7862..86bc5e50c3e 100644 --- a/java/ImageProcessing/framework/FilePanel.java +++ b/java/ImageProcessing/framework/FilePanel.java @@ -144,6 +144,9 @@ class HelpPanel extends Panel this.add (this.aboutButton_); this.add (this.helpButton_); + // Disable the Help button for now + this.helpButton_.disable (); + this.resize (100, 100); } diff --git a/java/ImageProcessing/framework/ImageApp.java b/java/ImageProcessing/framework/ImageApp.java index 5cfe8835b42..aa50fd3105f 100644 --- a/java/ImageProcessing/framework/ImageApp.java +++ b/java/ImageProcessing/framework/ImageApp.java @@ -157,7 +157,7 @@ public class ImageApp extends Applet Choice choice = new Choice (); // Add the default choice first - choice.addItem ("Filters:"); + choice.addItem ("None"); // Now do the file processing -- to determine which filters need // to be loaded. @@ -170,6 +170,11 @@ public class ImageApp extends Applet if (this.configFile_ == null) this.configFile_ = "http://www.cs.wustl.edu/~pjain/java/ACE_wrappers/java/ImageProcessing/framework/filter.conf"; + if (this.filterContext_ == null) + this.filterContext_ = getParameter ("filterContext"); + if (this.filterContext_ == null) + this.filterContext_ = "http://www.cs.wustl.edu/~pjain/java/ACE_wrappers/java/ImageProcessing/"; + URL url; String configInfo= null; try @@ -218,6 +223,7 @@ public class ImageApp extends Applet fullFilterName = tokens.nextToken (); filterName = this.extractFilterName (fullFilterName); + // URL filter = new URL (this.filterContext_ + fullFilterName + ".class"); System.out.println ("Loading: " + fullFilterName); // Load the filter class Class c = Class.forName (fullFilterName); @@ -264,6 +270,7 @@ public class ImageApp extends Applet private Panel centerPanel_ = new Panel (); private String configFile_ = null; + private String filterContext_ = null; private Choice choice_ = null; private ImageCanvas imageCanvas_ = new ImageCanvas (); private FilePanel filePanel_; diff --git a/java/ImageProcessing/framework/ImageCanvas.java b/java/ImageProcessing/framework/ImageCanvas.java index 182bd54bf9b..f527accf545 100644 --- a/java/ImageProcessing/framework/ImageCanvas.java +++ b/java/ImageProcessing/framework/ImageCanvas.java @@ -143,13 +143,10 @@ class ImageCanvas extends Canvas // Check if mouse is within the bounds of the image private boolean inBounds (int x, int y) { - if (this.image_ == null) - return false; - else - return (x >= this.x_) && - (y >= this.y_) && - (x <= (this.x_ + this.zoom_ * this.image_.getWidth (this))) && - (y <= (this.y_ + this.zoom_ * this.image_.getHeight (this))); + return (x >= this.x_) && + (y >= this.y_) && + (x <= (this.x_ + this.zoom_ * this.image_.getWidth (this))) && + (y <= (this.y_ + this.zoom_ * this.image_.getHeight (this))); } private MediaTracker tracker_ = new MediaTracker(this); diff --git a/netsvcs/clients/Naming/Dump_Restore/nametest.cpp b/netsvcs/clients/Naming/Dump_Restore/nametest.cpp deleted file mode 100644 index fb9c71a5014..00000000000 --- a/netsvcs/clients/Naming/Dump_Restore/nametest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "ace/Naming_Context.h" -// $Id$ - -#include "ace/Name_Options.h" -#include "nametest.h" - -void -Nametest::listopt (void) -{ - cout << "serverport is " - << ACE_Name_Options::instance ()->nameserver_port() - << endl; - cout << "serverhost is " - << ACE_Name_Options::instance ()->nameserver_host() - << endl; - cout << "process_name is " - << ACE_Name_Options::instance ()->process_name() - << endl; - cout << "namespace_dir is " - << ACE_Name_Options::instance ()->namespace_dir() - << endl; -} - -int -Nametest::init (int argc, char *argv[]) -{ - ACE_Server_Record *sr; - ACE_Service_Config::svc_rep ()->find ("Name_Server_Proxy", &sr); - ACE_Service_Type *st = sr->type (); - ACE_Server_Object *so = st->object (); -dynamic_cast<ACE_Name_Server_Proxy *> (so); - - ACE_Name_Server_Proxy *ns_proxy = ACE_Service_Config::name_server_proxy (); - - ns_proxy->bind (...); - - this->listopt (); - - ACE_Naming_Context ns_context; - - if (ns_context.open (ACE_Naming_Context::NET_LOCAL) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ns_context.open"), -1); - - const char *mykey = argv[0]; - char *myvalue = argv[1]; - char *ns_value = 0; - char *ns_type = 0; - - if (ns_context.bind (mykey, myvalue, "ottotype") == -1) - cout << "bind failed" << endl; - else - cout << "bind succeeded" << endl; - - - if (ns_context.resolve (mykey, ns_value, ns_type) == -1) - cout << "resolve of " << mykey << " failed" << endl; - else - cout << "resolve of " << mykey << " succeeded, value = " - << ns_value << ", type = " << ns_type << endl; - - delete [] ns_value; - delete [] ns_type; - ns_value = 0; - ns_type = 0; - - if (ns_context.rebind (mykey, myvalue, "newottotype") == -1) - cout << "rebind failed" << endl; - else - cout << "rebind succeeded" << endl; - - if (ns_context.resolve (mykey, ns_value, ns_type) == -1) - cout << "resolve of " << mykey << " failed" << endl; - else - cout << "resolve of " << mykey << " succeeded, value = " - << ns_value << ", type = " << ns_type << endl; - - delete [] ns_value; - delete [] ns_type; - ns_value = 0; - ns_type = 0; - - if (ns_context.unbind (mykey) == -1) - cout << "unbind failed" << endl; - else - cout << "unbind succeeded" << endl; - - return 0; -} - -int -Nametest::fini (void) -{ - cout << "Nametest::fini called" << endl; - return 0; -} - -int -Nametest::info (char **, unsigned) const -{ - cout << "Nametest::info called" << endl; - return 0; -} - -extern "C" ACE_Service_Object *_alloc(void); - -// Factory function that is called automatically when the ACE -// framework dynamically links this shared object file. - -ACE_Service_Object *_alloc (void) -{ - return new Nametest; -} diff --git a/netsvcs/clients/Naming/Dump_Restore/nametest.h b/netsvcs/clients/Naming/Dump_Restore/nametest.h deleted file mode 100644 index fa0cc5dc05c..00000000000 --- a/netsvcs/clients/Naming/Dump_Restore/nametest.h +++ /dev/null @@ -1,15 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -#include "ace/Service_Object.h" - -class Nametest : public ACE_Service_Object -{ -public: - virtual int init (int argc, char *argv[]); - virtual int fini (void); - virtual int info (char **, size_t) const; - - void listopt (void); -}; - diff --git a/netsvcs/lib/Client_Logging_Handler.i b/netsvcs/lib/Client_Logging_Handler.i deleted file mode 100644 index 57c6d26e751..00000000000 --- a/netsvcs/lib/Client_Logging_Handler.i +++ /dev/null @@ -1,4 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - diff --git a/netsvcs/lib/Server_Logging_Handler.cpp b/netsvcs/lib/Server_Logging_Handler.cpp index e9cc86f1255..0fa8089a820 100644 --- a/netsvcs/lib/Server_Logging_Handler.cpp +++ b/netsvcs/lib/Server_Logging_Handler.cpp @@ -100,10 +100,8 @@ template class ACE_Thr_Server_Logging_Handler<Synch_Receiver>; template class ACE_Svc_Handler<LOGGING_PEER_STREAM, ACE_SYNCH>; #if defined (ACE_HAS_TLI) - #if defined (ACE_HAS_THREADS) - template class ACE_Svc_Handler<LOGGING_PEER_STREAM, ACE_NULL_SYNCH>; - #endif /* ACE_HAS_THREADS */ - // else if ! ACE_HAS_TLI, LOGGING_PEER_STREAM is ACE_SOCK_STREAM, + template class ACE_Svc_Handler<LOGGING_PEER_STREAM, ACE_NULL_SYNCH>; + // else LOGGING_PEER_STREAM is ACE_SOCK_STREAM, // and the specialization would be // template class ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>; // That specialization is in TS_Server_Handler.cpp, so we don't need it diff --git a/netsvcs/lib/Server_Logging_Handler.i b/netsvcs/lib/Server_Logging_Handler.i deleted file mode 100644 index 57c6d26e751..00000000000 --- a/netsvcs/lib/Server_Logging_Handler.i +++ /dev/null @@ -1,4 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - diff --git a/netsvcs/lib/Server_Logging_Handler_T.cpp b/netsvcs/lib/Server_Logging_Handler_T.cpp index 5d85bc14a8f..d330b0a8eac 100644 --- a/netsvcs/lib/Server_Logging_Handler_T.cpp +++ b/netsvcs/lib/Server_Logging_Handler_T.cpp @@ -244,7 +244,8 @@ ACE_Thr_Server_Logging_Handler<LMR>::ACE_Thr_Server_Logging_Handler (ACE_Thread_ { } -template<class LMR> int +template<class LMR> +int ACE_Thr_Server_Logging_Handler<LMR>::open (void *) { // call base class open_common diff --git a/netsvcs/servers/cli.conf b/netsvcs/servers/cli.conf deleted file mode 100644 index b2d8fbc8194..00000000000 --- a/netsvcs/servers/cli.conf +++ /dev/null @@ -1,11 +0,0 @@ -# UNIX version -# -# These are the services that can be linked into ACE. -# Note that you can replace the hardcoded "../lib/libnet_svcs" with -# a relative path if you set your LD search path correctly -- ACE will -# locate this for you automatically by reading your LD search path! -# In addition, you can replace the hardcoded "-p 20xxx" with "-p -# $PORTxxx" if you set your environment variables correctly. - -# Activate the Client Logging Daemon. -dynamic Client_Logging_Service Service_Object * ../lib/libnet_svcs:_make_ACE_Client_Logging_Connector() active "-p 20009 -h merengue" diff --git a/netsvcs/servers/ntsvc.conf b/netsvcs/servers/ntsvc.conf deleted file mode 100644 index 94ed5d78c2a..00000000000 --- a/netsvcs/servers/ntsvc.conf +++ /dev/null @@ -1,12 +0,0 @@ -# Windows NT version. -# -# These are the services that can be linked into ACE. -# Note that your path needs to include the path for netsvcs.dll -# In addition, you can replace the hardcoded "-p 20xxx" with "-p -# $PORTxxx" if you set your environment variables correctly. - -dynamic Token_Service Service_Object * netsvcs.dll:_make_ACE_Token_Acceptor() "-p 20202" -dynamic Name_Server Service_Object * netsvcs.dll:_make_ACE_Name_Acceptor() "-p 20012" -#dynamic Client_Logging_Service Service_Object * netsvcs.dll:_make_ACE_Client_Logging_Connector() active "-p 20008" -#dynamic Server_Logging_Service Service_Object * netsvcs.dll:_make_ACE_Server_Logging_Acceptor() active "-p 20009" -#dynamic Thr_Server_Logging_Service Service_Object * netsvcs.dll:_make_ACE_Thr_Server_Logging_Acceptor() active "-p 20020" diff --git a/performance-tests/Misc/test_naming.cpp b/performance-tests/Misc/test_naming.cpp index 41e09f541ff..ea2b00c1124 100644 --- a/performance-tests/Misc/test_naming.cpp +++ b/performance-tests/Misc/test_naming.cpp @@ -131,11 +131,8 @@ void do_testing (int argc, char *argv[], int light) } else // Use NO-SYNC { - const char *p = ACE::basename (name_options->process_name (), - ACE_DIRECTORY_SEPARATOR_CHAR); - char s[5 /* strlen ("light") */ + MAXNAMELEN + 1]; - ACE_OS::sprintf (s, "light%s", p); - name_options->database (s); + name_options->database (ACE_OS::strcat ("light", ACE::basename (name_options->process_name (), + ACE_DIRECTORY_SEPARATOR_CHAR))); ns_context.open (ACE_Naming_Context::PROC_LOCAL, 1); } diff --git a/tests/Buffer_Stream_Test.cpp b/tests/Buffer_Stream_Test.cpp index 4444b1ed070..2ba15d15cc3 100644 --- a/tests/Buffer_Stream_Test.cpp +++ b/tests/Buffer_Stream_Test.cpp @@ -112,11 +112,11 @@ Producer::svc (void) ACE_NEW_THREAD; // Keep reading stdin, until we reach EOF. - for (char *c = ACE_ALPHABET; *c != '\0'; c++) + for (char c = 'a'; c <= 'z'; c++) { // Allocate a new message. char d[2]; - d[0] = *c; + d[0] = c; d[1] = '\0'; ACE_Message_Block *mb; @@ -152,7 +152,7 @@ Consumer::svc (void) ACE_Message_Block *mb = 0; int result = 0; - char *c = ACE_ALPHABET; + char c = 'a'; char *output; // Keep looping, reading a message out of the queue, until we @@ -171,7 +171,7 @@ Consumer::svc (void) if (length > 0) { output = mb->rd_ptr (); - ACE_ASSERT (*c == output[0]); + ACE_ASSERT (c == output[0]); c++; } mb->release (); diff --git a/tests/CPP_Test.cpp b/tests/CPP_Test.cpp deleted file mode 100644 index 4c0bd291a50..00000000000 --- a/tests/CPP_Test.cpp +++ /dev/null @@ -1,261 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// CPP_Test.cpp -// -// = DESCRIPTION -// This is a simple test of the ACE_SOCK_Acceptor and -// AC_SOCK_Connector classes. The test forks two processes or -// spawns two threads (depending upon the platform) and then executes -// client and server allowing them to connect and exchange -// data. No user input is required as far as command line -// arguments are concerned. -// -// = AUTHOR -// Prashant Jain and Doug Schmidt -// -// ============================================================================ - -#include "ace/OS.h" -#include "ace/Thread.h" -#include "ace/Service_Config.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "ace/INET_Addr.h" -#include "ace/Handle_Set.h" -#include "test_config.h" - -static void * -client (void *arg) -{ -#if (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) - // Insert thread into thr_mgr - ACE_Thread_Control thread_control (ACE_Service_Config::thr_mgr ()); - ACE_NEW_THREAD; -#endif /* (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) */ - - ACE_INET_Addr *remote_addr = (ACE_INET_Addr *) arg; - ACE_INET_Addr server_addr (remote_addr->get_port_number (), "localhost"); - ACE_SOCK_Stream cli_stream; - ACE_SOCK_Connector con; - - ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting non-blocking connect\n")); - // Initiate timed, non-blocking connection with server. - - // Attempt a non-blocking connect to the server, reusing the local - // addr if necessary. - if (con.connect (cli_stream, server_addr, - (ACE_Time_Value *) &ACE_Time_Value::zero) == -1) - { - if (errno != EWOULDBLOCK) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "connection failed")); - - ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting timed connect\n")); - - // Check if non-blocking connection is in progress, - // and wait up to ACE_DEFAULT_TIMEOUT seconds for it to complete. - ACE_Time_Value tv (ACE_DEFAULT_TIMEOUT); - - if (con.complete (cli_stream, &server_addr, &tv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "connection failed"), 0); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) connected to %s\n", - server_addr.get_host_name ())); - } - - if (cli_stream.disable (ACE_NONBLOCK) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "disable")); - - // Send data to server (correctly handles "incomplete writes"). - - for (char c = 'a'; c <= 'z'; c++) - if (cli_stream.send_n (&c, 1) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); - - // Explicitly close the writer-side of the connection. - if (cli_stream.close_writer () == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close_writer")); - - char buf[1]; - - // Wait for handshake with server. - if (cli_stream.recv_n (buf, 1) != 1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "recv_n")); - - // Close the connection completely. - if (cli_stream.close () == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); - - return 0; -} - -static void * -server (void *arg) -{ -#if (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) - // Insert thread into thr_mgr - ACE_Thread_Control thread_control (ACE_Service_Config::thr_mgr ()); - ACE_NEW_THREAD; -#endif /* (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) */ - - ACE_SOCK_Acceptor *peer_acceptor = (ACE_SOCK_Acceptor *) arg; - - if (peer_acceptor->enable (ACE_NONBLOCK) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "enable")); - - // Keep these objects out here to prevent excessive constructor - // calls... - ACE_SOCK_Stream new_stream; - ACE_INET_Addr cli_addr; - ACE_Handle_Set handle_set; - ACE_Time_Value tv (ACE_DEFAULT_TIMEOUT); - // Performs the iterative server activities. - - for (;;) - { - char buf[BUFSIZ]; - char t = 'a'; - - handle_set.reset (); - handle_set.set_bit (peer_acceptor->get_handle ()); - - int result = ACE_OS::select (int (peer_acceptor->get_handle ()) + 1, - handle_set, - 0, 0, &tv); - if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "select"), 0); - else if (result == 0) - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) select timed out, shutting down\n")); - return 0; - } - - // Create a new ACE_SOCK_Stream endpoint (note automatic restart - // if errno == EINTR). - - while ((result = peer_acceptor->accept (new_stream, &cli_addr)) != -1) - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) client %s connected from %d\n", - cli_addr.get_host_name (), cli_addr.get_port_number ())); - - // Enable non-blocking I/O. - if (new_stream.enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "enable"), 0); - - handle_set.reset (); - handle_set.set_bit (new_stream.get_handle ()); - - // Read data from client (terminate on error). - - for (ssize_t r_bytes; ;) - { - if (ACE_OS::select (int (new_stream.get_handle ()) + 1, - handle_set, - 0, 0, 0) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "select"), 0); - - while ((r_bytes = new_stream.recv_n (buf, 1)) > 0) - { - ACE_ASSERT (t == buf[0]); - t++; - } - - if (r_bytes == 0) - { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) reached end of input, connection closed by client\n")); - - // Handshake back with client. - if (new_stream.send_n ("", 1) != 1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); - - // Close endpoint. - if (new_stream.close () == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); - return 0; - } - else if (r_bytes == -1) - { - if (errno == EWOULDBLOCK) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) no input available, going back to reading\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "recv_n"), 0); - } - } - } - - if (result == -1) - { - if (errno == EWOULDBLOCK) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) no connections available, going back to accepting\n")); - else - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "accept")); - } - } - return 0; -} - -static void -spawn (void) -{ - // Acceptor - ACE_SOCK_Acceptor peer_acceptor; - - // Create a server address. - ACE_INET_Addr server_addr; - - // Bind listener to any port and then find out what the port was. - if (peer_acceptor.open (ACE_Addr::sap_any) == -1 - || peer_acceptor.get_local_addr (server_addr) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "open")); - else - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting server at port %d\n", - server_addr.get_port_number ())); - -#if !defined (ACE_WIN32) && !defined (VXWORKS) - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "fork failed")); - exit (-1); - case 0: - ACE_LOG_MSG->sync ("child"); - client (&server_addr); - default: - server ((void *) &peer_acceptor); - ACE_OS::wait (); - } -#elif defined (ACE_HAS_THREADS) - if (ACE_Service_Config::thr_mgr ()->spawn - (ACE_THR_FUNC (server), (void *) &peer_acceptor, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "thread create failed")); - - if (ACE_Service_Config::thr_mgr ()->spawn - (ACE_THR_FUNC (client), (void *) &server_addr, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "thread create failed")); - - // Wait for the threads to exit. - ACE_Service_Config::thr_mgr ()->wait (); -#else - ACE_ERROR ((LM_ERROR, "(%P|%t) only one thread may be run in a process on this platform\n%a", 1)); -#endif /* ACE_HAS_THREADS */ - } -} - -int -main (int, char *[]) -{ - ACE_START_TEST ("CPP_Test"); - - spawn (); - - ACE_END_TEST; - return 0; -} diff --git a/tests/Conn_Test.cpp b/tests/Conn_Test.cpp index d5b6dd3ef5d..b5482267d31 100644 --- a/tests/Conn_Test.cpp +++ b/tests/Conn_Test.cpp @@ -66,8 +66,8 @@ Svc_Handler::send_data (void) { // Send data to server. - for (char *c = ACE_ALPHABET; *c != '\0'; c++) - if (this->peer ().send_n (c, 1) == -1) + for (char c = 'a'; c <= 'z'; c++) + if (this->peer ().send_n (&c, 1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); } @@ -79,7 +79,7 @@ Svc_Handler::recv_data (void) ACE_Handle_Set handle_set; handle_set.set_bit (new_stream.get_handle ()); - char *t = ACE_ALPHABET; + char t = 'a'; // Read data from client (terminate on error). @@ -97,13 +97,13 @@ Svc_Handler::recv_data (void) while ((r_bytes = new_stream.recv (&c, 1)) > 0) { - ACE_ASSERT (*t == c); + ACE_ASSERT (t == c); // We need to guard against cached connections, which // will send multiple sequences of letters from 'a' -> // 'z' through the same connection. - if (*t == 'z') - t = ACE_ALPHABET; + if (t == 'z') + t = 'a'; else t++; } diff --git a/tests/Future_Test.cpp b/tests/Future_Test.cpp index 6bededf0c32..6c42e795d08 100644 --- a/tests/Future_Test.cpp +++ b/tests/Future_Test.cpp @@ -12,8 +12,8 @@ // This example tests the ACE Future. // // = AUTHOR -// Andres Kruse <Andres.Kruse@cern.ch>, Douglas C. Schmidt -// <schmidt@cs.wustl.edu> and Per Andersson <pera@ipso.se> +// Andres Kruse <Andres.Kruse@cern.ch> and Douglas C. Schmidt +// <schmidt@cs.wustl.edu> // // ============================================================================ @@ -36,12 +36,15 @@ static ATOMIC_INT task_count (0); // a counter for the futures.. static ATOMIC_INT future_count (0); +static ATOMIC_INT future_no (0); // a counter for the capsules.. static ATOMIC_INT capsule_count (0); +static ATOMIC_INT capsule_no (0); // a counter for the method objects... static ATOMIC_INT methodobject_count (0); +static ATOMIC_INT methodobject_no (0); class Scheduler : public ACE_Task<ACE_MT_SYNCH> // = TITLE @@ -89,10 +92,10 @@ Method_Object_work::Method_Object_work (Scheduler* new_Scheduler, u_long new_param, int new_count, ACE_Future<u_long> &new_result) - : scheduler_ (new_Scheduler), - param_ (new_param), - count_ (new_count), - future_result_ (new_result) + : scheduler_ (new_Scheduler), + param_ (new_param), + count_ (new_count), + future_result_ (new_result) { ACE_DEBUG ((LM_DEBUG, "(%t) Method_Object_work created\n")); @@ -100,17 +103,14 @@ Method_Object_work::Method_Object_work (Scheduler* new_Scheduler, Method_Object_work::~Method_Object_work (void) { - ACE_DEBUG ((LM_DEBUG, - "(%t) Method_Object_work will be deleted.\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) Method_Object_work will be deleted.\n")); } int Method_Object_work::call (void) { - return this->future_result_.set - (this->scheduler_->work_i (this->param_, - this->count_)); + return this->future_result_.set (this->scheduler_->work_i (this->param_, this->count_)); } class Method_Object_name : public ACE_Method_Object @@ -118,8 +118,7 @@ class Method_Object_name : public ACE_Method_Object // Reification of the <name> method. { public: - Method_Object_name (Scheduler *, - ACE_Future<const char*> &); + Method_Object_name (Scheduler *, ACE_Future<const char*> &); virtual ~Method_Object_name (void); virtual int call (void); @@ -154,36 +153,27 @@ class Method_Object_end : public ACE_Method_Object // Reification of the <end> method. { public: - Method_Object_end (Scheduler *new_Scheduler) - : scheduler_ (new_Scheduler) {} + Method_Object_end (Scheduler *new_Scheduler): scheduler_ (new_Scheduler) {} virtual ~Method_Object_end (void) {} - virtual int call (void) { - this->scheduler_->close (); - return -1; - } + virtual int call (void) { this->scheduler_->close (); return -1; } private: Scheduler *scheduler_; }; // constructor -Scheduler::Scheduler (const char *newname, - Scheduler *new_Scheduler) +Scheduler::Scheduler (const char *newname, Scheduler *new_Scheduler) { ACE_NEW (this->name_, char[ACE_OS::strlen (newname) + 1]); ACE_OS::strcpy ((char *) this->name_, newname); this->scheduler_ = new_Scheduler; - ACE_DEBUG ((LM_DEBUG, - "(%t) Scheduler %s created\n", - this->name_)); + ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s created\n", this->name_)); } // Destructor Scheduler::~Scheduler (void) { - ACE_DEBUG ((LM_DEBUG, - "(%t) Scheduler %s will be destroyed\n", - this->name_)); + ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s will be destroyed\n", this->name_)); delete[] this->name_; } @@ -192,10 +182,7 @@ int Scheduler::open (void *) { task_count++; - ACE_DEBUG ((LM_DEBUG, - "(%t) Scheduler %s open\n", - this->name_)); - // Become an Active Object. + ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s open\n", this->name_)); return this->activate (THR_BOUND); } @@ -203,9 +190,7 @@ Scheduler::open (void *) int Scheduler::close (u_long) { - ACE_DEBUG ((LM_DEBUG, - "(%t) Scheduler %s close\n", - this->name_)); + ACE_DEBUG ((LM_DEBUG, "(%t) Scheduler %s close\n", this->name_)); task_count--; return 0; } @@ -284,8 +269,7 @@ Scheduler::work (u_long newparam, int newcount) ACE_Future<u_long> new_future; this->activation_queue_.enqueue - (new Method_Object_work (this, newparam, - newcount, new_future)); + (new Method_Object_work (this, newparam, newcount, new_future)); return new_future; } } @@ -297,12 +281,10 @@ static int n_loops = 100; #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) template class ACE_Future<const char *>; -template class ACE_Future<int>; template class ACE_Future<u_long>; -template class ACE_Future_Rep<char const *>; -template class ACE_Future_Rep<int>; -template class ACE_Future_Rep<u_long>; template class auto_ptr<ACE_Method_Object>; +template class ACE_Future_Rep<char const *>; +template class ACE_Future_Rep<unsigned long>; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ #endif /* ACE_HAS_THREADS */ @@ -335,8 +317,7 @@ main (int, char *[]) ACE_Future<u_long> fresulta, fresultb, fresultc, fresultd, fresulte; ACE_Future<const char*> fname; - ACE_DEBUG ((LM_DEBUG, - "(%t) going to do a non-blocking call\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) going to do a non-blocking call\n")); fresulta = andres->work (9013); fresultb = peter->work (9013); @@ -346,11 +327,9 @@ main (int, char *[]) // see if the result is available... if (fresulta.ready ()) - ACE_DEBUG ((LM_DEBUG, - "(%t) wow.. work is ready.....\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) wow.. work is ready.....\n")); - ACE_DEBUG ((LM_DEBUG, - "(%t) non-blocking call done... now blocking...\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) non-blocking call done... now blocking...\n")); // Save the result of fresulta. @@ -411,86 +390,7 @@ main (int, char *[]) (int) capsule_count, (int) methodobject_count)); - { - // Check if set then get works, older versions of ACE_Future - // will lock forever (or until the timer expires), will use a small - // timer value to avoid blocking the process. - - ACE_Future<int> f1; - f1.set(100); - - ACE_Time_Value timeout(1); - int value = 0; - - if (f1.get (value, &timeout) == 0 && value == 100) - ACE_DEBUG ((LM_DEBUG, - "Ace_Future<T>::Set followed by Ace_Future<T>::Get works.\n")); - else - ACE_DEBUG ((LM_DEBUG, - "ACE_Future<T>::Set followed by Ace_Future<T>::Get does " - "not work, broken Ace_Future<> implementation.\n")); - } - { - ACE_DEBUG ((LM_DEBUG, - "Checking if Ace_Future<T>::operator= is implemented " - "incorrectly this might crash the program.\n")); - - ACE_Future<int> f1; - { - ACE_Future<int> f2 (f1); // To ensure that a rep object is created - } - // Now it is one ACE_Future<int> referencing the rep instance - - ACE_DEBUG ((LM_DEBUG, "0.\n")); - //check that self assignment works - f1 = f1; - // Is there any repesentation left, and if so what is the ref - // count older ACE_Future<> implementations have deleted the rep - // instance at this moment - - // The stuff below might crash the process if the op= - // implementation was bad - int value = 0; - ACE_Time_Value timeout (1); - - f1.set (100); - f1.get (value, &timeout); - - ACE_DEBUG ((LM_DEBUG, "1.\n")); - { // Might delete the same data a couple of times - ACE_Future<int> f2 (f1); - f1.set (100); - f1.get (value, &timeout); - } - - ACE_DEBUG ((LM_DEBUG, "2.\n")); - { - ACE_Future<int> f2 (f1); - f1.set (100); - f1.get (value, &timeout); - } - - ACE_DEBUG ((LM_DEBUG, "3.\n")); - { - ACE_Future<int> f2 (f1); - f1.set (100); - f1.get (value, &timeout); - } - ACE_DEBUG ((LM_DEBUG, "4.\n")); - { - ACE_Future<int> f2 (f1); - f1.set (100); - f1.get (value, &timeout); - } - ACE_DEBUG ((LM_DEBUG, "5.\n")); - { - ACE_Future<int> f2 (90); - f2.get (value, &timeout); - f1.get (value, &timeout); - } - } - ACE_DEBUG ((LM_DEBUG, - "No it did not crash the program.\n")); + ACE_DEBUG ((LM_DEBUG,"(%t) th' that's all folks!\n")); ACE_OS::sleep (5); diff --git a/tests/Handle_Set_Test.cpp b/tests/Handle_Set_Test.cpp index 599b35ca5fc..d8803dfb137 100644 --- a/tests/Handle_Set_Test.cpp +++ b/tests/Handle_Set_Test.cpp @@ -18,123 +18,50 @@ // // ============================================================================ -#include "ace/Profile_Timer.h" + #include "ace/Handle_Set.h" #include "test_config.h" +#define IS_ODD(X) (((X) & 1) != 0) + static void -test_duplicates (size_t count) +run_test (int count) { - size_t duplicates = 0; - size_t sets = 0; - size_t clears = 0; + int duplicates = 0; + int sets = 0; + int clears = 0; ACE_Handle_Set handle_set; ACE_OS::srand (ACE_OS::time (0L)); - for (size_t i = 0; i < count; i++) + for (int i = 0; i < count; i++) { - size_t handle = size_t (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE); + int j = int (ACE_OS::rand () % ACE_Handle_Set::MAXSIZE); - if (ACE_ODD (handle)) + if (IS_ODD (j)) { - if (handle_set.is_set ((ACE_HANDLE) handle)) + if (handle_set.is_set ((ACE_HANDLE) j)) duplicates++; - handle_set.set_bit ((ACE_HANDLE) handle); + handle_set.set_bit ((ACE_HANDLE) j); sets++; } else { - if (handle_set.is_set ((ACE_HANDLE) handle)) + if (handle_set.is_set ((ACE_HANDLE) j)) duplicates--; - handle_set.clr_bit ((ACE_HANDLE) handle); + handle_set.clr_bit ((ACE_HANDLE) j); clears++; } } ACE_ASSERT (count == sets + clears); ACE_ASSERT (handle_set.num_set () + duplicates == sets); -} - -static void -test_boundaries (void) -{ - ACE_Handle_Set handle_set; - - ACE_HANDLE handle; - - // First test an empty set. - ACE_Handle_Set_Iterator i1 (handle_set); - - while ((handle = i1 ()) != ACE_INVALID_HANDLE) - ACE_ASSERT (!"this shouldn't get called since the set is empty!\n"); - - // Insert a bunch of HANDLEs into the set, testing for boundary - // conditions. - - handle_set.set_bit ((ACE_HANDLE) 0); - handle_set.set_bit ((ACE_HANDLE) 1); - handle_set.set_bit ((ACE_HANDLE) 32); - handle_set.set_bit ((ACE_HANDLE) 63); - handle_set.set_bit ((ACE_HANDLE) 64); - handle_set.set_bit ((ACE_HANDLE) 65); - handle_set.set_bit ((ACE_HANDLE) 127); - handle_set.set_bit ((ACE_HANDLE) 128); - handle_set.set_bit ((ACE_HANDLE) 129); - handle_set.set_bit ((ACE_HANDLE) 255); - - int count = 0; - - ACE_Handle_Set_Iterator i2 (handle_set); - - while ((handle = i2 ()) != ACE_INVALID_HANDLE) - count++; - - ACE_ASSERT (count == handle_set.num_set ()); -} - -static void -test_performance (size_t max_handles, - size_t max_iterations) -{ - ACE_Handle_Set handle_set; - size_t i; - - for (i = 0; i < max_handles; i++) - handle_set.set_bit ((ACE_HANDLE) i); - - ACE_Profile_Timer timer; - ACE_HANDLE handle; - size_t count = 0; - - timer.start (); - - for (i = 0; i < max_iterations; i++) - { - ACE_Handle_Set_Iterator iter (handle_set); - - // Only iterate up to <handle_set.max_set ()>. - while ((handle = iter ()) != ACE_INVALID_HANDLE) - count++; - } - - timer.stop (); - - ACE_ASSERT (count == max_handles * max_iterations); - - ACE_Profile_Timer::ACE_Elapsed_Time et; - - timer.elapsed_time (et); - - ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n", - et.real_time, et.user_time, et.system_time)); - - ACE_DEBUG ((LM_DEBUG, "time per each of the %d calls = %f usecs\n", - count, (et.real_time / double (count)) * 1000000)); +// ACE_DEBUG ((LM_DEBUG, "count = %d, set_size = %d, duplicates = %d\n", +// count, handle_set.num_set (), (sets - clears) == duplicates)); } int @@ -143,12 +70,7 @@ main (int argc, char *argv[]) ACE_START_TEST ("Handle_Set_Test"); int count = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_Handle_Set::MAXSIZE; - size_t max_handles = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_Handle_Set::MAXSIZE; - size_t max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : ACE_MAX_ITERATIONS; - - test_duplicates (count); - test_boundaries (); - test_performance (max_handles, max_iterations); + run_test (count); ACE_END_TEST; return 0; diff --git a/tests/IOStream_Test.cpp b/tests/IOStream_Test.cpp index 32f9a0a3019..be0cfc1c683 100644 --- a/tests/IOStream_Test.cpp +++ b/tests/IOStream_Test.cpp @@ -21,12 +21,11 @@ #include "ace/Acceptor.h" #include "ace/SOCK_Connector.h" #include "ace/SOCK_Acceptor.h" +#include "ace/INET_Addr.h" #include "ace/IOStream.h" #include "test_config.h" -#if !defined (ACE_LACKS_ACE_IOSTREAM) - -typedef ACE_IOStream_T<ACE_SOCK_Stream> ACE_SOCK_IOStream; +typedef ACE_IOStream<ACE_SOCK_Stream> ACE_SOCK_IOStream; /* The biggest drawback to an iostream is that it generally eats up whitespace when performing a get (>>) operation. @@ -375,26 +374,19 @@ spawn (void) #endif /* ACE_HAS_THREADS */ return 0; } -#endif /* !ACE_LACKS_ACE_IOSTREAM */ int main (int, char *[]) { ACE_START_TEST ("IOStream_Test"); -#if !defined (ACE_LACKS_ACE_IOSTREAM) spawn (); -#else - ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n")); -#endif /* !ACE_LACKS_ACE_IOSTREAM */ + ACE_END_TEST; return 0; } - -#if !defined (ACE_LACKS_ACE_IOSTREAM) #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -template class ACE_IOStream_T<ACE_SOCK_Stream>; -template class ACE_Streambuf_T<ACE_SOCK_Stream>; +template class ACE_IOStream<ACE_SOCK_Stream>; +template class ACE_Streambuf<ACE_SOCK_Stream>; #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ -#endif /* !ACE_LACKS_ACE_IOSTREAM */ diff --git a/tests/MM_Shared_Memory_Test.cpp b/tests/MM_Shared_Memory_Test.cpp index 6149e201fda..b20083a1d22 100644 --- a/tests/MM_Shared_Memory_Test.cpp +++ b/tests/MM_Shared_Memory_Test.cpp @@ -42,13 +42,13 @@ client (void *) #endif /* ACE_WIN32 */ ACE_OS::sleep (3); - char *t = ACE_ALPHABET; + char t = 'a'; ACE_Shared_Memory_MM shm_client (shm_key); char *shm = (char *) shm_client.malloc (); for (char *s = shm; *s != '\0'; s++) { - ACE_ASSERT (*t == s[0]); + ACE_ASSERT (t == s[0]); t++; } *shm = '*'; @@ -72,8 +72,8 @@ server (void *) char *shm = (char *) shm_server.malloc (); char *s = shm; - for (char *c = ACE_ALPHABET; *c != '\0'; c++) - *s++ = *c; + for (char c = 'a'; c <= 'z'; c++) + *s++ = c; *s = '\0'; diff --git a/tests/Mem_Map_Test.cpp b/tests/Mem_Map_Test.cpp index 3ad9cc12a97..fa9078bc608 100644 --- a/tests/Mem_Map_Test.cpp +++ b/tests/Mem_Map_Test.cpp @@ -57,8 +57,8 @@ create_test_file (int size, int num_lines) char *mybuf; ACE_NEW_RETURN (mybuf, char[size + 1], -1); - char *c = ACE_ALPHABET; - char *d = c; + char c = 'a'; + char d = c; ACE_HANDLE file_handle = ACE_OS::open (ACE_DEFAULT_TEST_FILE, O_RDWR | O_CREAT | O_TRUNC, @@ -71,7 +71,7 @@ create_test_file (int size, int num_lines) { for (int i = 0; i < size; i++) { - mybuf[i] = *c; + mybuf[i] = c; c++; } diff --git a/tests/Priority_Buffer_Test.cpp b/tests/Priority_Buffer_Test.cpp index 7fe6d7cd33a..3a1134c63a2 100644 --- a/tests/Priority_Buffer_Test.cpp +++ b/tests/Priority_Buffer_Test.cpp @@ -94,14 +94,14 @@ producer (void *args) ACE_Message_Block *mb = 0; - for (char *c = ACE_ALPHABET; *c != '\0'; c++) + for (char c = 'a'; c <= 'z'; c++) { count++; // Allocate a new message ACE_NEW_RETURN (mb, ACE_Message_Block (1), 0); - *mb->rd_ptr () = *c; + *mb->rd_ptr () = c; // Set the priority. mb->msg_priority (count); diff --git a/tests/Priority_Task_Test.cpp b/tests/Priority_Task_Test.cpp index e7d6f4fb2b0..eeec7377c2c 100644 --- a/tests/Priority_Task_Test.cpp +++ b/tests/Priority_Task_Test.cpp @@ -29,6 +29,7 @@ class Priority_Task : public ACE_Task<ACE_MT_SYNCH> public: Priority_Task (void); + int close (u_long = 0); int open (void *); int svc (void); @@ -43,6 +44,13 @@ Priority_Task::Priority_Task (void) } int +Priority_Task::close (u_long) +{ + ACE_DEBUG ((LM_DEBUG, "(%t) leaving Task with priority %d\n", this->priority_)); + return 0; +} + +int Priority_Task::open (void *arg) { this->priority_ = *(int *) arg; @@ -129,12 +137,11 @@ main (int, char *[]) ACE_SCOPE_THREAD); } - ACE_DEBUG ((LM_DEBUG, "(%t) %d tasks spawned, wait for them to exit . . .\n", - ACE_MAX_ITERATIONS)); - // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); + for (i = 0; i < ACE_MAX_ITERATIONS; i++) + tasks[i].close (); #else ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); #endif /* ACE_HAS_THREADS */ diff --git a/tests/SOCK_Test.cpp b/tests/SOCK_Test.cpp index 4dfc0ac5023..08b8683ad76 100644 --- a/tests/SOCK_Test.cpp +++ b/tests/SOCK_Test.cpp @@ -71,8 +71,8 @@ client (void *arg) // Send data to server (correctly handles "incomplete writes"). - for (char *c = ACE_ALPHABET; *c != '\0'; c++) - if (cli_stream.send_n (c, 1) == -1) + for (char c = 'a'; c <= 'z'; c++) + if (cli_stream.send_n (&c, 1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); // Explicitly close the writer-side of the connection. @@ -119,7 +119,7 @@ server (void *arg) for (;;) { char buf[BUFSIZ]; - char *t = ACE_ALPHABET; + char t = 'a'; handle_set.reset (); handle_set.set_bit (peer_acceptor->get_handle ()); @@ -163,7 +163,7 @@ server (void *arg) while ((r_bytes = new_stream.recv (buf, 1)) > 0) { - ACE_ASSERT (*t == buf[0]); + ACE_ASSERT (t == buf[0]); t++; } diff --git a/tests/SPIPE_Test.cpp b/tests/SPIPE_Test.cpp index f47368c9e71..c06dded2721 100644 --- a/tests/SPIPE_Test.cpp +++ b/tests/SPIPE_Test.cpp @@ -51,8 +51,8 @@ client (void *) if (con.connect (cli_stream, ACE_SPIPE_Addr (ACE_WIDE_STRING (rendezvous))) == -1) ACE_ERROR ((LM_ERROR, "%p\n", rendezvous)); - for (char *c = ACE_ALPHABET; *c != '\0'; c++) - if (cli_stream.send (c, 1) == -1) + for (char c = 'a'; c <= 'z'; c++) + if (cli_stream.send (&c, 1) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "send_n")); if (cli_stream.close () == -1) @@ -74,7 +74,7 @@ server (void *) ACE_SPIPE_Acceptor acceptor; ACE_SPIPE_Stream new_stream; char buf[BUFSIZ]; - char *t = ACE_ALPHABET; + char t = 'a'; const char *rendezvous = PIPE_NAME; @@ -93,7 +93,7 @@ server (void *) while (new_stream.recv (buf, 1) > 0) { - ACE_ASSERT (*t == buf[0]); + ACE_ASSERT (t == buf[0]); t++; } ACE_DEBUG ((LM_DEBUG, "End of connection. Closing handle\n")); diff --git a/tests/SV_Shared_Memory_Test.cpp b/tests/SV_Shared_Memory_Test.cpp index e7e9eee727c..e5d7348c26a 100644 --- a/tests/SV_Shared_Memory_Test.cpp +++ b/tests/SV_Shared_Memory_Test.cpp @@ -28,9 +28,7 @@ static ACE_Malloc<ACE_SHARED_MEMORY_POOL, ACE_SV_Semaphore_Simple> allocator; const int SEM_KEY_1 = ACE_DEFAULT_SEM_KEY + 1; const int SEM_KEY_2 = ACE_DEFAULT_SEM_KEY + 2; - const int SHMSZ = 27; -const char SHMDATA[SHMSZ] = "abcdefghijklmnopqrstuvwxyz"; static int parent (char *shm) @@ -44,8 +42,12 @@ parent (char *shm) ACE_ASSERT (synch.open (SEM_KEY_2, ACE_SV_Semaphore_Complex::ACE_CREATE, 0) != -1); - for (int i = 0; i < SHMSZ; i++) - shm[i] = SHMDATA[i]; + char *s = shm; + + for (char c = 'a'; c <= 'z'; c++) + *s++ = c; + + *s = '\0'; if (mutex.release () == -1) ACE_ERROR ((LM_ERROR, "(%P) %p", "parent mutex.release")); @@ -79,8 +81,12 @@ child (char *shm) else ACE_ERROR_RETURN ((LM_ERROR, "(%P) child mutex.tryacquire"), 1); - for (int i = 0; i < SHMSZ; i++) - ACE_ASSERT (SHMDATA[i] == shm[i]); + char t = 'a'; + for (char *s = (char *) shm; *s != '\0'; s++) + { + ACE_ASSERT (t == s[0]); + t++; + } if (synch.release () == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%P) child synch.release"), 1); diff --git a/tests/Shared_Memory_SV_Test.cpp b/tests/Shared_Memory_SV_Test.cpp deleted file mode 100644 index a3654a7745b..00000000000 --- a/tests/Shared_Memory_SV_Test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// $Id$ - -// ============================================================================ -// -// = LIBRARY -// tests -// -// = FILENAME -// Shared_Memory_SV_Test.cpp -// -// = DESCRIPTION -// This is a simple test of ACE_Shared_Memory_SV -// -// = AUTHOR -// Prashant Jain and Doug Schmidt -// -// ============================================================================ - - -#include "ace/Shared_Memory_SV.h" -#include "test_config.h" - -const int SHMSZ = 27; -const int SHM_KEY = 5678; - -static void -client (void) -{ - char t = 'a'; - ACE_Shared_Memory_SV shm_client (SHM_KEY, SHMSZ, - ACE_Shared_Memory_SV::ACE_CREATE); - char *shm = (char *) shm_client.malloc (); - - for (char *s = shm; *s != '\0'; s++) - { - ACE_ASSERT (t == s[0]); - t++; - } - *shm = '*'; - ACE_OS::exit (0); -} - -static void -server (void) -{ - ACE_Shared_Memory_SV shm_server (SHM_KEY, SHMSZ, - ACE_Shared_Memory_SV::ACE_CREATE); - char *shm = (char *) shm_server.malloc (); - char *s = shm; - - for (char c = 'a'; c <= 'z'; c++) - *s++ = c; - - *s = '\0'; - - while (*shm != '*') - ACE_OS::sleep (1); - - if (shm_server.remove () < 0) - ACE_ERROR ((LM_ERROR, "%p\n", "remove")); -} - -int -main (int, char *argv []) -{ - ACE_START_TEST ("Shared_Memory_SV_Test.cpp"); - - switch (ACE_OS::fork ()) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "fork"), 1); - case 0: - client (); - break; - default: - server (); - break; - } - - ACE_END_TEST; - return 0; -} - diff --git a/tests/Tokens_Test.cpp b/tests/Tokens_Test.cpp index 2c5605c3065..90c939ba79f 100644 --- a/tests/Tokens_Test.cpp +++ b/tests/Tokens_Test.cpp @@ -214,11 +214,6 @@ main (int, char *[]) server_host, server_port)); ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host)); - delete A; - delete B; - delete R; - delete W; - ACE_NEW_RETURN (A, ACE_Remote_Mutex ("R Mutex A", 0, 1), -1); ACE_NEW_RETURN (B, ACE_Remote_Mutex ("R Mutex B", 0, 1), -1); ACE_NEW_RETURN (R, ACE_Remote_RLock ("R Reader Lock", 0, 1), -1); @@ -233,11 +228,6 @@ main (int, char *[]) if (new_process.kill () == -1) ACE_ERROR_RETURN ((LM_ERROR, "Kill failed.\n"), -1); - delete A; - delete B; - delete R; - delete W; - ACE_DEBUG ((LM_DEBUG, "(%t) main thread exiting.\n")); #else ACE_ERROR ((LM_ERROR, diff --git a/tests/run_tests.ksh b/tests/run_tests.ksh deleted file mode 100755 index a4d7f0d8b17..00000000000 --- a/tests/run_tests.ksh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/ksh -f - -. ./run_tests.sh - -# EOF - diff --git a/tests/test_config.h b/tests/test_config.h index cec49951d40..0608be4ca34 100644 --- a/tests/test_config.h +++ b/tests/test_config.h @@ -135,8 +135,6 @@ const int ACE_MAX_INTERVAL = 0; const int ACE_MAX_ITERATIONS = 10; const int ACE_MAX_PROCESSES = 10; -char ACE_ALPHABET[] = "abcdefghijklmnopqrstuvwxyz"; - class ACE_Test_Output { public: |