diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-03-25 00:16:16 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-03-25 00:16:16 +0000 |
commit | 35c3c290bff12300023bd0e4db86cf5a138dff19 (patch) | |
tree | 4ca0c4cf0c41504a49af7afdb3addacec2c7102d | |
parent | 80221ce0258180843506814751bfe47498d079c4 (diff) | |
download | ATCD-35c3c290bff12300023bd0e4db86cf5a138dff19.tar.gz |
*** empty log message ***
-rw-r--r-- | ChangeLog-97a | 26 | ||||
-rw-r--r-- | ace/Malloc.h | 2 | ||||
-rw-r--r-- | ace/OS.h | 22 | ||||
-rw-r--r-- | ace/SOCK_Dgram_Mcast.cpp | 6 | ||||
-rw-r--r-- | ace/SOCK_Dgram_Mcast.h | 3 | ||||
-rw-r--r-- | examples/Reactor/Multicast/Log_Wrapper.cpp | 1 | ||||
-rw-r--r-- | examples/Reactor/Multicast/Log_Wrapper.h | 21 | ||||
-rw-r--r-- | examples/Threads/context_switch_time.cpp | 342 | ||||
-rw-r--r-- | netsvcs/lib/Makefile | 2 | ||||
-rw-r--r-- | netsvcs/lib/Server_Logging_Handler.cpp | 2 | ||||
-rw-r--r-- | performance-tests/Misc/context_switch_time.cpp | 342 | ||||
-rw-r--r-- | tests/Future_Test.cpp | 9 | ||||
-rw-r--r-- | tests/IOStream_Test.cpp | 506 | ||||
-rw-r--r-- | tests/Mutex_Test.cpp | 5 |
14 files changed, 636 insertions, 653 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a index 627e511d896..d676ded4bb1 100644 --- a/ChangeLog-97a +++ b/ChangeLog-97a @@ -1,5 +1,31 @@ Mon Mar 24 14:08:48 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> + * ace/SOCK_Dgram: Removed the #if defined (ACE_HAS_IP_MULTICAST) + since this is now handled at the ACE_OS level. + + * ace/OS.h: Added support for IP multicast macros and structs even + on platforms that don't support it so that the tests will + compile without having lots of #ifdefs. + + * tests/Future_Test.cpp: Added a check for platforms that lack + threads. + + * netsvcs/lib/Server_Logging_Handler.cpp: Added a check for + platforms that lack threads. + + * examples/Threads/context_switch_time.cpp: Added an #ifdef for + ACE_HAS_THREADS to this test so that it will compile on + platforms that don't have threading. Thanks to Scott Halstead + <scott.halstead@gs.com> for reporting this. + + * tests/IOStream_Test.cpp: Fixed up this test so that it works + correctly on platforms that lack multi-threading. Thanks to + Scott Halstead <scott.halstead@gs.com> for reporting this. + + * netsvcs/lib/Makefile: Reincluded the LIB target so that we'll + build a static library. Thanks to Scott Halstead + <scott.halstead@gs.com> for reporting this. + * ace/SOCK_Dgram.cpp (recv): Added a check to make sure that we don't try to copy more into the recv buffer than we've really got. Thanks to Alan_Cabrera@fp.cibc.com for this fix. diff --git a/ace/Malloc.h b/ace/Malloc.h index f4e0c9f14e3..606cc148648 100644 --- a/ace/Malloc.h +++ b/ace/Malloc.h @@ -107,7 +107,7 @@ public: // Allow the user to override this in the config.h file. #if !defined (ACE_MALLOC_ALIGN) -#define ACE_MALLOC_ALIGN long +#define ACE_MALLOC_ALIGN sizeof (long) #endif /* ACE_MALLOC_ALIGN */ // For alignment to long boundary @@ -199,6 +199,16 @@ typedef int key_t; #include /**/ <vxWorks.h> #endif /* VXWORKS */ +#if !defined (ACE_HAS_IP_MULTICAST) +struct ip_mreq +{ + struct in_addr imr_multiaddr; + // IP multicast address of group + struct in_addr imr_interface; + // local IP address of interface +}; +#endif /* ACE_HAS_IP_MULTICAST */ + #if defined (ACE_LACKS_FILELOCKS) struct flock { @@ -2106,6 +2116,18 @@ struct sigaction #define IPC_EXCL 0 #endif /* IPC_EXCL */ +#if !defined (IP_DROP_MEMBERSHIP) +#define IP_DROP_MEMBERSHIP 0 +#endif /* IP_DROP_MEMBERSHIP */ + +#if !defined (IP_ADD_MEMBERSHIP) +#define IP_ADD_MEMBERSHIP 0 +#endif /* IP_ADD_MEMBERSHIP */ + +#if !defined (SIOCGIFADDR) +#define SIOCGIFADDR 0 +#endif /* SIOCGIFADDR */ + #if !defined (IPC_PRIVATE) #define IPC_PRIVATE ACE_INVALID_SEM_KEY #endif /* IPC_PRIVATE */ diff --git a/ace/SOCK_Dgram_Mcast.cpp b/ace/SOCK_Dgram_Mcast.cpp index 9b6630f3ef9..756d9ca5183 100644 --- a/ace/SOCK_Dgram_Mcast.cpp +++ b/ace/SOCK_Dgram_Mcast.cpp @@ -5,8 +5,6 @@ #include "ace/SOCK_Dgram_Mcast.h" #include "ace/INET_Addr.h" -#if defined (ACE_HAS_IP_MULTICAST) - ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_Dgram_Mcast) void @@ -110,7 +108,8 @@ ACE_SOCK_Dgram_Mcast::make_multicast_address (const ACE_INET_Addr &mcast_addr, if (interface_addr.set (mcast_addr.get_port_number (), net_if) == -1) return -1; - multicast_address_.imr_interface.s_addr = htonl (interface_addr.get_ip_address ()); + multicast_address_.imr_interface.s_addr = + htonl (interface_addr.get_ip_address ()); #endif /* ACE_WIN32 */ } else @@ -119,4 +118,3 @@ ACE_SOCK_Dgram_Mcast::make_multicast_address (const ACE_INET_Addr &mcast_addr, multicast_address_.imr_multiaddr.s_addr = htonl (mcast_addr.get_ip_address ()); return 0; } -#endif /* ACE_HAS_IP_MULTICAST */ diff --git a/ace/SOCK_Dgram_Mcast.h b/ace/SOCK_Dgram_Mcast.h index 586627e8a12..1493d78c348 100644 --- a/ace/SOCK_Dgram_Mcast.h +++ b/ace/SOCK_Dgram_Mcast.h @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - // ============================================================================ // // = LIBRARY @@ -22,7 +21,6 @@ #include "ace/SOCK_Dgram.h" #include "ace/INET_Addr.h" -#if defined (ACE_HAS_IP_MULTICAST) class ACE_Export ACE_SOCK_Dgram_Mcast : public ACE_SOCK_Dgram // = TITLE // Defines the member functions for the ACE_SOCK multicast abstraction. @@ -108,5 +106,4 @@ private: #include "ace/SOCK_Dgram_Mcast.i" -#endif /* ACE_HAS_IP_MULTICAST */ #endif /* ACE_SOCK_DGRAM_MCAST_H */ diff --git a/examples/Reactor/Multicast/Log_Wrapper.cpp b/examples/Reactor/Multicast/Log_Wrapper.cpp index b7306b36371..9b98aca7990 100644 --- a/examples/Reactor/Multicast/Log_Wrapper.cpp +++ b/examples/Reactor/Multicast/Log_Wrapper.cpp @@ -2,7 +2,6 @@ // client.C - #include "Log_Wrapper.h" Log_Wrapper::Log_Wrapper (void) diff --git a/examples/Reactor/Multicast/Log_Wrapper.h b/examples/Reactor/Multicast/Log_Wrapper.h index f560bb95f5f..859ed3c3ae6 100644 --- a/examples/Reactor/Multicast/Log_Wrapper.h +++ b/examples/Reactor/Multicast/Log_Wrapper.h @@ -1,18 +1,19 @@ /* -*- C++ -*- */ // $Id$ - // log_wrapper.h -// wrapper around sending log messages via multicast #include "ace/Profile_Timer.h" #include "ace/INET_Addr.h" #include "ace/SOCK_Dgram_Mcast.h" -#if !defined (_LM_WRAPPER_H) -#define _LM_WRAPPER_H +#if !defined (_LOG_WRAPPER_H) +#define _LOG_WRAPPER_H class Log_Wrapper + // = TITLE + // Provide a wrapper around sending log messages via IP + // multicast. { public: Log_Wrapper (void); @@ -21,11 +22,11 @@ public: // = Types of logging messages. enum ACE_Log_Priority { - LM_MESSAGE, - LM_DEBUG, - LM_WARNING, - LM_ERROR, - LM_EMERG + LOG_MESSAGE, + LOG_DEBUG, + LOG_WARNING, + LOG_ERROR, + LOG_EMERG }; int open (const int port, const char* mcast_addr); @@ -59,4 +60,4 @@ private: // A logger object. }; -#endif /* _LM_WRAPPER_H */ +#endif /* _LOG_WRAPPER_H */ diff --git a/examples/Threads/context_switch_time.cpp b/examples/Threads/context_switch_time.cpp index 1b7276f7298..2a57b4dbbbc 100644 --- a/examples/Threads/context_switch_time.cpp +++ b/examples/Threads/context_switch_time.cpp @@ -1,5 +1,5 @@ // $Id$ -// + // ============================================================================ // // = LIBRARY @@ -59,6 +59,8 @@ // // ============================================================================ +#if defined (ACE_HAS_THREADS) + static const char usage [] = "[-? |\n" " [-c <repeat count, 0 means forever>]\n" " [-n to spawn a new LWP with each thread\n" @@ -77,44 +79,38 @@ static const char usage [] = "[-? |\n" #endif /* DEBUG */ #if defined (__sun) -/* Solaris priority values range from low to high with increasing priority */ -static const unsigned int LOW_PRIORITY = 1; -static const unsigned int HIGH_PRIORITY = 2; +// Solaris priority values range from low to high with increasing +// priority. +static const u_int LOW_PRIORITY = 1; +static const u_int HIGH_PRIORITY = 2; #else -/* VxWorks and Win32 priority values range from high to low with - increasing priority */ -static const unsigned int LOW_PRIORITY = 2; -static const unsigned int HIGH_PRIORITY = 1; -#endif - - -// global test configuration parameters -static unsigned long count = 1; -static unsigned long num_iterations = 1000; -static unsigned int new_lwp = 0; - +// VxWorks and Win32 priority values range from high to low with +// increasing priority. +static const u_int LOW_PRIORITY = 2; +static const u_int HIGH_PRIORITY = 1; +#endif -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Low_Priority_Null_Task -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// +// global test configuration parameters. +static u_long count = 1; +static u_long num_iterations = 1000; +static u_int new_lwp = 0; class Low_Priority_Null_Task : public ACE_Task<ACE_MT_SYNCH> { public: - Low_Priority_Null_Task (); - virtual ~Low_Priority_Null_Task (); + Low_Priority_Null_Task (void); + virtual ~Low_Priority_Null_Task (void); - virtual int svc (); + virtual int svc (void); // called by other task: it returns when this task is ready to // continue - void ready () { initialized_.acquire (); } + void ready (void) { initialized_.acquire (); } - void done (); + void done (void); + + ACE_hthread_t thread_id (void) const { return thread_id_; } - ACE_hthread_t thread_id () const { return thread_id_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // blocks until thread_id_ is assigned @@ -126,10 +122,10 @@ private: }; inline -Low_Priority_Null_Task::Low_Priority_Null_Task() : - ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), - initialized_ (0), // initialize to locked, then unlock when ready - blocked_semaphore_ (0) +Low_Priority_Null_Task::Low_Priority_Null_Task (void) + : ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), + initialized_ (0), // initialize to locked, then unlock when ready + blocked_semaphore_ (0) { #if DEBUG > 0 cout << "Low_Priority_Null_Task ctor" << endl; @@ -142,12 +138,12 @@ Low_Priority_Null_Task::Low_Priority_Null_Task() : #endif /* DEBUG */ } -Low_Priority_Null_Task::~Low_Priority_Null_Task() +Low_Priority_Null_Task::~Low_Priority_Null_Task (void) { } int -Low_Priority_Null_Task::svc () +Low_Priority_Null_Task::svc (void) { #if DEBUG > 0 cout << "Low_Priority_Null_Task::svc (), entering" << ::flush; @@ -172,29 +168,22 @@ Low_Priority_Null_Task::svc () } void -Low_Priority_Null_Task::done () +Low_Priority_Null_Task::done (void) { blocked_semaphore_.release (); } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Suspend_Resume_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Suspend_Resume_Test (const unsigned long iterations); - virtual ~Suspend_Resume_Test (); + Suspend_Resume_Test (const u_long iterations); + virtual ~Suspend_Resume_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; Low_Priority_Null_Task low_; @@ -203,16 +192,13 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Suspend_Resume_Test (); + Suspend_Resume_Test (void); Suspend_Resume_Test (const Suspend_Resume_Test &); Suspend_Resume_Test &operator= (const Suspend_Resume_Test &); }; -Suspend_Resume_Test::Suspend_Resume_Test (const unsigned long iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - low_ (), - timer_ () +Suspend_Resume_Test::Suspend_Resume_Test (const u_long iterations) + : iterations_ (iterations) { #if DEBUG > 0 cout << "Suspend_Resume_Test ctor" << endl; @@ -221,12 +207,12 @@ Suspend_Resume_Test::Suspend_Resume_Test (const unsigned long iterations) : this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, HIGH_PRIORITY); } -Suspend_Resume_Test::~Suspend_Resume_Test() +Suspend_Resume_Test::~Suspend_Resume_Test (void) { } int -Suspend_Resume_Test::svc () +Suspend_Resume_Test::svc (void) { #if DEBUG > 0 ACE_hthread_t thread_id; @@ -243,7 +229,7 @@ Suspend_Resume_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -269,34 +255,27 @@ Suspend_Resume_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class High_Priority_Simple_Task -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class High_Priority_Simple_Task : public ACE_Task<ACE_MT_SYNCH> { public: - High_Priority_Simple_Task (); - virtual ~High_Priority_Simple_Task (); + High_Priority_Simple_Task (void); + virtual ~High_Priority_Simple_Task (void); - virtual int svc (); + virtual int svc (void); // called by other task: it returns when this task is ready to // continue - void ready () { initialized_.acquire (); } + void ready (void) { initialized_.acquire (); } - void done (); + void done (void); - ACE_hthread_t thread_id () const { return thread_id_; } - unsigned long iterations () const { return iterations_; } + ACE_hthread_t thread_id (void) const { return thread_id_; } + u_long iterations (void) const { return iterations_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // block until thread_id_ is assigned int terminate_; - unsigned long iterations_; + u_long iterations_; // force proper construction of independent instances High_Priority_Simple_Task (const High_Priority_Simple_Task &); @@ -304,11 +283,10 @@ private: }; inline -High_Priority_Simple_Task::High_Priority_Simple_Task() : - ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), - initialized_ (0), // initialize to locked, then unlock when ready - terminate_ (0), - iterations_ (0) +High_Priority_Simple_Task::High_Priority_Simple_Task (void) + : initialized_ (0), // initialize to locked, then unlock when ready + terminate_ (0), + iterations_ (0) { #if DEBUG > 0 cout << "High_Priority_Simple_Task ctor" << endl; @@ -321,12 +299,12 @@ High_Priority_Simple_Task::High_Priority_Simple_Task() : #endif /* DEBUG */ } -High_Priority_Simple_Task::~High_Priority_Simple_Task() +High_Priority_Simple_Task::~High_Priority_Simple_Task (void) { } int -High_Priority_Simple_Task::svc () +High_Priority_Simple_Task::svc (void) { #if DEBUG > 0 cout << "High_Priority_Simple_Task::svc (), entering" << ::flush; @@ -364,31 +342,23 @@ High_Priority_Simple_Task::svc () return 0; } -inline -void -High_Priority_Simple_Task::done () +inline void +High_Priority_Simple_Task::done (void) { terminate_ = 1; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Ping_Suspend_Resume_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Ping_Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Ping_Suspend_Resume_Test (const unsigned long iterations); - virtual ~Ping_Suspend_Resume_Test (); + Ping_Suspend_Resume_Test (const u_long iterations); + virtual ~Ping_Suspend_Resume_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; High_Priority_Simple_Task high_; @@ -397,17 +367,16 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Ping_Suspend_Resume_Test (); + Ping_Suspend_Resume_Test (void); Ping_Suspend_Resume_Test (const Ping_Suspend_Resume_Test &); Ping_Suspend_Resume_Test &operator= (const Ping_Suspend_Resume_Test &); }; -Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const unsigned long - iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - high_ (), - timer_ () +Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const u_long + iterations) + : iterations_ (iterations), + high_ (), + timer_ () { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test ctor" << endl; @@ -416,12 +385,12 @@ Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const unsigned long this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, LOW_PRIORITY); } -Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test() +Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test (void) { } int -Ping_Suspend_Resume_Test::svc () +Ping_Suspend_Resume_Test::svc (void) { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test::svc (), entering" << ::flush; @@ -449,7 +418,7 @@ Ping_Suspend_Resume_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -491,39 +460,30 @@ Ping_Suspend_Resume_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Yield_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Yield_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Yield_Test (const unsigned long iterations); - virtual ~Yield_Test (); + Yield_Test (const u_long iterations); + virtual ~Yield_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; ACE_High_Res_Timer timer_; ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Yield_Test (); + Yield_Test (void); Yield_Test (const Yield_Test &); Yield_Test &operator= (const Yield_Test &); }; -Yield_Test::Yield_Test (const unsigned long iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - timer_ () +Yield_Test::Yield_Test (const u_long iterations) + : iterations_ (iterations) { #if DEBUG > 0 cout << "Yield_Test ctor" << endl; @@ -532,12 +492,12 @@ Yield_Test::Yield_Test (const unsigned long iterations) : this->activate (THR_BOUND | THR_DETACHED | new_lwp, 2, 0, LOW_PRIORITY); } -Yield_Test::~Yield_Test() +Yield_Test::~Yield_Test (void) { } int -Yield_Test::svc () +Yield_Test::svc (void) { #if DEBUG > 0 cout << "Yield_Test::svc (), entering" << ::flush; @@ -554,7 +514,7 @@ Yield_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -576,85 +536,71 @@ Yield_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// function get_options -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -static -unsigned int -get_options (int argc, char *argv []) +static u_int +parse_args (int argc, char *argv []) { ACE_Get_Opt get_opt (argc, argv, "c:n?"); int opt; - while ((opt = get_opt ()) != EOF) { - switch (opt) { - case 'c': - if (ACE_OS::atoi (get_opt.optarg) >= 0) - { - count = ACE_OS::atoi (get_opt.optarg); - } - else - { - cerr << argv [0] << ": count must be >= 0" << endl; - return 1; - } - break; - case 'n': - new_lwp = THR_NEW_LWP; + + while ((opt = get_opt ()) != EOF) + { + switch (opt) + { + case 'c': + if (ACE_OS::atoi (get_opt.optarg) >= 0) + count = ACE_OS::atoi (get_opt.optarg); + else + { + cerr << argv [0] << ": count must be >= 0" << endl; + return 1; + } + break; + case 'n': + new_lwp = THR_NEW_LWP; + break; + case '?': + cout << "usage: " << argv [0] << " " << usage << endl; + ACE_OS::exit (0); + break; + default: + cerr << argv [0] << ": unknown arg, " << (char) opt << endl; + cerr << "usage: " << argv [0] << " " << usage << endl; + return 1; + } + } + + switch (argc - get_opt.optind) + { + case 0: + // use default number of iterations break; - case '?': - cout << "usage: " << argv [0] << " " << usage << endl; - ACE_OS::exit (0); + case 1: + if (ACE_OS::atoi (argv [get_opt.optind]) > 0) + num_iterations = ACE_OS::atoi (argv [get_opt.optind]); + else + { + cerr << argv [0] << ": iterations must be > 0" << endl; + return 1; + } break; default: - cerr << argv [0] << ": unknown arg, " << (char) opt << endl; + cerr << argv [0] << ": too many arguments" << endl; cerr << "usage: " << argv [0] << " " << usage << endl; return 1; } - } - - switch (argc - get_opt.optind) { - case 0: - // use default number of iterations - break; - case 1: - if (ACE_OS::atoi (argv [get_opt.optind]) > 0) - { - num_iterations = ACE_OS::atoi (argv [get_opt.optind]); - } - else - { - cerr << argv [0] << ": iterations must be > 0" << endl; - return 1; - } - break; - default: - cerr << argv [0] << ": too many arguments" << endl; - cerr << "usage: " << argv [0] << " " << usage << endl; - return 1; - } return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// function main -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv []) { if (ACE_High_Res_Timer::supported () == 0) - { - ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " - "by ACE on this platform.\n", argv[0]); - } + ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " + "by ACE on this platform.\n", argv[0]); - if (get_options (argc, argv)) ACE_OS::exit (-1); + if (parse_args (argc, argv)) + ACE_OS::exit (-1); if (ACE_OS::sched_params ( ACE_Sched_Params ( @@ -663,10 +609,8 @@ main (int argc, char *argv []) ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) - { - ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " - "time-sharing class\n", argv[0]); - } + ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " + "time-sharing class\n", argv[0]); else { ACE_OS::perror (argv[0]); @@ -676,20 +620,22 @@ main (int argc, char *argv []) int forever = count == 0; - while (forever || count-- > 0) + while (forever || count-- > 0) { - // run suspend/resume test first . . . + // Run suspend/resume test first . . . Suspend_Resume_Test suspend_resume_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); - // then Ping Suspend/Resume test + // Then Ping Suspend/Resume test. Ping_Suspend_Resume_Test ping_suspend_resume_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); if (ping_suspend_resume_test.elapsed_time () > - suspend_resume_test.elapsed_time ()) + suspend_resume_test.elapsed_time ()) { cout << "context switch time is (" << setw (9) @@ -715,8 +661,9 @@ main (int argc, char *argv []) << endl; } - // then Yield test + // Then Yield test. Yield_Test yield_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); @@ -725,9 +672,14 @@ main (int argc, char *argv []) << " microseconds" << endl; } - return 0; } +#else +int +main (int, char *[]) +{ + ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); + return 0; +} +#endif /* ACE_HAS_THREADS */ - -// EOF diff --git a/netsvcs/lib/Makefile b/netsvcs/lib/Makefile index 3b3c2822cb1..ec3b51a3383 100644 --- a/netsvcs/lib/Makefile +++ b/netsvcs/lib/Makefile @@ -4,7 +4,7 @@ # Makefile for the server-side ACE network services #---------------------------------------------------------------------------- -#LIB = libnetsvcs.a +LIB = libnetsvcs.a SHLIB = libnetsvcs.$(SOEXT) FILES = TS_Server_Handler \ diff --git a/netsvcs/lib/Server_Logging_Handler.cpp b/netsvcs/lib/Server_Logging_Handler.cpp index 2160d8cd093..3d15aec685f 100644 --- a/netsvcs/lib/Server_Logging_Handler.cpp +++ b/netsvcs/lib/Server_Logging_Handler.cpp @@ -446,5 +446,7 @@ template class ACE_Server_Logging_Handler<ACE_TLI_Stream, ACE_INET_Addr, unsigne template class ACE_Strategy_Acceptor<ACE_Server_Logging_Handler<LOGGING_PEER_STREAM, u_long, ACE_NULL_SYNCH>, LOGGING_PEER_ACCEPTOR>; template class ACE_Strategy_Acceptor<ACE_Thr_Server_Logging_Handler, LOGGING_PEER_ACCEPTOR>; template class ACE_Svc_Handler<ACE_TLI_Stream, ACE_INET_Addr, ACE_Null_Mutex, ACE_Null_Condition_Mutex>; +#if defined (ACE_HAS_THREADS) template class ACE_Svc_Handler<ACE_TLI_Stream, ACE_INET_Addr, ACE_Thread_Mutex, ACE_Condition_Thread_Mutex>; +#endif /* ACE_HAS_THREADS */ #endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ diff --git a/performance-tests/Misc/context_switch_time.cpp b/performance-tests/Misc/context_switch_time.cpp index 1b7276f7298..2a57b4dbbbc 100644 --- a/performance-tests/Misc/context_switch_time.cpp +++ b/performance-tests/Misc/context_switch_time.cpp @@ -1,5 +1,5 @@ // $Id$ -// + // ============================================================================ // // = LIBRARY @@ -59,6 +59,8 @@ // // ============================================================================ +#if defined (ACE_HAS_THREADS) + static const char usage [] = "[-? |\n" " [-c <repeat count, 0 means forever>]\n" " [-n to spawn a new LWP with each thread\n" @@ -77,44 +79,38 @@ static const char usage [] = "[-? |\n" #endif /* DEBUG */ #if defined (__sun) -/* Solaris priority values range from low to high with increasing priority */ -static const unsigned int LOW_PRIORITY = 1; -static const unsigned int HIGH_PRIORITY = 2; +// Solaris priority values range from low to high with increasing +// priority. +static const u_int LOW_PRIORITY = 1; +static const u_int HIGH_PRIORITY = 2; #else -/* VxWorks and Win32 priority values range from high to low with - increasing priority */ -static const unsigned int LOW_PRIORITY = 2; -static const unsigned int HIGH_PRIORITY = 1; -#endif - - -// global test configuration parameters -static unsigned long count = 1; -static unsigned long num_iterations = 1000; -static unsigned int new_lwp = 0; - +// VxWorks and Win32 priority values range from high to low with +// increasing priority. +static const u_int LOW_PRIORITY = 2; +static const u_int HIGH_PRIORITY = 1; +#endif -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Low_Priority_Null_Task -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// +// global test configuration parameters. +static u_long count = 1; +static u_long num_iterations = 1000; +static u_int new_lwp = 0; class Low_Priority_Null_Task : public ACE_Task<ACE_MT_SYNCH> { public: - Low_Priority_Null_Task (); - virtual ~Low_Priority_Null_Task (); + Low_Priority_Null_Task (void); + virtual ~Low_Priority_Null_Task (void); - virtual int svc (); + virtual int svc (void); // called by other task: it returns when this task is ready to // continue - void ready () { initialized_.acquire (); } + void ready (void) { initialized_.acquire (); } - void done (); + void done (void); + + ACE_hthread_t thread_id (void) const { return thread_id_; } - ACE_hthread_t thread_id () const { return thread_id_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // blocks until thread_id_ is assigned @@ -126,10 +122,10 @@ private: }; inline -Low_Priority_Null_Task::Low_Priority_Null_Task() : - ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), - initialized_ (0), // initialize to locked, then unlock when ready - blocked_semaphore_ (0) +Low_Priority_Null_Task::Low_Priority_Null_Task (void) + : ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), + initialized_ (0), // initialize to locked, then unlock when ready + blocked_semaphore_ (0) { #if DEBUG > 0 cout << "Low_Priority_Null_Task ctor" << endl; @@ -142,12 +138,12 @@ Low_Priority_Null_Task::Low_Priority_Null_Task() : #endif /* DEBUG */ } -Low_Priority_Null_Task::~Low_Priority_Null_Task() +Low_Priority_Null_Task::~Low_Priority_Null_Task (void) { } int -Low_Priority_Null_Task::svc () +Low_Priority_Null_Task::svc (void) { #if DEBUG > 0 cout << "Low_Priority_Null_Task::svc (), entering" << ::flush; @@ -172,29 +168,22 @@ Low_Priority_Null_Task::svc () } void -Low_Priority_Null_Task::done () +Low_Priority_Null_Task::done (void) { blocked_semaphore_.release (); } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Suspend_Resume_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Suspend_Resume_Test (const unsigned long iterations); - virtual ~Suspend_Resume_Test (); + Suspend_Resume_Test (const u_long iterations); + virtual ~Suspend_Resume_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; Low_Priority_Null_Task low_; @@ -203,16 +192,13 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Suspend_Resume_Test (); + Suspend_Resume_Test (void); Suspend_Resume_Test (const Suspend_Resume_Test &); Suspend_Resume_Test &operator= (const Suspend_Resume_Test &); }; -Suspend_Resume_Test::Suspend_Resume_Test (const unsigned long iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - low_ (), - timer_ () +Suspend_Resume_Test::Suspend_Resume_Test (const u_long iterations) + : iterations_ (iterations) { #if DEBUG > 0 cout << "Suspend_Resume_Test ctor" << endl; @@ -221,12 +207,12 @@ Suspend_Resume_Test::Suspend_Resume_Test (const unsigned long iterations) : this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, HIGH_PRIORITY); } -Suspend_Resume_Test::~Suspend_Resume_Test() +Suspend_Resume_Test::~Suspend_Resume_Test (void) { } int -Suspend_Resume_Test::svc () +Suspend_Resume_Test::svc (void) { #if DEBUG > 0 ACE_hthread_t thread_id; @@ -243,7 +229,7 @@ Suspend_Resume_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -269,34 +255,27 @@ Suspend_Resume_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class High_Priority_Simple_Task -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class High_Priority_Simple_Task : public ACE_Task<ACE_MT_SYNCH> { public: - High_Priority_Simple_Task (); - virtual ~High_Priority_Simple_Task (); + High_Priority_Simple_Task (void); + virtual ~High_Priority_Simple_Task (void); - virtual int svc (); + virtual int svc (void); // called by other task: it returns when this task is ready to // continue - void ready () { initialized_.acquire (); } + void ready (void) { initialized_.acquire (); } - void done (); + void done (void); - ACE_hthread_t thread_id () const { return thread_id_; } - unsigned long iterations () const { return iterations_; } + ACE_hthread_t thread_id (void) const { return thread_id_; } + u_long iterations (void) const { return iterations_; } private: ACE_hthread_t thread_id_; ACE_Semaphore initialized_; // block until thread_id_ is assigned int terminate_; - unsigned long iterations_; + u_long iterations_; // force proper construction of independent instances High_Priority_Simple_Task (const High_Priority_Simple_Task &); @@ -304,11 +283,10 @@ private: }; inline -High_Priority_Simple_Task::High_Priority_Simple_Task() : - ACE_Task<ACE_MT_SYNCH> (ACE_Service_Config::thr_mgr ()), - initialized_ (0), // initialize to locked, then unlock when ready - terminate_ (0), - iterations_ (0) +High_Priority_Simple_Task::High_Priority_Simple_Task (void) + : initialized_ (0), // initialize to locked, then unlock when ready + terminate_ (0), + iterations_ (0) { #if DEBUG > 0 cout << "High_Priority_Simple_Task ctor" << endl; @@ -321,12 +299,12 @@ High_Priority_Simple_Task::High_Priority_Simple_Task() : #endif /* DEBUG */ } -High_Priority_Simple_Task::~High_Priority_Simple_Task() +High_Priority_Simple_Task::~High_Priority_Simple_Task (void) { } int -High_Priority_Simple_Task::svc () +High_Priority_Simple_Task::svc (void) { #if DEBUG > 0 cout << "High_Priority_Simple_Task::svc (), entering" << ::flush; @@ -364,31 +342,23 @@ High_Priority_Simple_Task::svc () return 0; } -inline -void -High_Priority_Simple_Task::done () +inline void +High_Priority_Simple_Task::done (void) { terminate_ = 1; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Ping_Suspend_Resume_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Ping_Suspend_Resume_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Ping_Suspend_Resume_Test (const unsigned long iterations); - virtual ~Ping_Suspend_Resume_Test (); + Ping_Suspend_Resume_Test (const u_long iterations); + virtual ~Ping_Suspend_Resume_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; High_Priority_Simple_Task high_; @@ -397,17 +367,16 @@ private: ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Ping_Suspend_Resume_Test (); + Ping_Suspend_Resume_Test (void); Ping_Suspend_Resume_Test (const Ping_Suspend_Resume_Test &); Ping_Suspend_Resume_Test &operator= (const Ping_Suspend_Resume_Test &); }; -Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const unsigned long - iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - high_ (), - timer_ () +Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const u_long + iterations) + : iterations_ (iterations), + high_ (), + timer_ () { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test ctor" << endl; @@ -416,12 +385,12 @@ Ping_Suspend_Resume_Test::Ping_Suspend_Resume_Test (const unsigned long this->activate (THR_BOUND | THR_DETACHED | new_lwp, 1, 0, LOW_PRIORITY); } -Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test() +Ping_Suspend_Resume_Test::~Ping_Suspend_Resume_Test (void) { } int -Ping_Suspend_Resume_Test::svc () +Ping_Suspend_Resume_Test::svc (void) { #if DEBUG > 0 cout << "Ping_Suspend_Resume_Test::svc (), entering" << ::flush; @@ -449,7 +418,7 @@ Ping_Suspend_Resume_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -491,39 +460,30 @@ Ping_Suspend_Resume_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// class Yield_Test -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - class Yield_Test : public ACE_Task<ACE_MT_SYNCH> { public: - Yield_Test (const unsigned long iterations); - virtual ~Yield_Test (); + Yield_Test (const u_long iterations); + virtual ~Yield_Test (void); - virtual int svc (); + virtual int svc (void); - ACE_hrtime_t elapsed_time () const { return elapsed_time_; } + ACE_hrtime_t elapsed_time (void) const { return elapsed_time_; } private: - const unsigned long iterations_; + const u_long iterations_; ACE_High_Res_Timer timer_; ACE_hrtime_t elapsed_time_; // force proper construction of independent instances - Yield_Test (); + Yield_Test (void); Yield_Test (const Yield_Test &); Yield_Test &operator= (const Yield_Test &); }; -Yield_Test::Yield_Test (const unsigned long iterations) : - ACE_Task<ACE_MT_SYNCH> (), - iterations_ (iterations), - timer_ () +Yield_Test::Yield_Test (const u_long iterations) + : iterations_ (iterations) { #if DEBUG > 0 cout << "Yield_Test ctor" << endl; @@ -532,12 +492,12 @@ Yield_Test::Yield_Test (const unsigned long iterations) : this->activate (THR_BOUND | THR_DETACHED | new_lwp, 2, 0, LOW_PRIORITY); } -Yield_Test::~Yield_Test() +Yield_Test::~Yield_Test (void) { } int -Yield_Test::svc () +Yield_Test::svc (void) { #if DEBUG > 0 cout << "Yield_Test::svc (), entering" << ::flush; @@ -554,7 +514,7 @@ Yield_Test::svc () timer_.start (); - for (unsigned long i = 0; i < iterations_; ++i) + for (u_long i = 0; i < iterations_; ++i) { #if DEBUG > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) @@ -576,85 +536,71 @@ Yield_Test::svc () return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// function get_options -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -static -unsigned int -get_options (int argc, char *argv []) +static u_int +parse_args (int argc, char *argv []) { ACE_Get_Opt get_opt (argc, argv, "c:n?"); int opt; - while ((opt = get_opt ()) != EOF) { - switch (opt) { - case 'c': - if (ACE_OS::atoi (get_opt.optarg) >= 0) - { - count = ACE_OS::atoi (get_opt.optarg); - } - else - { - cerr << argv [0] << ": count must be >= 0" << endl; - return 1; - } - break; - case 'n': - new_lwp = THR_NEW_LWP; + + while ((opt = get_opt ()) != EOF) + { + switch (opt) + { + case 'c': + if (ACE_OS::atoi (get_opt.optarg) >= 0) + count = ACE_OS::atoi (get_opt.optarg); + else + { + cerr << argv [0] << ": count must be >= 0" << endl; + return 1; + } + break; + case 'n': + new_lwp = THR_NEW_LWP; + break; + case '?': + cout << "usage: " << argv [0] << " " << usage << endl; + ACE_OS::exit (0); + break; + default: + cerr << argv [0] << ": unknown arg, " << (char) opt << endl; + cerr << "usage: " << argv [0] << " " << usage << endl; + return 1; + } + } + + switch (argc - get_opt.optind) + { + case 0: + // use default number of iterations break; - case '?': - cout << "usage: " << argv [0] << " " << usage << endl; - ACE_OS::exit (0); + case 1: + if (ACE_OS::atoi (argv [get_opt.optind]) > 0) + num_iterations = ACE_OS::atoi (argv [get_opt.optind]); + else + { + cerr << argv [0] << ": iterations must be > 0" << endl; + return 1; + } break; default: - cerr << argv [0] << ": unknown arg, " << (char) opt << endl; + cerr << argv [0] << ": too many arguments" << endl; cerr << "usage: " << argv [0] << " " << usage << endl; return 1; } - } - - switch (argc - get_opt.optind) { - case 0: - // use default number of iterations - break; - case 1: - if (ACE_OS::atoi (argv [get_opt.optind]) > 0) - { - num_iterations = ACE_OS::atoi (argv [get_opt.optind]); - } - else - { - cerr << argv [0] << ": iterations must be > 0" << endl; - return 1; - } - break; - default: - cerr << argv [0] << ": too many arguments" << endl; - cerr << "usage: " << argv [0] << " " << usage << endl; - return 1; - } return 0; } - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// function main -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv []) { if (ACE_High_Res_Timer::supported () == 0) - { - ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " - "by ACE on this platform.\n", argv[0]); - } + ACE_OS::fprintf (stderr, "%s: high-resolution time is not supported " + "by ACE on this platform.\n", argv[0]); - if (get_options (argc, argv)) ACE_OS::exit (-1); + if (parse_args (argc, argv)) + ACE_OS::exit (-1); if (ACE_OS::sched_params ( ACE_Sched_Params ( @@ -663,10 +609,8 @@ main (int argc, char *argv []) ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) - { - ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " - "time-sharing class\n", argv[0]); - } + ACE_OS::fprintf (stderr, "%s: user is not superuser, so remain in " + "time-sharing class\n", argv[0]); else { ACE_OS::perror (argv[0]); @@ -676,20 +620,22 @@ main (int argc, char *argv []) int forever = count == 0; - while (forever || count-- > 0) + while (forever || count-- > 0) { - // run suspend/resume test first . . . + // Run suspend/resume test first . . . Suspend_Resume_Test suspend_resume_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); - // then Ping Suspend/Resume test + // Then Ping Suspend/Resume test. Ping_Suspend_Resume_Test ping_suspend_resume_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); if (ping_suspend_resume_test.elapsed_time () > - suspend_resume_test.elapsed_time ()) + suspend_resume_test.elapsed_time ()) { cout << "context switch time is (" << setw (9) @@ -715,8 +661,9 @@ main (int argc, char *argv []) << endl; } - // then Yield test + // Then Yield test. Yield_Test yield_test (num_iterations); + // Wait for all tasks to exit. ACE_Service_Config::thr_mgr ()->wait (); @@ -725,9 +672,14 @@ main (int argc, char *argv []) << " microseconds" << endl; } - return 0; } +#else +int +main (int, char *[]) +{ + ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n")); + return 0; +} +#endif /* ACE_HAS_THREADS */ - -// EOF diff --git a/tests/Future_Test.cpp b/tests/Future_Test.cpp index cfd48fc5a7e..9336a6e10f8 100644 --- a/tests/Future_Test.cpp +++ b/tests/Future_Test.cpp @@ -286,6 +286,9 @@ static int n_loops = 100; #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) template class ACE_Future<const char *>; template class ACE_Future<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 */ @@ -400,9 +403,3 @@ main (int, char *[]) ACE_END_TEST; return 0; } - -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) -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 */ diff --git a/tests/IOStream_Test.cpp b/tests/IOStream_Test.cpp index ffc9a0a3e9a..8f4dbb59d8f 100644 --- a/tests/IOStream_Test.cpp +++ b/tests/IOStream_Test.cpp @@ -17,7 +17,6 @@ // // ============================================================================ - #include "ace/Thread.h" #include "ace/Acceptor.h" #include "ace/SOCK_Connector.h" @@ -28,9 +27,9 @@ typedef ACE_IOStream<ACE_SOCK_Stream> ACE_SOCK_IOStream; -short PORT = ACE_DEFAULT_SERVER_PORT; -u_long error_at_server = 0; -u_long error_at_client = 0; +static short PORT = ACE_DEFAULT_SERVER_PORT; +static u_long error_at_server = 0; +static u_long error_at_client = 0; /* The biggest drawback to an iostream is that it generally eats up whitespace when performing a get (>>) operation. @@ -64,275 +63,312 @@ u_long error_at_client = 0; then a float then a double. */ -/* Since I can't rely on GNU's String class being everywhere - (yet), here's a simple class that will work with quoted - strings. Use at your own risk! It is very incomplete! - */ +// Since I can't rely on GNU's String class being everywhere (yet), +// here's a simple class that will work with quoted strings. Use at +// your own risk! It is very incomplete! + class qchar { -private: - char c_; public: - qchar() { c_ = '\0'; } + qchar (void) { c_ = '\0'; } - qchar(char c) : c_(c) { }; + qchar (char c) : c_(c) { }; - operator char () const { return(c_); } + operator char () const { return c_; } - qchar operator=(char c) { return(c_ = c); } + qchar operator= (char c) { return c_ = c; } - int operator==(char c) { return(c_ == c); } + int operator== (char c) { return c_ == c; } - friend ACE_SOCK_IOStream & operator>>(ACE_SOCK_IOStream & stream, qchar * buf); - friend ACE_SOCK_IOStream & operator<<(ACE_SOCK_IOStream & stream, qchar * buf); - friend ostream & operator<<(ostream & stream, qchar * buf); -}; + friend ACE_SOCK_IOStream &operator>> (ACE_SOCK_IOStream & stream, qchar * buf); + friend ACE_SOCK_IOStream &operator<< (ACE_SOCK_IOStream & stream, qchar * buf); + friend ostream &operator<< (ostream & stream, qchar * buf); -/* This is taken almost directly from the QuotedString object that - has been derived from GNU's String class. The advantage to - using QuotedString is that it is MUCH more robust than qchar - will every be. - */ -ACE_SOCK_IOStream & operator>>(ACE_SOCK_IOStream & stream, qchar * buf) -{ - char c; - - *buf = '\0'; // Initialize the string +private: + char c_; +}; - if( !(stream >> c) ) // eat space up to the first char - { - return stream; - } +// This is taken almost directly from the QuotedString object that has +// been derived from GNU's String class. The advantage to using +// QuotedString is that it is MUCH more robust than qchar will every +// be. - // if we don't have a quote, append until we see space - if (c != '"') - { - for( *buf++ = c ; stream.get(c) && !isspace(c) ; *buf++ = c ); - } - else +ACE_SOCK_IOStream & +operator>> (ACE_SOCK_IOStream & stream, qchar *buf) +{ + char c; + + *buf = '\0'; // Initialize the string + + if (!(stream >> c)) // eat space up to the first char + return stream; + + // if we don't have a quote, append until we see space + if (c != '"') + for (*buf++ = c; + stream.get(c) && !isspace(c); + *buf++ = c) + continue; + else + for (; stream.get(c) && c != '"'; *buf++ = c) + if (c == '\\') { - for( ; stream.get(c) && c != '"' ; *buf++ = c ) - { - if (c == '\\') - { - stream.get(c); - if (c != '"') - *buf++ = '\\'; - } - } + stream.get(c); + if (c != '"') + *buf++ = '\\'; } - *buf = '\0'; + *buf = '\0'; - return stream; + return stream; } -ACE_SOCK_IOStream & operator<<(ACE_SOCK_IOStream & stream, qchar * buf) +ACE_SOCK_IOStream & +operator<< (ACE_SOCK_IOStream &stream, qchar *buf) { - stream.put('"'); - while( *buf ) - { - if( *buf == '"' ) - stream.put('\\'); - stream.put((char)*buf++); - } - stream.put('"'); + stream.put ('"'); + while (*buf) + if (*buf == '"') + stream.put ('\\'); - return stream; + stream.put ((char) *buf++); + stream.put ('"'); + + return stream; } -ostream & operator<<(ostream & stream, qchar * buf) +ostream & +operator<< (ostream &stream, qchar *buf) { - while( *buf ) - stream.put((char)*buf++); + while (*buf) + stream.put ((char) *buf++); - return stream; + return stream; } -/* Our client thread will initiate the test by sending some data - to the server. - */ -static void *client_thread(void * _thr_mgr) -{ - ACE_NEW_THREAD; +// Our client thread will initiate the test by sending some data to +// the server. - ACE_Thread_Manager * thr_mgr = (ACE_Thread_Manager *)_thr_mgr; - ACE_Thread_Control thread_control (thr_mgr); +static void * +client (void *arg) +{ + ACE_NEW_THREAD; + +#if defined (ACE_HAS_THREADS) + ACE_Thread_Control thread_control (ACE_Service_Config::thr_mgr ()); +#endif /* ACE_HAS_THREADS */ + + ACE_SOCK_IOStream server; + ACE_INET_Addr addr (PORT, ACE_DEFAULT_SERVER_HOST); + ACE_SOCK_Connector connector; + + if (connector.connect (server, addr) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "Failed to connect to server thread"), -1); + + // Send a string to the server which it can interpret as a qchar[] + char *str = "\"This is a test string.\""; + ACE_DEBUG ((LM_DEBUG, "Client Sending: (%s)\n", str)); + server << str << endl; + + // Allow the server to get the string and echo it to the user. (The + // iostream doesn't need this, but humans do :) + ACE_OS::sleep (2); + + // Send another string but this time the server will read it as a + // char[]. Notice how the server's output doesn't include all of + // the spaces sent by the client. + + str = "\"THIS IS A TEST STRING.\""; + ACE_DEBUG ((LM_DEBUG, "Client Sending: (%s)\n", str)); + server << str << endl; + + // Again, give the server time to display the happenings to the + // user. + ACE_OS::sleep (2); + + // Read from the server an int, float, long, float double. The + // iostream will pull them out by using the whitespace provided by + // the server. + + int i; + float f1, f2; + long l; + double d; + server >> i >> f1 >> l >> f2 >> d; + + ACE_DEBUG ((LM_DEBUG, + "Client Received: int %d float %f long %d float %f double %f\n", + i, f1, (int) l, f2, d)); + + // Check for proper received values. + if (i != 1 || (f1 < 0.123420 || f1 > 0.123422) + || l != 666555444 || (f2 < 23.44 || f2 > 23.46) + || (d < -47.1e+9 || d > -45.9e+9)) + { + ACE_DEBUG ((LM_ERROR, "incorrect value received, should be:\n" + "int 1 float 0.123421 long 666555444 float 23.450001 " + "double -46500000000.00000\n")); + ++error_at_client; + } + + // Reset the precision to limit ourselves to two significant digits. + server.precision (2); + + // Now, make a little change & send 'em back. + i *= -1; server << i << " "; + f1 *= -1; server << f1 << " "; + l *= -1; server << l << " "; + f2 *= -1; server << f2 << " "; + d *= -1; server << d << " "; + server << endl; + + // Shut down the test. + server.close(); + + return 0; +} - ACE_SOCK_IOStream server; - ACE_INET_Addr addr(PORT,ACE_DEFAULT_SERVER_HOST); - ACE_SOCK_Connector connector; +// Test the server's ability to receive data from the client and then +// begin a two-way conversation. - if( connector.connect(server,addr) < 0 ) - { - ACE_DEBUG ((LM_ERROR, "Failed to connect to server thread")); - return (void *) -1; - } - - // Send a string to the server which it can interpret as a qchar[] - char * str = "\"This is a test string.\""; - ACE_DEBUG ((LM_DEBUG, "Client Sending: (%s)\n", str)); - server << str << endl; - - // Allow the server to get the string and echo it to the user. - // (The iostream doesn't need this, but humans do :) - // - ACE_OS::sleep(2); - - // Send another string but this time the server will read it - // as a char[]. Notice how the server's output doesn't include - // all of the spaces sent by the client. - // - str = "\"THIS IS A TEST STRING.\""; - ACE_DEBUG ((LM_DEBUG, "Client Sending: (%s)\n", str)); - server << str << endl; - - // Again, give the server time to display the happenings to the user. - ACE_OS::sleep(2); - - // Read from the server an int, float, long, float double. - // The iostream will pull them out by using the whitespace - // provided by the server. - // - int i; - float f1, f2; - long l; - double d; - server >> i >> f1 >> l >> f2 >> d; - - ACE_DEBUG ((LM_DEBUG, "Client Received: int %d float %f long %d float %f double %f\n", i, f1, (int) l, f2, d)); - - // check for proper received values - if (i != 1 || (f1 < 0.123420 || f1 > 0.123422) || - l != 666555444 || (f2 < 23.44 || f2 > 23.46) || - (d < -47.1e+9 || d > -45.9e+9)) - { - ACE_DEBUG ((LM_ERROR, "incorrect value received, should be:\n" - "int 1 float 0.123421 long 666555444 float 23.450001 " - "double -46500000000.00000\n")); - ++error_at_client; - } - - // Reset the precision to limit ourselves - // to two significant digits. - server.precision(2); - - // Now, make a little change & send 'em back. - i *= -1; server << i << " "; - f1 *= -1; server << f1 << " "; - l *= -1; server << l << " "; - f2 *= -1; server << f2 << " "; - d *= -1; server << d << " "; - server << endl; - - // Shut down the test. - server.close(); - - return 0; +void * +server (void *) +{ + ACE_NEW_THREAD; + +#if defined (ACE_HAS_THREADS) + ACE_Thread_Control thread_control (ACE_Service_Config::thr_mgr ()); +#endif /* ACE_HAS_THREADS */ + + ACE_INET_Addr addr (PORT); + ACE_SOCK_Acceptor acceptor (addr); + ACE_SOCK_IOStream client_handler; + + if (thr_mgr.spawn (ACE_THR_FUNC (client), + 0, + THR_NEW_LWP | THR_DETACHED) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n","spawing client thread"), 1); + + if (acceptor.accept (client_handler) == -1) + ACE_DEBUG ((LM_ERROR, "Failed to accept new client_handler")); + + // Read a qbuf[] from the client. Notice that all of the client's + // whitespace is preserved. + qchar qbuf[1024]; + ACE_OS::memset (qbuf, 0, sizeof qbuf); + client_handler >> qbuf; + ACE_DEBUG ((LM_DEBUG, + "Server Received: (\"%s\")\n", + qbuf)); + + // Give the client time to announce the next test to the user. + ACE_OS::sleep (2); + + // Now we try to use a char[] to get a string from the client. + // Compared to the method above, this is quite messy. Notice also + // that whitespace is lost. + + char buf[1024]; + ACE_OS::memset (buf, 0, sizeof buf); + ACE_DEBUG ((LM_DEBUG, "Server Received: (")); + + while (buf[ACE_OS::strlen (buf) - 1] != '"') + { + client_handler >> buf; + ACE_DEBUG ((LM_DEBUG, "%s ", buf)); + } + + ACE_DEBUG ((LM_DEBUG, ")\n")); + + // Send some non-textual data to the client. We use a single + // character to separate the fields but we could have used any valid + // whitespace. The data will be sent if the iostream's buffer gets + // filled or when we flush it with an explicit client.sync() command + // or the implicit <<endl. + + ACE_DEBUG ((LM_DEBUG, "Server Sending: 1 .12342134 666555444 23.45 -46.5e9 \n")); + client_handler << 1 << " "; + client_handler << .12342134 << " "; + client_handler << 666555444 << " "; + client_handler << 23.45 << " "; + client_handler << -46.5e9 << " "; + client_handler << endl; + + // The client will have changed the sign of each data field and sent + // 'em all back to us. At the same time, the client used the + // precision() function to change the significant digits for + // non-integer values. + int i; + float f1, f2; + long l; + double d; + client_handler >> i >> f1 >> l >> f2 >> d; + + ACE_DEBUG ((LM_DEBUG, + "Server Received: int %d float %g long %d float %g double %g\n", + i, f1, (int) l, f2, d)); + + // check for proper received values + if (i != -1 || (f1 < -0.13 || f1 > -0.11) + || l != -666555444 || (f2 < -24.0 || f2 > -22.0) + || (d < 45e+9 || d > 47e+9)) + { + ACE_DEBUG ((LM_ERROR, "incorrect value received, should be:\n" + "int -1 float -0.12 long -666555444 float -23 double 4.6e+10\n")); + ++error_at_server; + } + + ACE_ASSERT (error_at_client == 0 && error_at_server == 0); } -/* Test the server's ability to receive data from the client and then begin - a two-way conversation. - */ -void server_test(ACE_SOCK_IOStream & client) +static void +spawn (void) { - // Read a qbuf[] from the client. Notice that all of the - // client's whitespace is preserved. - // - qchar qbuf[1024]; - ACE_OS::memset(qbuf,0,sizeof(qbuf)); - client >> qbuf; - ACE_DEBUG ((LM_DEBUG, "Server Received: (\"%s\")\n", qbuf)); - - // Give the client time to announce the next test to the user - ACE_OS::sleep(2); - - // Now we try to use a char[] to get a string from the - // client. Compared to the method above, this is quite - // messy. Notice also that whitespace is lost. - // - char buf[1024]; - ACE_OS::memset(buf,0,sizeof(buf)); - ACE_DEBUG ((LM_DEBUG, "Server Received: (")); - while( buf[strlen(buf)-1] != '"' ) - { - client >> buf; - ACE_DEBUG ((LM_DEBUG, "%s ", buf)); - } - ACE_DEBUG ((LM_DEBUG, ")\n")); - - // Send some non-textual data to the client. - // We use a single character to separate the fields - // but we could have used any valid whitespace. - // The data will be sent if the iostream's buffer - // gets filled or when we flush it with an explicit - // client.sync() command or the implicit <<endl. - // - ACE_DEBUG ((LM_DEBUG, "Server Sending: 1 .12342134 666555444 23.45 -46.5e9 \n")); - client << 1 << " "; - client << .12342134 << " "; - client << 666555444 << " "; - client << 23.45 << " "; - client << -46.5e9 << " "; - client << endl; - - // The client will have changed the sign of each data field - // and sent 'em all back to us. At the same time, the - // client used the precision() function to change the - // significant digits for non-integer values. - // - int i; - float f1, f2; - long l; - double d; - client >> i >> f1 >> l >> f2 >> d; - - ACE_DEBUG ((LM_DEBUG, "Server Received: int %d float %g long %d float %g double %g\n", i, f1, (int) l, f2, d)); - - // check for proper received values - if (i != -1 || (f1 < -0.13 || f1 > -0.11) || - l != -666555444 || (f2 < -24.0 || f2 > -22.0) || - (d < 45e+9 || d > 47e+9)) - { - ACE_DEBUG ((LM_ERROR, "incorrect value received, should be:\n" - "int -1 float -0.12 long -666555444 float -23 double 4.6e+10\n")); - ++error_at_server; - } - - return; +#if defined (ACE_HAS_THREADS) + if (thr_mgr.spawn (ACE_THR_FUNC (server), + 0, + THR_NEW_LWP | THR_DETACHED) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n","spawing server thread"), 1); + + // Wait for the client and server thread to exit. + thr_mgr.wait (); + +#elif !defined (ACE_LACKS_EXEC) + server (); + + switch (ACE_OS::fork ("child")) + { + case -1: + ACE_ERROR ((LM_ERROR, "%p\n%a", "fork failed")); + ACE_OS::_exit (-1); + case 0: // In child + { + client (); + break; + } + default: // In parent + { + // Allow the client to exit, then remove the Process_Mutex. + ACE_OS::wait (); + break; + } + } +#else + ACE_ERROR ((LM_ERROR, + "threads *and* processes not supported on this platform\n%")); +#endif /* ACE_HAS_THREADS */ } - int main (int argc, char *argv[]) { - ACE_START_TEST ("IOStream_Test"); - - if( argc > 1 ) - PORT = ACE_OS::atoi(argv[1]); - - ACE_Thread_Manager thr_mgr; - ACE_INET_Addr addr(PORT); - ACE_SOCK_Acceptor acceptor(addr); - ACE_SOCK_IOStream connection; - - if (thr_mgr.spawn(ACE_THR_FUNC (client_thread),&thr_mgr,THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN((LM_ERROR,"%p\n","spawing client thread"),1); - - if( acceptor.accept(connection) < 0 ) - { - ACE_DEBUG ((LM_ERROR, "Failed to accept new connection")); - } - - server_test(connection); + ACE_START_TEST ("IOStream_Test"); - // Wait for the client thread to exit - thr_mgr.wait(); + if (argc > 1) + PORT = ACE_OS::atoi (argv[1]); - connection.close(); - acceptor.close(); + spawn (); - ACE_END_TEST; - return error_at_client || error_at_server; + ACE_END_TEST; } #if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) diff --git a/tests/Mutex_Test.cpp b/tests/Mutex_Test.cpp index 114641a500f..dc8332df51b 100644 --- a/tests/Mutex_Test.cpp +++ b/tests/Mutex_Test.cpp @@ -62,7 +62,7 @@ spawn (void) { case -1: ACE_ERROR ((LM_ERROR, "%p\n%a", "fork failed")); - exit (-1); + ACE_OS::_exit (-1); case 0: // In child { ACE_Process_Mutex pm (ACE_WIDE_STRING (name)); @@ -97,7 +97,8 @@ spawn (void) ACE_Service_Config::thr_mgr ()->wait (); #else - ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n%a", 1)); + ACE_ERROR ((LM_ERROR, + "threads *and* processes not supported on this platform\n%")); #endif /* ACE_HAS_THREADS */ } |