diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-07-16 22:14:12 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-07-16 22:14:12 +0000 |
commit | aa40a4d37fd037fdc3f53d033e50c43f0df3b7ba (patch) | |
tree | b12cbcdc1d51af59f40438a30ef807fc07251cac | |
parent | 990b33725cb865eda58f583ad5e52965b4e97b9d (diff) | |
download | ATCD-aa40a4d37fd037fdc3f53d033e50c43f0df3b7ba.tar.gz |
*** empty log message ***
8 files changed, 77 insertions, 50 deletions
diff --git a/examples/IPC_SAP/UPIPE_SAP/ex2.cpp b/examples/IPC_SAP/UPIPE_SAP/ex2.cpp index 6efddd0ffed..8fac8c3ffca 100644 --- a/examples/IPC_SAP/UPIPE_SAP/ex2.cpp +++ b/examples/IPC_SAP/UPIPE_SAP/ex2.cpp @@ -1,15 +1,14 @@ -// Example for using ACE_UPIPE_SAP and ACE_Thread for intra-process // $Id$ +// 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 <fstream.h> #if defined (ACE_HAS_THREADS) @@ -32,38 +31,48 @@ supplier (void *) for (int i = 0; i < size; i++) mybuf[i] = 'a'; - ACE_DEBUG ((LM_DEBUG, "(%t) supplier starting connect thread\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) supplier starting connect thread\n")); ACE_UPIPE_Connector con; if (con.connect (s_stream, c_addr) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", + ACE_DEBUG ((LM_DEBUG, + "(%t) %p\n", "ACE_UPIPE_Acceptor.connect failed")); - // Test asynchronisity. - s_stream.enable (SIGIO); + // Test asynchronicity (the "acausal principle" ;-)). + s_stream.enable (ACE_SIGIO); + + ACE_Message_Block *mb_p; for (int j = 0; j < iterations; j++) { - ACE_Message_Block *mb_p = - new ACE_Message_Block (size, ACE_Message_Block::MB_DATA, - (ACE_Message_Block *) 0, mybuf); + ACE_NEW_RETURN (mb_p, + ACE_Message_Block (size, + ACE_Message_Block::MB_DATA, + (ACE_Message_Block *) 0, + mybuf), + 0); if (s_stream.send (mb_p) == -1) - { - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", "send failed")); - return 0; - } + ACE_ERROR_RETURN ((LM_ERROR, + "(%t) %p\n", + "send failed"), + 0); } + ACE_NEW_RETURN (mb_p, + ACE_Message_Block ((size_t) 0), + 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; - } - + if (s_stream.send (mb_p) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%t) %p\n", + "send failed"), + 0); s_stream.close (); return 0; } @@ -77,27 +86,37 @@ consumer (void *) int wm = size * iterations; - if (c_stream.control (ACE_IO_Cntl_Msg::SET_HWM, &wm) == -1) - ACE_DEBUG ((LM_DEBUG, "set HWM failed\n")); + if (c_stream.control (ACE_IO_Cntl_Msg::SET_HWM, + &wm) == -1) + ACE_DEBUG ((LM_DEBUG, + "set HWM failed\n")); ACE_UPIPE_Addr serv_addr ("pattern"); - ACE_UPIPE_Acceptor acc (serv_addr); // accept will wait up to 4 seconds + // 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, + 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_ERROR_RETURN ((LM_ERROR, + "%p\n", + "spawn"), + 0); - ACE_DEBUG ((LM_DEBUG, "(%t) consumer starting accept\n")); + ACE_DEBUG ((LM_DEBUG, + "(%t) consumer starting accept\n")); if (acc.accept (c_stream) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) %p\n", + ACE_DEBUG ((LM_DEBUG, + "(%t) %p\n", "ACE_UPIPE_Acceptor.accept failed")); - // time measurement + // Time measurement. time_t currsec; ACE_OS::time (&currsec); time_t start = (time_t) currsec; @@ -116,7 +135,6 @@ consumer (void *) "(%t) Transferred %d blocks of size %d\n" "The program ran %d seconds\n", received_messages, size, secs)); - c_stream.close (); return 0; } @@ -128,9 +146,13 @@ main (int argc, char *argv[]) iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : 16; // Spawn the two threads. - if (thr_mgr.spawn (ACE_THR_FUNC (consumer), (void *) 0, + 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 (); diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.i b/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.i index 14de88bce6e..0e42f033c07 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.i @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - #include "ace/Get_Opt.h" ACE_INLINE @@ -19,7 +18,7 @@ Handle_Broadcast::open (const ACE_INET_Addr &r, int async) { if (this->ACE_SOCK_Dgram::open (r) == -1) return -1; - else if (async && ACE_SOCK_Dgram::enable (SIGIO) == -1) + else if (async && ACE_SOCK_Dgram::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.i b/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.i index 735ca3fd066..0574138cc2e 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.i @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - #include "ace/Get_Opt.h" ACE_INLINE @@ -14,7 +13,7 @@ Handle_L_CODgram::open (const ACE_UNIX_Addr &suad, int async) { if (this->ACE_LSOCK_CODgram::open (ACE_Addr::sap_any, suad) == -1) return -1; - else if (async && this->ACE_LSOCK_CODgram::enable (SIGIO) == -1) + else if (async && this->ACE_LSOCK_CODgram::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.i b/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.i index adbb9be45e5..0fca5d4d2d5 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.i @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - #include "ace/Get_Opt.h" ACE_INLINE @@ -14,7 +13,7 @@ Handle_L_Dgram::open (const ACE_UNIX_Addr &suad, int async) { if (this->ACE_LSOCK_Dgram::open (suad) == -1) return -1; - else if (async && this->ACE_LSOCK_Dgram::enable (SIGIO) == -1) + else if (async && this->ACE_LSOCK_Dgram::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.i b/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.i index b8c93ff25f5..4d481fb4670 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.i @@ -30,7 +30,7 @@ Handle_L_Pipe::open (const ACE_UNIX_Addr &suap, int async) { if (this->ACE_LSOCK_Acceptor::open (suap) == -1) return -1; - else if (async && this->ACE_LSOCK_Acceptor::enable (SIGIO) == -1) + else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.i b/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.i index d3d4933ee69..7d36a7d1a32 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.i @@ -21,7 +21,7 @@ Handle_L_Stream::open (const ACE_UNIX_Addr &suas, { if (this->ACE_LSOCK_Acceptor::open (suas) == -1) return -1; - else if (async && this->ACE_LSOCK_Acceptor::enable (SIGIO) == -1) + else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.i b/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.i index 1112125956f..735c5291f75 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.i @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - #include "ace/Get_Opt.h" ACE_INLINE @@ -14,7 +13,7 @@ Handle_R_Dgram::open (const ACE_INET_Addr &r, int async) { if (this->ACE_SOCK_Dgram::open (r) == -1) return -1; - else if (async && this->ACE_SOCK_Dgram::enable (SIGIO) == -1) + else if (async && this->ACE_SOCK_Dgram::enable (ACE_SIGIO) == -1) return -1; else return 0; diff --git a/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.i b/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.i index 5b3cc84e1c3..3f6b3cfebc1 100644 --- a/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.i +++ b/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.i @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - #include "ace/Get_Opt.h" #include "ace/WFMO_Reactor.h" @@ -17,7 +16,7 @@ Handle_R_Stream::open (const ACE_INET_Addr &sia, int async) { if (this->ACE_SOCK_Acceptor::open (sia) == -1) return -1; - else if (async && this->ACE_SOCK_Acceptor::enable (SIGIO) == -1) + else if (async && this->ACE_SOCK_Acceptor::enable (ACE_SIGIO) == -1) return -1; else return 0; @@ -26,13 +25,17 @@ Handle_R_Stream::open (const ACE_INET_Addr &sia, int async) ACE_INLINE int Handle_R_Stream::info (char **strp, size_t length) const { - char buf[BUFSIZ]; + char buf[BUFSIZ]; ACE_INET_Addr sa; if (this->get_local_addr (sa) == -1) return -1; - ACE_OS::sprintf (buf, "%d/%s %s", sa.get_port_number (), "tcp", "# tests remote stream\n"); + ACE_OS::sprintf (buf, + "%d/%s %s", + sa.get_port_number (), + "tcp", + "# tests remote stream\n"); if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) return -1; @@ -59,9 +62,12 @@ Handle_R_Stream::init (int argc, char *argv[]) if (this->open (sis) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); + else if (ACE_Reactor::instance ()->register_handler (this, ACE_Event_Handler::ACCEPT_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "registering service with ACE_Reactor\n"), -1); + ACE_ERROR_RETURN ((LM_ERROR, + "registering service with ACE_Reactor\n"), + -1); return 0; } @@ -89,7 +95,8 @@ Handle_R_Stream::handle_input (int) // created handle. This is because the newly created handle will // inherit the properties of the listen handle, including its event // associations. - int reset_new_handle = ACE_Reactor::instance ()->uses_event_associations (); + int reset_new_handle = + ACE_Reactor::instance ()->uses_event_associations (); if (this->accept (this->new_remote_stream, // stream 0, // remote address @@ -107,8 +114,10 @@ Handle_R_Stream::handle_input (int) if (this->new_remote_stream.get_remote_addr (sa) == -1) return -1; - ACE_DEBUG ((LM_INFO, "accepted from host %s at port %d\n", - sa.get_host_name (), sa.get_port_number ())); + ACE_DEBUG ((LM_INFO, + "accepted from host %s at port %d\n", + sa.get_host_name (), + sa.get_port_number ())); ACE_OS::puts ("----------------------------------------"); |