diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-22 01:31:30 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-08-22 01:31:30 +0000 |
commit | 0e91d13bf9be5b6fef2e693bfd07200dcb0f9d52 (patch) | |
tree | aea249749256c0057e1bcc3288f85b513f0939ce /examples/IPC_SAP | |
parent | 1f130377539c2effeb97e48d234989906b17744e (diff) | |
download | ATCD-0e91d13bf9be5b6fef2e693bfd07200dcb0f9d52.tar.gz |
*** empty log message ***
Diffstat (limited to 'examples/IPC_SAP')
-rw-r--r-- | examples/IPC_SAP/UPIPE_SAP/auto_builtin_ptr.h | 20 | ||||
-rw-r--r-- | examples/IPC_SAP/UPIPE_SAP/ex1.cpp | 103 | ||||
-rw-r--r-- | examples/IPC_SAP/UPIPE_SAP/ex2.cpp | 45 | ||||
-rw-r--r-- | examples/IPC_SAP/UPIPE_SAP/ex3.cpp | 94 |
4 files changed, 150 insertions, 112 deletions
diff --git a/examples/IPC_SAP/UPIPE_SAP/auto_builtin_ptr.h b/examples/IPC_SAP/UPIPE_SAP/auto_builtin_ptr.h deleted file mode 100644 index b8d82470d58..00000000000 --- a/examples/IPC_SAP/UPIPE_SAP/auto_builtin_ptr.h +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -template <class X> -class auto_builtin_ptr - // = TITLE - // Implements an simple-minded auto_ptr abstraction for builtin types. -{ -public: - // = Initialization and termination methods - auto_builtin_ptr (X *p = 0): p_ (p) {} - ~auto_builtin_ptr (void) { delete [] this->p_; } - - // = Accessor methods. - operator X * (void) const { return this->p_; } - -private: - X *p_; -}; - diff --git a/examples/IPC_SAP/UPIPE_SAP/ex1.cpp b/examples/IPC_SAP/UPIPE_SAP/ex1.cpp index 71cebb90f83..287a778a053 100644 --- a/examples/IPC_SAP/UPIPE_SAP/ex1.cpp +++ b/examples/IPC_SAP/UPIPE_SAP/ex1.cpp @@ -1,9 +1,21 @@ // $Id$ -// Example for using ACE_UPIPE_SAP and ACE_Thread for intra-process -// communication. +// ============================================================================ // -// Author : Gerhard Lenzer and Douglas C. Schmidt +// = LIBRARY +// examples +// +// = FILENAME +// ex1.cpp +// +// = DESCRIPTION +// Example for using <ACE_UPIPE_SAP> and <ACE_Thread> for +// intra-process communication. +// +// = AUTHOR +// Gerhard Lenzer and Douglas C. Schmidt +// +// ============================================================================ #include "ace/Stream.h" #include "ace/UPIPE_Acceptor.h" @@ -13,37 +25,42 @@ ACE_RCSID(UPIPE_SAP, ex1, "$Id$") #if defined (ACE_HAS_THREADS) -// Global thread manager. -static ACE_Thread_Manager thr_mgr; - -//ACE_UPIPE_Manager ltc_mgr; - // Global pattern static ACE_UPIPE_Addr addr ("pattern"); -// peer1 thread. +// peer1 thread entry point. static void * peer1 (void *) { ACE_UPIPE_Stream c_stream; - ACE_DEBUG ((LM_DEBUG, "(%t) peer1 starting connect\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) peer1 starting connect\n")); ACE_UPIPE_Connector con; if (con.connect (c_stream, addr) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) peer1 ACE_UPIPE_Connector failed\n")); + ACE_ERROR ((LM_ERROR, + "(%t) peer1 ACE_UPIPE_Connector failed\n")); + + ACE_Message_Block *mb; + ACE_NEW_RETURN (mb, + new ACE_Message_Block (20), + 0); - ACE_Message_Block *mb = new ACE_Message_Block (20); mb->copy ("hello", 6); if (c_stream.send (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) error peer1 send\n")); + ACE_ERROR ((LM_ERROR, + "(%t) error peer1 send\n")); if (c_stream.recv (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) error peer1 recv\n")); + ACE_ERROR ((LM_ERROR, + "(%t) error peer1 recv\n")); - ACE_DEBUG ((LM_DEBUG, "(%t) peer1 ack is \"%s\"\n", mb->rd_ptr ())); + ACE_ERROR ((LM_ERROR, + "(%t) peer1 ack is \"%s\"\n", + mb->rd_ptr ())); // Free up the memory block. mb->release (); @@ -51,9 +68,10 @@ peer1 (void *) // Now try the send()/recv() interface. char mytext[] = "This string is sent by peer1 as buffer"; - ACE_DEBUG ((LM_DEBUG, "(%t) peer1 sending text\n")); + ACE_ERROR ((LM_ERROR, + "(%t) peer1 sending text\n")); if (c_stream.send (mytext, sizeof mytext) == -1) - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, "(%t) buffer send from peer1 failed\n")); char conbuf[30]; // Buffer to receive response. @@ -63,7 +81,7 @@ peer1 (void *) for (char c = ' '; c != '!'; i++) { if (c_stream.recv (&c, 1) == -1) - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, "(%t) buffer recv from peer1 failed\n")); else conbuf[i] = c; @@ -84,20 +102,26 @@ peer2 (void *) ACE_UPIPE_Stream s_stream; // Spawn a peer1 thread. - if (thr_mgr.spawn (ACE_THR_FUNC (peer1), (void *) 0, - THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 0); + if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (peer1), + (void *) 0, + THR_NEW_LWP | THR_DETACHED) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "spawn"), + 0); - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 starting accept\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) peer2 starting accept\n")); if (acc.accept (s_stream) == -1) - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, "(%t) ACE_UPIPE_Acceptor.accept failed\n")); ACE_Message_Block *mb = 0; if (s_stream.recv (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 recv failed\n")); + ACE_ERROR ((LM_ERROR, + "(%t) peer2 recv failed\n")); ACE_DEBUG ((LM_DEBUG, "(%t) peer2 recv is \"%s\"\n", mb->rd_ptr ())); @@ -106,23 +130,27 @@ peer2 (void *) mb->copy ("thanks", 7); if (s_stream.send (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 send failed\n")); + ACE_ERROR ((LM_ERROR, + "(%t) peer2 send failed\n")); char s_buf[42]; - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 sleeping on recv\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) peer2 sleeping on recv\n")); if (s_stream.recv (s_buf, sizeof s_buf) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 recv failed\n")); + ACE_ERROR ((LM_ERROR, + "(%t) peer2 recv failed\n")); else ACE_DEBUG ((LM_DEBUG, "(%t) peer2 received buffer with \"%s\"\n", s_buf)); - ACE_OS::strcpy (s_buf, "this is the peer2 response!"); + ACE_OS::strcpy (s_buf, + "this is the peer2 response!"); if (s_stream.send (s_buf, 30) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) peer2 send failed\n")); - + ACE_ERROR ((LM_ERROR, + "(%t) peer2 send failed\n")); s_stream.close (); return 0; } @@ -131,10 +159,13 @@ int main (int, char *[]) { // Spawn a peer2 thread. - if (thr_mgr.spawn (ACE_THR_FUNC (peer2), (void *) 0, - THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1); - + if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (peer2), + (void *) 0, + THR_NEW_LWP | THR_DETACHED) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "spawn"), + 1); // Wait for peer2 and peer1 threads to exit. thr_mgr.wait (); return 0; @@ -143,6 +174,8 @@ main (int, char *[]) int main (int, char *[]) { - ACE_ERROR_RETURN ((LM_ERROR, "threads not supported on this platform\n"), -1); + ACE_ERROR_RETURN ((LM_ERROR, + "threads not supported on this platform\n"), + -1); } #endif /* ACE_HAS_THREADS */ diff --git a/examples/IPC_SAP/UPIPE_SAP/ex2.cpp b/examples/IPC_SAP/UPIPE_SAP/ex2.cpp index 7bd48ba2ec4..5ed7fc17df5 100644 --- a/examples/IPC_SAP/UPIPE_SAP/ex2.cpp +++ b/examples/IPC_SAP/UPIPE_SAP/ex2.cpp @@ -1,14 +1,26 @@ // $Id$ -// Example for using ACE_UPIPE_SAP and ACE_Thread for intra-process -// communication. +// ============================================================================ // -// Author : Gerhard Lenzer and Douglas C. Schmidt +// = LIBRARY +// examples +// +// = FILENAME +// ex2.cpp +// +// = DESCRIPTION +// Example for using <ACE_UPIPE_SAP> and <ACE_Thread> for +// intra-process communication. +// +// = AUTHOR +// Gerhard Lenzer and Douglas C. Schmidt +// +// ============================================================================ -#include <fstream.h> #include "ace/UPIPE_Connector.h" #include "ace/UPIPE_Acceptor.h" -#include "auto_builtin_ptr.h" +#include "ace/Auto_Ptr.h" +#include <fstream.h> ACE_RCSID(UPIPE_SAP, ex2, "$Id$") @@ -18,8 +30,8 @@ ACE_RCSID(UPIPE_SAP, ex2, "$Id$") static ACE_Thread_Manager thr_mgr; // Data for testsuite. -int size = 0; -int iterations = 0; +static int size = 0; +static int iterations = 0; static void * supplier (void *) @@ -28,7 +40,7 @@ supplier (void *) ACE_UPIPE_Addr c_addr ("pattern"); - auto_builtin_ptr <char> mybuf = new char[size]; + ACE_Auto_Basic_Ptr <char> mybuf = new char[size]; for (int i = 0; i < size; i++) mybuf[i] = 'a'; @@ -39,7 +51,7 @@ supplier (void *) ACE_UPIPE_Connector con; if (con.connect (s_stream, c_addr) == -1) - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_UPIPE_Acceptor.connect failed")); @@ -56,7 +68,6 @@ supplier (void *) (ACE_Message_Block *) 0, mybuf), 0); - if (s_stream.send (mb_p) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%t) %p\n", @@ -114,7 +125,7 @@ consumer (void *) "(%t) consumer starting accept\n")); if (acc.accept (c_stream) == -1) - ACE_DEBUG ((LM_DEBUG, + ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_UPIPE_Acceptor.accept failed")); @@ -155,25 +166,23 @@ main (int argc, char *argv[]) "%p\n", "spawn"), 1); - // Wait for producer and consumer threads to exit. thr_mgr.wait (); return 0; } - #else int main (int, char *[]) { - ACE_ERROR ( (LM_ERROR, "threads not supported on this platform\n")); - return 0; + ACE_ERROR_RETURN ((LM_ERROR, + "threads not supported on this platform\n"), + 0); } #endif /* ACE_HAS_THREADS */ - #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_builtin_ptr <char>; +template class ACE_Auto_Basic_Ptr <char>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_builtin_ptr <char> +#pragma instantiate ACE_Auto_Basic_Ptr <char> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/IPC_SAP/UPIPE_SAP/ex3.cpp b/examples/IPC_SAP/UPIPE_SAP/ex3.cpp index eaa645d0c44..7492d218d61 100644 --- a/examples/IPC_SAP/UPIPE_SAP/ex3.cpp +++ b/examples/IPC_SAP/UPIPE_SAP/ex3.cpp @@ -1,16 +1,27 @@ // $Id$ -// Example for using ACE_UPIPE_SAP and ACE_Thread for intra-process -// communication. This example uses char buffers as input/output -// interface to the ACE_UPIPE_Stream +// ============================================================================ // -// Authors: Gerhard Lenzer and Prashant Jain. - -#include <fstream.h> +// = LIBRARY +// examples +// +// = FILENAME +// ex3.cpp +// +// = DESCRIPTION +// Example for using <ACE_UPIPE_SAP> and <ACE_Thread> for intra-process +// communication. This example uses char buffers as input/output +// interface to the <ACE_UPIPE_Stream>. +// +// = AUTHOR +// Gerhard Lenzer and Prashant Jain. +// +// ============================================================================ #include "ace/UPIPE_Connector.h" #include "ace/UPIPE_Acceptor.h" -#include "auto_builtin_ptr.h" +#include "ace/Auto_Ptr.h" +#include <fstream.h> ACE_RCSID(UPIPE_SAP, ex3, "$Id$") @@ -20,8 +31,8 @@ ACE_RCSID(UPIPE_SAP, ex3, "$Id$") static ACE_Thread_Manager thr_mgr; // Data for testsuite. -int size = 0; -int iterations = 0; +static int size = 0; +static int iterations = 0; static void * supplier (void *) @@ -31,32 +42,31 @@ supplier (void *) ACE_UPIPE_Connector con; - ACE_DEBUG ((LM_DEBUG, "(%t) supplier starting connect thread\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) supplier starting connect thread\n")); if (con.connect (s_stream, c_addr) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", + ACE_ERROR ((LM_ERROR, + "(%t) %p\n", "ACE_UPIPE_Acceptor.connect failed")); - auto_builtin_ptr <char> mybuf = new char[size]; + ACE_Auto_Basic_Ptr <char> mybuf = new char[size]; for (int i = 0; i < size; i++) mybuf[i] = 'a'; for (int j = 0; j < iterations; j++) if (s_stream.send (mybuf, size) == -1) - { - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", "send failed")); - return 0; - } + ACE_ERROR_RETURN ((LM_ERROR, + "(%t) %p\n", "send failed"), + 0); // Insert a 0-sized message block to signal the other side to shut // down. if (s_stream.send (new ACE_Message_Block ((size_t) 0)) == -1) - { - cout << "error put" << endl; - return 0; - } - + ACE_ERROR_RETURN ((LM_ERROR, + "(%t) %p\n", "error put"), + 0); s_stream.close (); return 0; } @@ -70,21 +80,25 @@ consumer (void *) // Accept will wait up to 4 seconds ACE_UPIPE_Acceptor acc (serv_addr); - ACE_DEBUG ((LM_DEBUG, "(%t) consumer spawning the supplier thread\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) consumer spawning the supplier thread\n")); // Spawn the supplier thread. if (thr_mgr.spawn (ACE_THR_FUNC (supplier), (void *) 0, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 0); - - ACE_DEBUG ((LM_DEBUG, "(%t) consumer starting accept\n")); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "spawn"), + 0); + ACE_DEBUG ((LM_DEBUG, + "(%t) consumer starting accept\n")); if (acc.accept (c_stream) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", + ACE_ERROR ((LM_ERROR, "(%t) %p\n", "ACE_UPIPE_Acceptor.accept failed")); // Ensure deletion upon exit. - auto_builtin_ptr <char> mybuf = new char[size]; + ACE_Auto_Basic_Ptr <char> mybuf = new char[size]; time_t currsec; ACE_OS::time (&currsec); @@ -98,11 +112,11 @@ consumer (void *) result = c_stream.recv (mybuf, size); if (result <= 0) break; - // ACE_DEBUG ((LM_DEBUG, "(%t) %d: %s\n", size, (char *) mybuf)); } if (result == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", "recv failed")); + ACE_ERROR ((LM_ERROR, + "(%t) %p\n", "recv failed")); ACE_OS::time (&currsec); time_t secs = (time_t) currsec - start; @@ -110,8 +124,9 @@ consumer (void *) ACE_DEBUG ((LM_DEBUG, "(%t) Transferred %d blocks of size %d\n" "The program ran %d seconds\n", - blocks, size, secs)); - + blocks, + size, + secs)); c_stream.close (); return 0; } @@ -125,8 +140,10 @@ main (int argc, char *argv[]) // Spawn the thread. if (thr_mgr.spawn (ACE_THR_FUNC (consumer), (void *) 0, THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR_RETURN ( (LM_ERROR, "%p\n", "spawn"), 1); - + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "spawn"), + 1); // Wait for producer and consumer threads to exit. thr_mgr.wait (); return 0; @@ -135,15 +152,14 @@ main (int argc, char *argv[]) int main (int, char *[]) { - ACE_ERROR ( (LM_ERROR, "threads not supported on this platform\n")); - return 0; + ACE_ERROR_RETURN ((LM_ERROR, + "threads not supported on this platform\n"), + 0); } #endif /* ACE_HAS_THREADS */ - #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_builtin_ptr <char>; +template class ACE_Auto_Basic_Ptr <char>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_builtin_ptr <char> +#pragma instantiate ACE_Auto_Basic_Ptr <char> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - |