diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2002-04-23 11:32:18 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2002-04-23 11:32:18 +0000 |
commit | 90d61fbdf279ecbeee52aecbb8f399acbffaf800 (patch) | |
tree | beea6da53c6a9d0e4c1e0c569fbde2ae7963eba1 /examples | |
parent | 4374173f4da0708b05424a3a3aca362e9fdd7591 (diff) | |
download | ATCD-90d61fbdf279ecbeee52aecbb8f399acbffaf800.tar.gz |
ChangeLogTag: Tue Apr 23 13:29:12 2002 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Reactor/Makefile.bor | 1 | ||||
-rw-r--r-- | examples/Reactor/Proactor/Makefile.bor | 25 | ||||
-rw-r--r-- | examples/Reactor/Proactor/post_completions.cpp | 60 | ||||
-rw-r--r-- | examples/Reactor/Proactor/simple_test_proactor.cpp | 26 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_cancel.cpp | 44 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_end_event_loop.cpp | 32 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_proactor.cpp | 16 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_proactor2.cpp | 12 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_proactor3.cpp | 118 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_timeout.cpp | 30 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_timeout_st.cpp | 30 | ||||
-rw-r--r-- | examples/Reactor/Proactor/test_udp_proactor.cpp | 14 |
12 files changed, 217 insertions, 191 deletions
diff --git a/examples/Reactor/Makefile.bor b/examples/Reactor/Makefile.bor index 106d1095bfe..7e2beea81f0 100644 --- a/examples/Reactor/Makefile.bor +++ b/examples/Reactor/Makefile.bor @@ -6,6 +6,7 @@ DIRS = \ Dgram \ Multicast \ Ntalker \ + Proactor \ WFMO_Reactor !include <$(ACE_ROOT)\include\makeinclude\recurse.bor> diff --git a/examples/Reactor/Proactor/Makefile.bor b/examples/Reactor/Proactor/Makefile.bor new file mode 100644 index 00000000000..63d68ef4b73 --- /dev/null +++ b/examples/Reactor/Proactor/Makefile.bor @@ -0,0 +1,25 @@ +# +# Makefile for building the ACE Proactor examples +# + +NAMES = \ + simple_test_proactor \ + test_proactor \ + test_timeout \ + test_timeout_st \ + post_completions \ + test_end_event_loop \ + test_cancel \ + test_proactor2 \ + test_udp_proactor + +OBJFILES = $(OBJDIR)\$(NAME).obj + +CFLAGS = $(ACE_CFLAGS) + +CPPDIR = . + +LIBFILES = $(ACE_LIB) + +!include <$(ACE_ROOT)\include\makeinclude\recurse.bor> +!include <$(ACE_ROOT)\include\makeinclude\build_exe.bor> diff --git a/examples/Reactor/Proactor/post_completions.cpp b/examples/Reactor/Proactor/post_completions.cpp index 1935271f0a1..f24fe05038b 100644 --- a/examples/Reactor/Proactor/post_completions.cpp +++ b/examples/Reactor/Proactor/post_completions.cpp @@ -9,7 +9,7 @@ // Proactor. It also shows the how to specify the particular // real-time signals to post completions. The Real-time signal // based completion strategy is implemented with -// ACE_POSIX_SIG_PROACTOR. +// ACE_POSIX_SIG_PROACTOR. // (So, it can be used only if ACE_HAS_AIO_CALLS is defined and // ACE_POSIX_AIOCB_PROACTOR is not defined) // Since it is faking results, you have to pay by knowing and @@ -57,12 +57,12 @@ static ACE_Atomic_Op <ACE_Thread_Mutex, size_t> Completions_To_Go; class My_Result : public RESULT_CLASS { // = TITLE - // + // // Result Object that we will post to the Proactor. // // = DESCRIPTION // - + public: My_Result (ACE_Handler &handler, const void *act, @@ -78,11 +78,11 @@ public: sequence_number_ (sequence_number) {} // Constructor. - + virtual ~My_Result (void) {} // Destructor. - + void complete (u_long, int success, const void *completion_key, @@ -100,13 +100,13 @@ public: // Print the completion details. ACE_DEBUG ((LM_DEBUG, - "(%t) Completion sequence number %d, success : %d, error : %d, signal_number : %d, %u more to go\n", + "(%t) Completion sequence number %d, success : %d, error : %d, signal_number : %d, %u more to go\n", this->sequence_number_, this->success_, this->error_, this->signal_number (), to_go)); - + // Sleep for a while. ACE_OS::sleep (4); } @@ -115,20 +115,20 @@ private: size_t sequence_number_; // Sequence number for the result object. }; - + class My_Handler : public ACE_Handler { // = TITLE // - // Handler class for faked completions. + // Handler class for faked completions. // // = DESCRIPTION // - + public: My_Handler (void) {} // Constructor. - + virtual ~My_Handler (void) {} // Destructor. }; @@ -136,14 +136,14 @@ public: class My_Task: public ACE_Task <ACE_NULL_SYNCH> { // = TITLE - // - // Contains thread functions which execute event loops. Each + // + // Contains thread functions which execute event loops. Each // thread waits for a different signal. // public: My_Task (void) {} // Constructor. - + virtual ~My_Task (void) {} // Destructor. @@ -151,7 +151,7 @@ public: { // Store the proactor. this->proactor_ = (ACE_Proactor *) proactor; - + // Activate the Task. this->activate (THR_NEW_LWP, 5); return 0; @@ -161,14 +161,14 @@ public: { // Handle events for 13 seconds. ACE_Time_Value run_time (13); - + ACE_DEBUG ((LM_DEBUG, "(%t):Starting svc routine\n")); - + if (this->proactor_->handle_events (run_time) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%t):%p.\n", "Worker::svc"), -1); - + ACE_DEBUG ((LM_DEBUG, "(%t) work complete\n")); - + return 0; } @@ -178,7 +178,7 @@ private: }; int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); @@ -187,8 +187,8 @@ main (int argc, char *argv[]) "(%P | %t):Test starts \n")); // = Get two POSIX_SIG_Proactors, one with SIGRTMIN and one with - // SIGRTMAX. - + // SIGRTMAX. + ACE_Proactor proactor1; // Proactor1. SIGRTMIN Proactor. (default). @@ -196,10 +196,10 @@ main (int argc, char *argv[]) #if defined (ACE_HAS_AIO_CALLS) && !defined (ACE_POSIX_AIOCB_PROACTOR) ACE_DEBUG ((LM_DEBUG, "Using ACE_POSIX_SIG_Proactor\n")); - + sigset_t signal_set; // Signal set that we want to mask. - + // Clear the signal set. if (sigemptyset (&signal_set) == -1) ACE_ERROR_RETURN ((LM_ERROR, @@ -230,9 +230,9 @@ main (int argc, char *argv[]) // Handler for completions. My_Handler handler; - + // = Create a few MyResult objects and post them to Proactor. - const size_t NrCompletions (10); + const size_t NrCompletions (10); My_Result *result_objects [NrCompletions]; int signal_number = ACE_SIGRTMAX; size_t ri; @@ -256,7 +256,7 @@ main (int argc, char *argv[]) ri), 1); } - ACE_OS::sleep(5); + ACE_OS::sleep(5); // Post all the result objects. ACE_Proactor *proactor; for (ri = 0; ri < NrCompletions; ri++) @@ -265,7 +265,7 @@ main (int argc, char *argv[]) // completions. if (ri % 2) proactor = &proactor1; - else + else proactor = &proactor2; if (result_objects [ri]->post_completion (proactor->implementation ()) == -1) @@ -273,7 +273,7 @@ main (int argc, char *argv[]) "Test failed\n"), 1); } - + ACE_Thread_Manager::instance ()->wait (); int status = 0; @@ -303,7 +303,7 @@ template class ACE_Atomic_Op_Ex <ACE_Thread_Mutex, size_t>; #else /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS && !ACE_POSIX_AIOCB_PROACTOR*/ -int +int main (int, char *[]) { ACE_DEBUG ((LM_DEBUG, diff --git a/examples/Reactor/Proactor/simple_test_proactor.cpp b/examples/Reactor/Proactor/simple_test_proactor.cpp index 511b95d956c..510a0f6f0a8 100644 --- a/examples/Reactor/Proactor/simple_test_proactor.cpp +++ b/examples/Reactor/Proactor/simple_test_proactor.cpp @@ -29,8 +29,8 @@ ACE_RCSID(Proactor, test_proactor, "simple_test_proactor.cpp,v 1.1 1999/05/18 22 // This only works on Win32 platforms and on Unix platforms supporting // POSIX aio calls. -static char *file = "simple_test_proactor.cpp"; -static char *dump_file = "simple_output"; +static ACE_TCHAR *file = ACE_TEXT("simple_test_proactor.cpp"); +static ACE_TCHAR *dump_file = ACE_TEXT("simple_output"); class Simple_Tester : public ACE_Handler { @@ -66,7 +66,7 @@ private: ACE_Asynch_Read_File rf_; // rf (read file): for writing from the file. - + ACE_Asynch_Write_File wf_; // ws (write File): for writing to the file. @@ -114,7 +114,7 @@ Simple_Tester::open (void) 0644); if (this->dump_file_ == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_OS::open"), -1); - + // Open ACE_Asynch_Read_File if (this->rf_.open (*this, this->input_file_) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Read_File::open"), -1); @@ -123,10 +123,10 @@ Simple_Tester::open (void) if (this->wf_.open (*this, this->dump_file_) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Write_File::open"), -1); - ACE_DEBUG ((LM_DEBUG, + ACE_DEBUG ((LM_DEBUG, "Simple_Tester::open: Files and Asynch Operations opened sucessfully\n")); - + // Start an asynchronous read file if (this->initiate_read_file () == -1) return -1; @@ -147,7 +147,7 @@ Simple_Tester::initiate_read_file (void) mb->size () - 1) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Read_File::read"), -1); - ACE_DEBUG ((LM_DEBUG, + ACE_DEBUG ((LM_DEBUG, "Simple_Tester:initiate_read_file: Asynch Read File issued sucessfully\n")); return 0; @@ -194,12 +194,12 @@ void Simple_Tester::handle_write_file (const ACE_Asynch_Write_File::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_write_File called\n")); - + // Reset pointers result.message_block ().rd_ptr (result.message_block ().rd_ptr () - result.bytes_transferred ()); result.message_block ().rd_ptr ()[result.bytes_transferred ()] = '\0'; - + ACE_DEBUG ((LM_DEBUG, "********************\n")); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_write", result.bytes_to_write ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ())); @@ -221,9 +221,9 @@ Simple_Tester::handle_write_file (const ACE_Asynch_Write_File::Result &result) } static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "f:d:"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("f:d:")); int c; while ((c = get_opt ()) != EOF) @@ -247,7 +247,7 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; @@ -256,7 +256,7 @@ main (int argc, char *argv[]) if (Simple_Tester.open () == -1) return -1; - + int success = 1; // dispatch events diff --git a/examples/Reactor/Proactor/test_cancel.cpp b/examples/Reactor/Proactor/test_cancel.cpp index 5823fe82de6..2190ff499ec 100644 --- a/examples/Reactor/Proactor/test_cancel.cpp +++ b/examples/Reactor/Proactor/test_cancel.cpp @@ -11,20 +11,20 @@ // = DESCRIPTION // This program tests cancelling an Asynchronous Operation in the // Proactor framework. -// +// // This tests accepts a connection and issues an Asynchronous Read // Stream. It reads <read_size> (option -s) number of bytes and // when this operation completes, it issues another Asynchronous // Read Stream to <read_size> and immediately calls <cancel> to // cancel the operation and so the program exits closing the -// connection. +// connection. // // Works fine on NT. On Solaris platforms, the asynch read is // pending, but the cancel returns with the value <AIO_ALLDONE> // indicating all the operations in that handle are done. // But, LynxOS has a good <aio_cancel> implementation. It works -// fine. -// +// fine. +// // = RUN // ./test_cancel -p <port_number> // Then telnet to this port and send <read_size> bytes and your @@ -77,7 +77,7 @@ public: virtual void open (ACE_HANDLE handle, ACE_Message_Block &message_block); // This is called after the new connection has been accepted. - + protected: // These methods are called by the framework @@ -90,7 +90,7 @@ private: ACE_Message_Block mb_; // Message block to read from the stream. - + ACE_HANDLE handle_; // Handle for IO to remote peer }; @@ -106,7 +106,7 @@ Receiver::~Receiver (void) ACE_DEBUG ((LM_DEBUG, "Receiver: Closing down Remote connection:%d\n", this->handle_)); - + ACE_OS::closesocket (this->handle_); } @@ -115,9 +115,9 @@ Receiver::open (ACE_HANDLE handle, ACE_Message_Block &) { // New connection, initiate stuff - + ACE_DEBUG ((LM_DEBUG, "%N:%l:Receiver::open called\n")); - + // Cache the new connection this->handle_ = handle; @@ -129,11 +129,11 @@ Receiver::open (ACE_HANDLE handle, } // Try to read <n> bytes from the stream. - + ACE_DEBUG ((LM_DEBUG, "Receiver::open: Issuing Asynch Read of (%d) bytes from the stream\n", read_size)); - + if (this->rs_.read (this->mb_, read_size) == -1) ACE_ERROR ((LM_ERROR, @@ -166,7 +166,7 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) // Set the pointers back in the message block. result.message_block ().wr_ptr (result.message_block ().rd_ptr ()); - + // Issue another read, but immediately cancel it. // Issue the read. @@ -174,15 +174,15 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) ACE_DEBUG ((LM_DEBUG, "Issuing Asynch Read of (%d) bytes from the stream\n", read_size)); - + if (this->rs_.read (this->mb_, read_size) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "Receiver::handle_read_stream: Failed to issue the read")); - + // Cancel the read. - + ACE_DEBUG ((LM_DEBUG, "Cacelling Asynch Read ")); @@ -198,14 +198,14 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) else { done = 1; - + ACE_DEBUG ((LM_DEBUG, "Receiver completed\n")); // Print the error message if any. if (result.error () != 0) { errno = result.error (); - + ACE_ERROR ((LM_ERROR, "%p\n", "Asynch Read Stream Error: ")); @@ -214,9 +214,9 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) } static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "p:s:"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:s:")); int c; while ((c = get_opt ()) != EOF) @@ -240,11 +240,11 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; - + // Note: acceptor parameterized by the Receiver ACE_Asynch_Acceptor<Receiver> acceptor; @@ -261,7 +261,7 @@ main (int argc, char *argv[]) while (success > 0 && !done) // dispatch events success = ACE_Proactor::instance ()->handle_events (); - + return 0; } diff --git a/examples/Reactor/Proactor/test_end_event_loop.cpp b/examples/Reactor/Proactor/test_end_event_loop.cpp index c97be444e27..8177f2ca429 100644 --- a/examples/Reactor/Proactor/test_end_event_loop.cpp +++ b/examples/Reactor/Proactor/test_end_event_loop.cpp @@ -9,7 +9,7 @@ // Proactor. To end the event loop, threads that are blocked in // waiting for completions are woken up and the event loop comes // to the end. This is tested in this program. -// +// // Threads are doing <run_event_loop> with/without time_out // values and the main thread calls <end_event_loop>. // @@ -38,8 +38,8 @@ class My_Task: public ACE_Task <ACE_NULL_SYNCH> { // = TITLE - // - // Contains thread functions which execute event loops. Each + // + // Contains thread functions which execute event loops. Each // thread waits for a different signal. // public: @@ -48,7 +48,7 @@ public: : time_flag_ (0) {} - + virtual ~My_Task (void) {} // Destructor. @@ -61,30 +61,30 @@ public: this->time_flag_ = 0; else this->time_flag_ = 1; - + // Spawn the threads. if (this->activate (THR_NEW_LWP, 5) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%N:%l:%p\n", "My_Task:open: <activate> failed"), -1); - + return 0; } - + // Thread function. int svc (void) { ACE_DEBUG ((LM_DEBUG, "(%P|%t):Starting svc routine\n")); - + if (this->time_flag_) { ACE_DEBUG ((LM_DEBUG, "(%P|%t):Going to do *timed* <run_event_loop> \n")); ACE_Time_Value run_time (13); - + if (ACE_Proactor::instance ()->run_event_loop (run_time) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t):%p.\n", "<Proactor::run_event_loop> failed"), @@ -94,7 +94,7 @@ public: { ACE_DEBUG ((LM_DEBUG, "(%P|%t):Going to do *indefinite* <run_event_loop> \n")); - + if (ACE_Proactor::instance ()->run_event_loop () == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t):%p.\n", "<Proactor::run_event_loop> failed"), @@ -102,14 +102,14 @@ public: } return 0; }; - + private: int time_flag_; - // If zero, indefinite event loop, otherwise timed event loop. + // If zero, indefinite event loop, otherwise timed event loop. }; int -main (int argc, char *argv []) +ACE_TMAIN (int argc, ACE_TCHAR *argv []) { ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); @@ -136,7 +136,7 @@ main (int argc, char *argv []) ACE_ERROR_RETURN ((LM_ERROR, "%N:%l:(%P | %t):Failed to <open> the task\n"), 1); - + // Give a gap. ACE_OS::sleep (3); @@ -145,7 +145,7 @@ main (int argc, char *argv []) ACE_ERROR_RETURN ((LM_ERROR, "%N:%l:(%P | %t):Failed to <end_event_loop>\n"), 1); - + ACE_Thread_Manager::instance ()->wait (); ACE_DEBUG ((LM_DEBUG, @@ -161,7 +161,7 @@ template class ACE_Task <ACE_NULL_SYNCH>; #else /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS && !ACE_POSIX_AIOCB_PROACTOR*/ -int +int main (int, char *[]) { ACE_DEBUG ((LM_DEBUG, diff --git a/examples/Reactor/Proactor/test_proactor.cpp b/examples/Reactor/Proactor/test_proactor.cpp index a2ec5dd138c..2cb4b2caccc 100644 --- a/examples/Reactor/Proactor/test_proactor.cpp +++ b/examples/Reactor/Proactor/test_proactor.cpp @@ -38,16 +38,16 @@ ACE_RCSID(Proactor, test_proactor, "$Id$") // POSIX aio calls. // Host that we're connecting to. -static char *host = 0; +static ACE_TCHAR *host = 0; // Port that we're receiving connections on. static u_short port = ACE_DEFAULT_SERVER_PORT; // File that we're sending. -static char *file = "test_proactor.cpp"; +static ACE_TCHAR *file = ACE_TEXT("test_proactor.cpp"); // Name of the output file. -static char *dump_file = "output"; +static ACE_TCHAR *dump_file = ACE_TEXT("output"); // Keep track of when we're done. static int done = 0; @@ -315,7 +315,7 @@ class Sender : public ACE_Handler public: Sender (void); ~Sender (void); - int open (const char *host, + int open (const ACE_TCHAR *host, u_short port); ACE_HANDLE handle (void) const; @@ -394,7 +394,7 @@ Sender::handle (void) const } int -Sender::open (const char *host, +Sender::open (const ACE_TCHAR *host, u_short port) { // Initialize stuff @@ -631,9 +631,9 @@ Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) } static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "h:p:f:d:"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("h:p:f:d:")); int c; while ((c = get_opt ()) != EOF) @@ -664,7 +664,7 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; diff --git a/examples/Reactor/Proactor/test_proactor2.cpp b/examples/Reactor/Proactor/test_proactor2.cpp index 384de47be02..5de8cf171c3 100644 --- a/examples/Reactor/Proactor/test_proactor2.cpp +++ b/examples/Reactor/Proactor/test_proactor2.cpp @@ -61,7 +61,7 @@ int PrintSigMask (); #define COUT(X) cout << X ; cout.flush (); // Host that we're connecting to. -static char *host = 0; +static ACE_TCHAR *host = 0; // duplex mode: ==0 half-duplex // !=0 full duplex @@ -370,7 +370,7 @@ class Sender : public ACE_Handler public: Sender (void); ~Sender (void); -int open (const char *host, u_short port); +int open (const ACE_TCHAR *host, u_short port); void close (); ACE_HANDLE handle (void) const; @@ -430,7 +430,7 @@ ACE_HANDLE Sender::handle (void) const return this->stream_.get_handle (); } -int Sender::open (const char *host, u_short port) +int Sender::open (const ACE_TCHAR *host, u_short port) { // Initialize stuff // Connect to remote host @@ -627,9 +627,9 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) //-------------------------------------------------------------------------- static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "n:p:d:h:"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:p:d:h:")); int c; while ((c = get_opt ()) != EOF) @@ -661,7 +661,7 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_UNUSED_ARG (initial_read_size); diff --git a/examples/Reactor/Proactor/test_proactor3.cpp b/examples/Reactor/Proactor/test_proactor3.cpp index d651bb5341d..d0bc56c6936 100644 --- a/examples/Reactor/Proactor/test_proactor3.cpp +++ b/examples/Reactor/Proactor/test_proactor3.cpp @@ -11,7 +11,7 @@ // = DESCRIPTION // This program illustrates how the <ACE_Proactor> can be used to // implement an application that does various asynchronous -// operations. +// operations. // // = AUTHOR // Irfan Pyarali <irfan@cs.wustl.edu> @@ -69,13 +69,13 @@ static int proactor_type = 0; static int max_aio_operations = 0; // Host that we're connecting to. -static char *host = 0; +static ACE_TCHAR *host = 0; // number of Senders instances static int senders = 1; static const int MaxSenders = 100; -// duplex mode: ==0 half-duplex +// duplex mode: ==0 half-duplex // !=0 full duplex static int duplex = 0; @@ -91,7 +91,7 @@ class MyTask: public ACE_Task<ACE_MT_SYNCH> // MyTask plays role for Proactor threads pool public: MyTask (void) : threads_ (0), proactor_ (0) {} - + int svc (void); void waitready (void) { event_.wait (); } @@ -105,17 +105,17 @@ private: void delete_proactor (void); }; -void +void MyTask::create_proactor (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); if (threads_ == 0) { #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) ACE_WIN32_Proactor *proactor = new ACE_WIN32_Proactor; ACE_DEBUG ((LM_DEBUG,"(%t) Create Proactor Type=WIN32")); - + #elif defined (ACE_HAS_AIO_CALLS) ACE_POSIX_Proactor *proactor = 0; @@ -125,7 +125,7 @@ MyTask::create_proactor (void) case 1: proactor = new ACE_POSIX_AIOCB_Proactor (max_aio_operations); ACE_DEBUG ((LM_DEBUG,"(%t) Create Proactor Type=AIOCB\n")); break; - case 2: proactor = new ACE_POSIX_SIG_Proactor; + case 2: proactor = new ACE_POSIX_SIG_Proactor; ACE_DEBUG ((LM_DEBUG,"(%t) Create Proactor Type=SIG\n")); break; # if defined (sun) @@ -137,7 +137,7 @@ MyTask::create_proactor (void) ACE_DEBUG ((LM_DEBUG,"(%t) Create Proactor Type=SIG\n")); break; } -#endif +#endif proactor_ = new ACE_Proactor (proactor, 1); @@ -148,10 +148,10 @@ MyTask::create_proactor (void) threads_++; } -void +void MyTask::delete_proactor (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); if (--threads_ == 0) { ACE_DEBUG ((LM_DEBUG, "(%t) Delete Proactor\n")); @@ -161,7 +161,7 @@ MyTask::delete_proactor (void) } } -int +int MyTask::svc (void) { ACE_DEBUG ((LM_DEBUG, "(%t) MyTask started\n")); @@ -181,7 +181,7 @@ MyTask::svc (void) class Receiver : public ACE_Service_Handler { public: - + Receiver (void); ~Receiver (void); @@ -198,8 +198,8 @@ protected: // This is called when asynchronous <read> operation from the socket // complete. - virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result); - // This is called when an asynchronous <write> to the file + virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result); + // This is called when an asynchronous <write> to the file // completes. private: @@ -221,25 +221,25 @@ Receiver::Receiver (void) : handle_ (ACE_INVALID_HANDLE), io_count_ (0) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); sessions_++; ACE_DEBUG ((LM_DEBUG, "Receiver Ctor sessions_=%d\n", sessions_)); } Receiver::~Receiver (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); sessions_--; ACE_OS::closesocket (this->handle_); ACE_DEBUG ((LM_DEBUG, "~Receiver Dtor sessions_=%d\n", sessions_)); } // return true if we alive, false we commited suicide -int +int Receiver::check_destroy (void) { { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); if (io_count_ > 0) return 1; @@ -249,13 +249,13 @@ Receiver::check_destroy (void) return 0; } -void +void Receiver::open (ACE_HANDLE handle, ACE_Message_Block &) { ACE_DEBUG ((LM_DEBUG, "%N:%l:Receiver::open called\n")); - + this->handle_ = handle; if (this->ws_.open (*this, this->handle_) == -1) @@ -272,10 +272,10 @@ Receiver::open (ACE_HANDLE handle, check_destroy (); } -int +int Receiver::initiate_read_stream (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); ACE_Message_Block *mb = 0; ACE_NEW_RETURN (mb, @@ -296,10 +296,10 @@ Receiver::initiate_read_stream (void) return 0; } -int +int Receiver::initiate_write_stream (ACE_Message_Block &mb, int nbytes) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); if (nbytes <= 0) { mb.release (); @@ -326,7 +326,7 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) { // Reset pointers. result.message_block ().rd_ptr ()[result.bytes_transferred ()] = '\0'; - + if (result.bytes_transferred () == 0 || result.error () != 0) { ACE_DEBUG ((LM_DEBUG, "handle_read_stream called\n")); @@ -341,14 +341,14 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) ACE_DEBUG ((LM_DEBUG, "********************\n")); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ())); } - + if (result.success () && result.bytes_transferred () != 0) { // Successful read: write the data to the file asynchronously. // Note how we reuse the <ACE_Message_Block> for the writing. // Therefore, we do not delete this buffer because it is handled // in <handle_write_stream>. - + if(this->initiate_write_stream (result.message_block (), result.bytes_transferred ()) == 0) { @@ -366,7 +366,7 @@ Receiver::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) } { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); io_count_--; } check_destroy (); @@ -403,7 +403,7 @@ Receiver::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) } { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); io_count_--; } check_destroy (); @@ -416,7 +416,7 @@ class Sender : public ACE_Handler public: Sender (void); ~Sender (void); - int open (const char *host, u_short port); + int open (const ACE_TCHAR *host, u_short port); void close (void); ACE_HANDLE handle (void) const; @@ -474,7 +474,7 @@ ACE_HANDLE Sender::handle (void) const return this->stream_.get_handle (); } -int Sender::open (const char *host, u_short port) +int Sender::open (const ACE_TCHAR *host, u_short port) { // Initialize stuff // Connect to remote host @@ -516,15 +516,15 @@ int Sender::open (const char *host, u_short port) return 0; } -int +int Sender::initiate_write_stream (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); welcome_message_.rd_ptr(welcome_message_.base ()); welcome_message_.wr_ptr(welcome_message_.base ()); welcome_message_.wr_ptr (ACE_OS::strlen (data)); - + if (this->ws_.write (welcome_message_, welcome_message_.length ()) == -1) ACE_ERROR_RETURN((LM_ERROR, @@ -535,10 +535,10 @@ Sender::initiate_write_stream (void) return 0; } -int +int Sender::initiate_read_stream (void) { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); // Create a new <Message_Block>. Note that this message block will // be used both to <read> data asynchronously from the socket and to @@ -565,7 +565,7 @@ Sender::initiate_read_stream (void) return 0; } -void +void Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) { if (result.bytes_transferred () == 0 || result.error () != 0) @@ -592,12 +592,12 @@ Sender::handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) { if (duplex != 0) // full duplex, continue write initiate_write_stream (); - else // half-duplex read reply, after read we will start write + else // half-duplex read reply, after read we will start write initiate_read_stream (); } { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); io_count_--; } } @@ -609,10 +609,10 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) { ACE_DEBUG ((LM_DEBUG, "handle_read_stream called\n")); - + // Reset pointers. result.message_block ().rd_ptr ()[result.bytes_transferred ()] = '\0'; - + ACE_DEBUG ((LM_DEBUG, "********************\n")); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "bytes_to_read", result.bytes_to_read ())); ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "handle", result.handle ())); @@ -624,7 +624,7 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) ACE_DEBUG ((LM_DEBUG, "********************\n")); ACE_DEBUG ((LM_DEBUG, "%s = %s\n", "message_block", result.message_block ().rd_ptr ())); } - + result.message_block().release (); if (result.success () && result.bytes_transferred () != 0) @@ -633,7 +633,7 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) // Note how we reuse the <ACE_Message_Block> for the writing. // Therefore, we do not delete this buffer because it is handled // in <handle_write_stream>. - + if (duplex != 0) // full duplex, continue read initiate_read_stream (); else // half-duplex writey, after write we will start read @@ -641,7 +641,7 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) } { - ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); + ACE_Guard<ACE_Recursive_Thread_Mutex> locker (mutex_); io_count_--; } } @@ -649,7 +649,7 @@ Sender::handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) static int set_proactor_type (const char *ptype) { - if (!ptype) + if (!ptype) return false; switch (toupper (*ptype)) @@ -665,9 +665,9 @@ set_proactor_type (const char *ptype) } static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "t:o:n:p:d:h:s:u"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("t:o:n:p:d:h:s:u")); int c; while ((c = get_opt ()) != EOF) @@ -690,7 +690,7 @@ parse_args (int argc, char *argv[]) if (senders > MaxSenders) senders = MaxSenders; break; - case 'o': // max number of aio for proactor + case 'o': // max number of aio for proactor max_aio_operations = ACE_OS::atoi (get_opt.opt_arg ()); break; case 't': // Proactor Type @@ -721,7 +721,7 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { #if defined (sun) ACE_DEBUG ((LM_DEBUG, "\nSUN defined!\n")); @@ -788,7 +788,7 @@ main (int argc, char *argv[]) tm->wait_task (&task1); cout << "\nNumber of Receivers objects=" - << Receiver::get_number_sessions () + << Receiver::get_number_sessions () << flush; for (i = 0; i < senders; ++i) @@ -800,7 +800,7 @@ main (int argc, char *argv[]) return 0; } -static int +static int disable_signal (int sigmin, int sigmax) { #ifndef ACE_WIN32 @@ -813,21 +813,21 @@ disable_signal (int sigmin, int sigmax) for (int i = sigmin; i <= sigmax; i++) sigaddset (&signal_set, i); - + // Put the <signal_set>. if (ACE_OS::pthread_sigmask (SIG_BLOCK, &signal_set, 0) != 0) ACE_ERROR ((LM_ERROR, "Error:(%P | %t):%p\n", "pthread_sigmask failed")); #endif /* ACE_WIN32 */ - - return 1; + + return 1; } // Get the <signal_set> back from the OS. #if 0 -static int +static int print_sigmask (void) { #ifndef ACE_WIN32 @@ -847,13 +847,13 @@ print_sigmask (void) COUT ("\nSig ") COUT (i) - COUT (" is ") + COUT (" is ") COUT (member) - + if (member == -1) break; } - + #endif /* ACE_WIN32 */ return 0; } diff --git a/examples/Reactor/Proactor/test_timeout.cpp b/examples/Reactor/Proactor/test_timeout.cpp index 15918ab8256..8639b79ee23 100644 --- a/examples/Reactor/Proactor/test_timeout.cpp +++ b/examples/Reactor/Proactor/test_timeout.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_timeout.cpp // @@ -18,7 +18,7 @@ // // = AUTHOR // Irfan Pyarali and Alexander Babu Arulanthu -// +// // ============================================================================ #include "ace/Proactor.h" @@ -47,19 +47,19 @@ public: const void *arg) { // Print out when timeouts occur. - ACE_DEBUG ((LM_DEBUG, "(%t) %d timeout occurred for %s @ %d.\n", + ACE_DEBUG ((LM_DEBUG, "(%t) %d timeout occurred for %s @ %d.\n", ++count_, (char *) arg, (tv - this->start_time_).sec ())); - + // Sleep for a while ACE_OS::sleep (4); } - + private: ACE_Atomic_Op <ACE_Thread_Mutex, int> count_; // Number of the timer event. - + ACE_Time_Value start_time_; // Starting time of the test. }; @@ -67,24 +67,24 @@ private: class Worker : public ACE_Task <ACE_NULL_SYNCH> { public: - int svc (void) + int svc (void) { // Handle events for 13 seconds. ACE_Time_Value run_time (13); - + ACE_DEBUG ((LM_DEBUG, "(%t):Starting svc routine\n")); - + if (ACE_Proactor::run_event_loop(run_time) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%t):%p.\n", "Worker::svc"), -1); - + ACE_DEBUG ((LM_DEBUG, "(%t) work complete\n")); - + return 0; } }; int -main (int, char *[]) +ACE_TMAIN (int, ACE_TCHAR *[]) { Timeout_Handler handler; @@ -105,12 +105,12 @@ main (int, char *[]) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1); Worker worker; - + if (worker.activate (THR_NEW_LWP, 10) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1); ACE_Thread_Manager::instance ()->wait (); - + return 0; } @@ -124,7 +124,7 @@ template class ACE_Atomic_Op_Ex<ACE_Thread_Mutex, int>; #else /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS && !ACE_POSIX_AIOCB_PROACTOR*/ -int +int main (int, char *[]) { ACE_DEBUG ((LM_DEBUG, diff --git a/examples/Reactor/Proactor/test_timeout_st.cpp b/examples/Reactor/Proactor/test_timeout_st.cpp index cf8372b6c37..3e5e70483f5 100644 --- a/examples/Reactor/Proactor/test_timeout_st.cpp +++ b/examples/Reactor/Proactor/test_timeout_st.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // examples -// +// // = FILENAME // test_timeout_st.cpp // @@ -16,7 +16,7 @@ // // = AUTHOR // Irfan Pyarali and Alexander Babu Arulanthu -// +// // ============================================================================ #include "ace/Proactor.h" @@ -31,38 +31,38 @@ class Timeout_Handler : public ACE_Handler { // = TITLE // Generic timeout handler. - + public: Timeout_Handler (void) - : count_ (0), + : count_ (0), start_time_ (ACE_OS::gettimeofday ()) - { + { } virtual void handle_time_out (const ACE_Time_Value &tv, const void *arg) { // Print out when timeouts occur. - ACE_DEBUG ((LM_DEBUG, "(%t) %d timeout occurred for %s @ %d.\n", + ACE_DEBUG ((LM_DEBUG, "(%t) %d timeout occurred for %s @ %d.\n", ++count_, (char *) arg, (tv - this->start_time_).sec ())); } - + private: int count_; // Sequence number for the timeouts. - + ACE_Time_Value start_time_; // Starting time of the test. }; int -main (int, char *[]) +ACE_TMAIN (int, ACE_TCHAR *[]) { Timeout_Handler handler; - + // Register a 2 second timer. ACE_Time_Value foo_tv (2); if (ACE_Proactor::instance ()->schedule_timer (handler, @@ -70,7 +70,7 @@ main (int, char *[]) ACE_Time_Value::zero, foo_tv) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1); - + // Register a 3 second timer. ACE_Time_Value bar_tv (3); if (ACE_Proactor::instance ()->schedule_timer (handler, @@ -81,17 +81,17 @@ main (int, char *[]) // Handle events for 13 seconds. ACE_Time_Value run_time (13); - + ACE_DEBUG ((LM_DEBUG, "Starting event loop\n")); - + // Run the event loop. if (ACE_Proactor::run_event_loop(run_time) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%t):%p.\n", "Worker::svc"), 1); - + ACE_DEBUG ((LM_DEBUG, "Ending event loop\n")); - + return 0; } diff --git a/examples/Reactor/Proactor/test_udp_proactor.cpp b/examples/Reactor/Proactor/test_udp_proactor.cpp index 31029eab233..04b87840dd5 100644 --- a/examples/Reactor/Proactor/test_udp_proactor.cpp +++ b/examples/Reactor/Proactor/test_udp_proactor.cpp @@ -32,7 +32,7 @@ ACE_RCSID(Proactor, test_udp_proactor, "test_proactor.cpp,v 1.29 2001/02/02 23:4 // This only works on Win32 platforms. // Host that we're connecting to. -static char *host = 0; +static ACE_TCHAR *host = 0; // Port that we're receiving connections on. static u_short port = ACE_DEFAULT_SERVER_PORT; @@ -219,7 +219,7 @@ class Sender : public ACE_Handler public: Sender (void); ~Sender (void); - int open (const char *host, u_short port); + int open (const ACE_TCHAR *host, u_short port); protected: // These methods are called by the freamwork @@ -252,7 +252,7 @@ Sender::~Sender (void) } int -Sender::open (const char *host, +Sender::open (const ACE_TCHAR *host, u_short port) { // Initialize stuff @@ -293,7 +293,7 @@ Sender::open (const char *host, // chain up to IOV_MAX message block using this method. msg->cont(body); - + // do the asynch send size_t number_of_bytes_sent = 0; ACE_INET_Addr serverAddr(port, host); @@ -363,9 +363,9 @@ Sender::handle_write_dgram (const ACE_Asynch_Write_Dgram::Result &result) } static int -parse_args (int argc, char *argv[]) +parse_args (int argc, ACE_TCHAR *argv[]) { - ACE_Get_Opt get_opt (argc, argv, "h:p:"); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("h:p:")); int c; while ((c = get_opt ()) != EOF) @@ -387,7 +387,7 @@ parse_args (int argc, char *argv[]) } int -main (int argc, char *argv[]) +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (parse_args (argc, argv) == -1) return -1; |