diff options
Diffstat (limited to 'examples/C++NPv1')
21 files changed, 0 insertions, 1642 deletions
diff --git a/examples/C++NPv1/.cvsignore b/examples/C++NPv1/.cvsignore deleted file mode 100644 index 7735c154a0c..00000000000 --- a/examples/C++NPv1/.cvsignore +++ /dev/null @@ -1,14 +0,0 @@ -RTTPC_logging_server -RTTPC_logging_server -iterative_logging_server -iterative_logging_server -logging_client -logging_client -ppc_logging_server -ppc_logging_server -reactive_logging_server -reactive_logging_server -reactive_logging_server_ex -reactive_logging_server_ex -tpc_logging_server -tpc_logging_server diff --git a/examples/C++NPv1/C++NPv1.mpc b/examples/C++NPv1/C++NPv1.mpc deleted file mode 100644 index f7d3f626ff4..00000000000 --- a/examples/C++NPv1/C++NPv1.mpc +++ /dev/null @@ -1,70 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project(*Iterative_Logging_Server) : aceexe { - avoids += uses_wchar - exename = iterative_logging_server - Source_Files { - Iterative_Logging_Server.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*Logging_Client) : aceexe { - avoids += uses_wchar - exename = logging_client - Source_Files { - Logging_Client.cpp - } -} - -project(*PPC_Logging_Server) : aceexe { - avoids += uses_wchar - exename = ppc_logging_server - Source_Files { - Process_Per_Connection_Logging_Server.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*Reactive_Logging_Server) : aceexe { - avoids += uses_wchar - exename = reactive_logging_server - Source_Files { - Reactive_Logging_Server.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*Reactive_Logging_Server_Ex) : aceexe { - avoids += uses_wchar - exename = reactive_logging_server_ex - Source_Files { - Reactive_Logging_Server_Ex.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*RTTPC_Logging_Server) : aceexe { - avoids += uses_wchar - exename = RTTPC_logging_server - Source_Files { - RT_Thread_Per_Connection_Logging_Server.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*TPC_Logging_Server) : aceexe { - avoids += uses_wchar - exename = tpc_logging_server - Source_Files { - Thread_Per_Connection_Logging_Server.cpp - Logging_Server.cpp - Logging_Handler.cpp - } -} diff --git a/examples/C++NPv1/Iterative_Logging_Server.cpp b/examples/C++NPv1/Iterative_Logging_Server.cpp deleted file mode 100644 index f4c28f08da7..00000000000 --- a/examples/C++NPv1/Iterative_Logging_Server.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Log_Msg.h" -#include "Iterative_Logging_Server.h" - -int main (int argc, char *argv[]) -{ - Iterative_Logging_Server server; - - if (server.run (argc, argv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - return 0; -} diff --git a/examples/C++NPv1/Iterative_Logging_Server.h b/examples/C++NPv1/Iterative_Logging_Server.h deleted file mode 100644 index c58edc16ecb..00000000000 --- a/examples/C++NPv1/Iterative_Logging_Server.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _ITERATIVE_LOGGING_SERVER_H -#define _ITERATIVE_LOGGING_SERVER_H - -#include "ace/FILE_IO.h" -#include "ace/INET_Addr.h" -#include "ace/Log_Msg.h" - -#include "Logging_Handler.h" -#include "Logging_Server.h" - -class ACE_SOCK_Stream; - -class Iterative_Logging_Server : public Logging_Server -{ -protected: - ACE_FILE_IO log_file_; - Logging_Handler logging_handler_; - -public: - Iterative_Logging_Server () : logging_handler_ (log_file_) {} - - virtual ~Iterative_Logging_Server () { log_file_.close (); } - - Logging_Handler &logging_handler () { return logging_handler_; } - -protected: - // Override inherited open() from Logging_Server - virtual int open (u_short port) { - if (make_log_file (log_file_) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "make_log_file()"), -1); - return Logging_Server::open (port); - } - - virtual int handle_connections () { - ACE_INET_Addr logging_peer_addr; - - if (acceptor ().accept (logging_handler_.peer (), - &logging_peer_addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "acceptor.accept()"), -1); - - ACE_DEBUG ((LM_DEBUG, "Accepted connection from %s\n", - logging_peer_addr.get_host_name ())); - return 0; - } - - virtual int handle_data (ACE_SOCK_Stream *) { - while (logging_handler_.log_record () != -1) - continue; - - logging_handler_.close (); // Close the socket handle. - return 0; - } - -}; - -#endif /* _ITERATIVE_LOGGING_SERVER_H */ diff --git a/examples/C++NPv1/Logging_Client.cpp b/examples/C++NPv1/Logging_Client.cpp deleted file mode 100644 index 614b557c551..00000000000 --- a/examples/C++NPv1/Logging_Client.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_NS_sys_time.h" -#include "ace/CDR_Stream.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Stream.h" -#include "ace/Log_Msg.h" -#include "ace/Log_Record.h" -#include "ace/OS_NS_unistd.h" - -// FUZZ: disable check_for_streams_include -#include "ace/streams.h" - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0)) -# include <stdio.h> -#else -# include <string> -#endif - -int operator<< (ACE_OutputCDR &cdr, const ACE_Log_Record &log_record) -{ - size_t msglen = log_record.msg_data_len (); - // The ACE_Log_Record::msg_data () function is non-const, since it - // returns a non-const pointer to internal class members. Since we - // know that no members are modified here, we can safely const_cast - // the log_record parameter without violating the interface - // contract. - ACE_Log_Record &nonconst_record = (const_cast<ACE_Log_Record&> (log_record)); - // Insert each field from <log_record> into the output CDR stream. - cdr << ACE_CDR::Long (log_record.type ()); - cdr << ACE_CDR::Long (log_record.pid ()); - cdr << ACE_CDR::Long (log_record.time_stamp ().sec ()); - cdr << ACE_CDR::Long (log_record.time_stamp ().usec ()); - cdr << ACE_CDR::ULong (msglen); - cdr.write_char_array (nonconst_record.msg_data (), msglen); - return cdr.good_bit (); -} - - -class Logging_Client { -private: - ACE_SOCK_Stream logging_peer_; - -public: - ACE_SOCK_Stream &peer () { return logging_peer_; } - - int send (const ACE_Log_Record &log_record) { - // Serialize the log record using a CDR stream, allocate - // enough space for the complete <ACE_Log_Record>. - const size_t max_payload_size = - 4 // type() - + 8 // timestamp - + 4 // process id - + 4 // data length - + ACE_Log_Record::MAXLOGMSGLEN // data - + ACE_CDR::MAX_ALIGNMENT; // padding; - - // Insert contents of <log_record> into payload stream. - ACE_OutputCDR payload (max_payload_size); - payload << log_record; - - // Get the number of bytes used by the CDR stream. - ACE_CDR::ULong length = payload.total_length (); - - // Send a header so the receiver can determine the byte - // order and size of the incoming CDR stream. - ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8); - header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER); - - // Store the size of the payload that follows - header << ACE_CDR::ULong (length); - // Use an iovec to send both buffer and payload simultaneously. - iovec iov[2]; - iov[0].iov_base = header.begin ()->rd_ptr (); - iov[0].iov_len = 8; - iov[1].iov_base = payload.begin ()->rd_ptr (); - iov[1].iov_len = length; - - // Send header and payload efficiently using "gather-write". - return logging_peer_.sendv_n (iov, 2); - } - - ~Logging_Client () { logging_peer_.close (); } -}; - - -int main (int argc, char *argv[]) -{ - u_short logger_port = argc > 1 ? atoi (argv[1]) : 0; - const char *logger_host = - argc > 2 ? argv[2] : ACE_DEFAULT_SERVER_HOST; - int result; - - ACE_INET_Addr server_addr; - - if (logger_port != 0) - result = server_addr.set (logger_port, logger_host); - else - result = server_addr.set ("ace_logger", logger_host); - if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR, "lookup %s, %p\n", - logger_port == 0 ? "ace_logger" : argv[1], - logger_host), 1); - - ACE_SOCK_Connector connector; - Logging_Client logging_client; - - if (connector.connect (logging_client.peer (), server_addr) < 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connect()"), 1); - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0)) - for (;;) { - char user_input[ACE_Log_Record::MAXLOGMSGLEN]; - if (!gets (user_input)) - break; - - ACE_Time_Value now (ACE_OS::gettimeofday ()); - ACE_Log_Record log_record (LM_INFO, now, ACE_OS::getpid ()); - log_record.msg_data (user_input); - if (logging_client.send (log_record) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", "logging_client.send()"), 1); - } -#else - - // Limit the number of characters read on each record - cin.width (ACE_Log_Record::MAXLOGMSGLEN); - - for (;;) { - -#if defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) && (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB == 0) - string user_input; - getline (cin, user_input, '\n'); -#else - std::string user_input; - std::getline (cin, user_input, '\n'); - -#endif - - if (!cin || cin.eof ()) break; - - ACE_Time_Value now (ACE_OS::gettimeofday ()); - ACE_Log_Record log_record (LM_INFO, now, ACE_OS::getpid ()); - log_record.msg_data (user_input.c_str ()); - if (logging_client.send (log_record) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", "logging_client.send()"), 1); - } -#endif - - return 0; // Logging_Client destructor closes TCP connection. -} diff --git a/examples/C++NPv1/Logging_Handler.cpp b/examples/C++NPv1/Logging_Handler.cpp deleted file mode 100644 index dc1d56b3190..00000000000 --- a/examples/C++NPv1/Logging_Handler.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/ACE.h" -#include "ace/CDR_Stream.h" -#include "ace/INET_Addr.h" -#include "ace/Log_Record.h" -#include "ace/Message_Block.h" - -#include "Logging_Handler.h" - -// FUZZ: disable check_for_streams_include -#include "ace/streams.h" - -#include "ace/os_include/os_netdb.h" - -int operator>> (ACE_InputCDR &cdr, ACE_Log_Record &log_record) -{ - ACE_CDR::Long type; - ACE_CDR::Long pid; - ACE_CDR::Long sec, usec; - ACE_CDR::ULong buffer_len; - - // Extract each field from input CDR stream into <log_record>. - if ((cdr >> type) && (cdr >> pid) && (cdr >> sec) && (cdr >> usec) - && (cdr >> buffer_len)) { - ACE_TCHAR log_msg[ACE_Log_Record::MAXLOGMSGLEN+1]; - log_record.type (type); - log_record.pid (pid); - log_record.time_stamp (ACE_Time_Value (sec, usec)); - cdr.read_char_array (log_msg, buffer_len); - log_msg[buffer_len] = '\0'; - log_record.msg_data (log_msg); - } - return cdr.good_bit (); -} - - -int Logging_Handler::recv_log_record (ACE_Message_Block *&mblk) -{ - // Put <logging_peer>'s hostname in new message block. - ACE_INET_Addr peer_addr; - logging_peer_.get_remote_addr (peer_addr); - mblk = new ACE_Message_Block (MAXHOSTNAMELEN + 1); - peer_addr.get_host_name (mblk->wr_ptr (), MAXHOSTNAMELEN); - mblk->wr_ptr (strlen (mblk->wr_ptr ()) + 1); // Go past name - - // Allocate a message block for the payload; initially at least - // large enough to hold the header, but needs some room for - // alignment. - ACE_Message_Block *payload = - new ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE); - // Align the Message Block for a CDR stream - ACE_CDR::mb_align (payload); - if (logging_peer_.recv_n (payload->wr_ptr (), 8) == 8) { - payload->wr_ptr (8); // Reflect addition of 8 bytes - - // Create a CDR stream to parse the 8-byte header. - ACE_InputCDR cdr (payload); - - // Extract the byte-order and use helper methods to - // disambiguate octet, booleans, and chars. - ACE_CDR::Boolean byte_order; - cdr >> ACE_InputCDR::to_boolean (byte_order); - - // Set the byte-order on the stream... - cdr.reset_byte_order (byte_order); - - // Extract the length - ACE_CDR::ULong length; - cdr >> length; - - // Ensure there's sufficient room for log record payload. - ACE_CDR::grow (payload, 8 + ACE_CDR::MAX_ALIGNMENT + length); - - // Use <recv_n> to obtain the contents. - if (logging_peer_.recv_n (payload->wr_ptr (), length) > 0) { - payload->wr_ptr (length); // Reflect additional bytes - // Chain the payload to mblk via the contination field. - mblk->cont (payload); - return length; - } - } - // Error cases end up here, so we need to release the memory to - // prevent a leak. - payload->release (); - payload = 0; - mblk->release (); - mblk = 0; - return -1; -} - - -int Logging_Handler::write_log_record (ACE_Message_Block *mblk) -{ - // Peer hostname is in the <mblk> and the log record data - // is in its continuation. - if (log_file_.send_n (mblk) == -1) - return -1; - if (ACE::debug ()) { - // Build a CDR stream from the log record data. - ACE_InputCDR cdr (mblk->cont ()); - ACE_CDR::Boolean byte_order; - ACE_CDR::ULong length; - // Extract the byte-order and length, ending up at the start - // of the log record itself. Use the byte order to properly - // set the CDR stream for extracting the contents. - cdr >> ACE_InputCDR::to_boolean (byte_order); - cdr.reset_byte_order (byte_order); - cdr >> length; - ACE_Log_Record log_record; - cdr >> log_record; // Finally extract the <ACE_log_record>. - log_record.print (mblk->rd_ptr (), 1, cerr); - } - return mblk->total_length (); -} - - -int Logging_Handler::log_record () -{ - ACE_Message_Block *mblk = 0; - if (recv_log_record (mblk) == -1) - return -1; - else { - int result = write_log_record (mblk); - mblk->release (); // Free up the contents. - return result == -1 ? -1 : 0; - } -} diff --git a/examples/C++NPv1/Logging_Handler.h b/examples/C++NPv1/Logging_Handler.h deleted file mode 100644 index 80de5ebac51..00000000000 --- a/examples/C++NPv1/Logging_Handler.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_HANDLER_H -#define _LOGGING_HANDLER_H - -#include "ace/FILE_IO.h" -#include "ace/SOCK_Stream.h" - -class ACE_Message_Block; - -class Logging_Handler -{ -protected: - ACE_FILE_IO &log_file_; // Reference to a log file. - - ACE_SOCK_Stream logging_peer_; // Connected to the client. - -public: - // Initialization and termination methods. - Logging_Handler (ACE_FILE_IO &log_file): log_file_ (log_file) {} - Logging_Handler (ACE_FILE_IO &log_file, - ACE_HANDLE handle): log_file_ (log_file) - { logging_peer_.set_handle (handle); } - Logging_Handler (ACE_FILE_IO &log_file, - const ACE_SOCK_Stream &logging_peer) - : log_file_ (log_file), logging_peer_ (logging_peer) {} - int close () { return logging_peer_.close (); } - - // Receive one log record from a connected client. Returns - // length of record on success and <mblk> contains the - // hostname, <mblk->cont()> contains the log record header - // (the byte order and the length) and the data. Returns -1 on - // failure or connection close. - int recv_log_record (ACE_Message_Block *&log_record); - - // Write one record to the log file. The <mblk> contains the - // hostname and the <mblk->cont> contains the log record. - // Returns length of record written on success, or -1 on failure. - int write_log_record (ACE_Message_Block *log_record); - - // Log one record by calling <recv_log_record> and - // <write_log_record>. Returns 0 on success and -1 on failure. - int log_record (); - - // Accessor method. - ACE_SOCK_Stream &peer () { return logging_peer_; } -}; - -#endif /* _LOGGING_HANDLER_H */ diff --git a/examples/C++NPv1/Logging_Server.cpp b/examples/C++NPv1/Logging_Server.cpp deleted file mode 100644 index c685412c769..00000000000 --- a/examples/C++NPv1/Logging_Server.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/FILE_Addr.h" -#include "ace/FILE_Connector.h" -#include "ace/FILE_IO.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Stream.h" -#include "Logging_Server.h" -#include "ace/OS_NS_string.h" -#include "ace/os_include/os_netdb.h" - -int Logging_Server::run (int argc, char *argv[]) -{ - if (open (argc > 1 ? atoi (argv[1]) : 0) == -1) - return -1; - - for (;;) { - if (wait_for_multiple_events () == -1) - return -1; - if (handle_connections () == -1) - return -1; - if (handle_data () == -1) - return -1; - } - - return 0; -} - - -int Logging_Server::open (u_short logger_port) -{ - ACE_INET_Addr server_addr; - int result; - - if (logger_port != 0) - result = server_addr.set (logger_port, - (ACE_UINT32) INADDR_ANY); - else - result = server_addr.set ("ace_logger", - (ACE_UINT32) INADDR_ANY); - if (result == -1) return -1; - - // Start listening, enable reuse of listen address for quick restarts. - return acceptor_.open (server_addr, 1); -} - - -int Logging_Server::make_log_file (ACE_FILE_IO &logging_file, - ACE_SOCK_Stream *logging_peer) -{ - char filename[MAXHOSTNAMELEN + sizeof (".log")]; - - if (logging_peer != 0) { // Use client's hostname as log file name. - ACE_INET_Addr logging_peer_addr; - logging_peer->get_remote_addr (logging_peer_addr); - logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN); - ACE_OS::strcat (filename, ".log"); - } - else - ACE_OS::strcpy (filename, "logging_server.log"); - - ACE_FILE_Connector connector; - return connector.connect (logging_file, - ACE_FILE_Addr (filename), - 0, // No timeout. - ACE_Addr::sap_any, // Ignored. - 0, // Don't try to reuse the addr. - O_RDWR|O_CREAT|O_APPEND, - ACE_DEFAULT_FILE_PERMS); -} diff --git a/examples/C++NPv1/Logging_Server.h b/examples/C++NPv1/Logging_Server.h deleted file mode 100644 index 1fd03bac775..00000000000 --- a/examples/C++NPv1/Logging_Server.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_SERVER_H -#define _LOGGING_SERVER_H - -#include "ace/FILE_IO.h" -#include "ace/SOCK_Acceptor.h" - -class ACE_SOCK_Stream; - -class Logging_Server -{ -public: - // Template Method that runs logging server's event loop. - virtual int run (int argc, char *argv[]); - -protected: - // The following four methods are ``hooks'' that can be - // overridden by subclasses. - virtual int open (u_short port = 0); - virtual int wait_for_multiple_events () { return 0; } - virtual int handle_connections () = 0; - virtual int handle_data (ACE_SOCK_Stream * = 0) = 0; - - // The following helper method can be used by the hook methods. - int make_log_file (ACE_FILE_IO &, ACE_SOCK_Stream * = 0); - - // Close the socket endpoint. - virtual ~Logging_Server () { acceptor_.close (); } - - // Accessor. - ACE_SOCK_Acceptor &acceptor () { return acceptor_; } - -private: - ACE_SOCK_Acceptor acceptor_; // Socket acceptor endpoint. -}; - -#endif /* _LOGGING_SERVER_H */ diff --git a/examples/C++NPv1/Makefile.am b/examples/C++NPv1/Makefile.am deleted file mode 100644 index e9312ab4b33..00000000000 --- a/examples/C++NPv1/Makefile.am +++ /dev/null @@ -1,178 +0,0 @@ -## Process this file with automake to create Makefile.in -## -## $Id$ -## -## This file was generated by MPC. Any changes made directly to -## this file will be lost the next time it is generated. -## -## MPC Command: -## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu - -ACE_BUILDDIR = $(top_builddir) -ACE_ROOT = $(top_srcdir) - -noinst_PROGRAMS = -## Makefile.C++NPv1_Iterative_Logging_Server.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += iterative_logging_server - -iterative_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -iterative_logging_server_SOURCES = \ - Iterative_Logging_Server.cpp \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - Iterative_Logging_Server.h \ - Logging_Handler.h \ - Logging_Server.h - -iterative_logging_server_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_Logging_Client.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += logging_client - -logging_client_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -logging_client_SOURCES = \ - Logging_Client.cpp \ - Iterative_Logging_Server.h \ - Logging_Handler.h \ - Logging_Server.h \ - Process_Per_Connection_Logging_Server.h \ - RT_Thread_Per_Connection_Logging_Server.h \ - Reactive_Logging_Server.h \ - Reactive_Logging_Server_Ex.h \ - Thread_Per_Connection_Logging_Server.h - -logging_client_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_PPC_Logging_Server.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += ppc_logging_server - -ppc_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -ppc_logging_server_SOURCES = \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - Process_Per_Connection_Logging_Server.cpp \ - Logging_Handler.h \ - Logging_Server.h \ - Process_Per_Connection_Logging_Server.h - -ppc_logging_server_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_RTTPC_Logging_Server.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += RTTPC_logging_server - -RTTPC_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -RTTPC_logging_server_SOURCES = \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - RT_Thread_Per_Connection_Logging_Server.cpp \ - Logging_Handler.h \ - Logging_Server.h \ - RT_Thread_Per_Connection_Logging_Server.h - -RTTPC_logging_server_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_Reactive_Logging_Server.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += reactive_logging_server - -reactive_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -reactive_logging_server_SOURCES = \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - Reactive_Logging_Server.cpp \ - Logging_Handler.h \ - Logging_Server.h \ - Reactive_Logging_Server.h - -reactive_logging_server_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_Reactive_Logging_Server_Ex.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += reactive_logging_server_ex - -reactive_logging_server_ex_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -reactive_logging_server_ex_SOURCES = \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - Reactive_Logging_Server_Ex.cpp \ - Logging_Handler.h \ - Logging_Server.h \ - Reactive_Logging_Server_Ex.h - -reactive_logging_server_ex_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv1_TPC_Logging_Server.am - -if !BUILD_USES_WCHAR -noinst_PROGRAMS += tpc_logging_server - -tpc_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -tpc_logging_server_SOURCES = \ - Logging_Handler.cpp \ - Logging_Server.cpp \ - Thread_Per_Connection_Logging_Server.cpp \ - Logging_Handler.h \ - Logging_Server.h \ - Thread_Per_Connection_Logging_Server.h - -tpc_logging_server_LDADD = \ - $(top_builddir)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Clean up template repositories, etc. -clean-local: - -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* - -rm -f gcctemp.c gcctemp so_locations *.ics - -rm -rf cxx_repository ptrepository ti_files - -rm -rf templateregistry ir.out - -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/examples/C++NPv1/Process_Per_Connection_Logging_Server.cpp b/examples/C++NPv1/Process_Per_Connection_Logging_Server.cpp deleted file mode 100644 index 54d936962aa..00000000000 --- a/examples/C++NPv1/Process_Per_Connection_Logging_Server.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Log_Msg.h" -#include "ace/Process_Manager.h" -#include "ace/Signal.h" -#include "ace/OS_NS_string.h" -#include "ace/os_include/os_fcntl.h" - -#include "Process_Per_Connection_Logging_Server.h" -#include "Logging_Handler.h" - -#include <errno.h> - -namespace { - extern "C" void sigterm_handler (int /* signum */) { /* No-op. */ } -} - - -Logging_Process::Logging_Process (const char *prog_name, - const ACE_SOCK_Stream &logging_peer) - : logging_peer_ (logging_peer.get_handle ()) -{ - ACE_OS::strcpy (prog_name_, prog_name); -} - -// Set up the process options here. If the decision to do a fork -// a no exec on POSIX needs to be changed, this is the only place -// that needs to change (omit the creation_flags() call). -// We request that the logging client's socket handle be passed -// to the child process. The internals of ACE_Process insure that -// it gets put on the command line if starting a new program image, -// and that if it needed to be duplicated to accomplish that (such -// as on Win32) it will get properly closed. -// The process_name () call sets the program to run and is also used -// for the fork() call on POSIX. -// avoid_zombies has a real affect only on POSIX; it's harmless on Win32. -// Setting the NO_EXEC creation flag is what prevents the exec() on -// POSIX. It has no affect on Win32. -int -Logging_Process::prepare (ACE_Process_Options &options) -{ - if (options.pass_handle (logging_peer_.get_handle ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "pass_handle"), -1); - options.command_line ("%s", prog_name_); - options.avoid_zombies (1); - options.creation_flags (ACE_Process_Options::NO_EXEC); - return 0; -} - -// Just delete the process object. If any handles needed to be -// duplicated to be passed to the child, they'll get closed now -// by the ACE_Process destructor. -void -Logging_Process::unmanage () -{ - delete this; -} - - -int -Process_Per_Connection_Logging_Server::handle_connections () -{ - ACE_SOCK_Stream logging_peer; - - // Block until a client connects. - if (acceptor ().accept (logging_peer) == -1) - return -1; - - Logging_Process *logger = - new Logging_Process (prog_name_, logging_peer); - ACE_Process_Options options; - pid_t pid; - pid = ACE_Process_Manager::instance ()->spawn (logger, - options); - // If we came back with pid 0 from the spawn(), this is a - // POSIX fork system - we are in the child process. Handle the - // logging records, then exit. - if (pid == 0) { - acceptor().close (); - handle_data (&logging_peer); - delete logger; - ACE_OS::exit (0); - } - logging_peer.close (); - if (pid == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn()"), -1); - - // See if there are any child processes that have - // exited - reap their status and clean up handles held - // open while the child executed. - ACE_Process_Manager::instance ()->wait (0, - ACE_Time_Value::zero); - return 0; -} - -int -Process_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client) -{ - // Disable non-blocking mode. - client->disable (ACE_NONBLOCK); - ACE_FILE_IO log_file; - make_log_file (log_file, client); - Logging_Handler logging_handler (log_file, *client); - - while (logging_handler.log_record () != -1) - continue; - - log_file.close (); - return 0; -} - - -int -Process_Per_Connection_Logging_Server::run (int argc, char *argv[]) -{ - ACE_OS::strncpy (prog_name_, argv[0], MAXPATHLEN); - prog_name_[MAXPATHLEN] = '\0'; // Ensure NUL-termination. - // If there are 2 command line arguments after prog_name_, this - // is a spawned worker process. Else run as the master. - if (argc == 3) - return run_worker (argc, argv); // Only on Win32. - else - return run_master (argc, argv); -} - -int -Process_Per_Connection_Logging_Server::run_master (int argc, char *argv[]) -{ - u_short logger_port = 0; - if (argc == 2) - logger_port = atoi (argv[1]); - if (open (logger_port) == -1) - return -1; - - for (;;) - if (handle_connections () == -1) - return -1; - - return 0; -} - -int -Process_Per_Connection_Logging_Server::run_worker (int, char *argv[]) -{ - int client_handle_i = atoi (argv[2]); - // Some compilers don't like reinterpret_casting an int to an int, so - // only do reinterpret_cast on Windows. -#if defined (ACE_WIN32) - ACE_HANDLE client_handle = - reinterpret_cast<ACE_HANDLE> (client_handle_i); -#else - ACE_HANDLE client_handle = - static_cast<ACE_HANDLE> (client_handle_i); -#endif /* ACE_WIN32 */ - ACE_SOCK_Stream client (client_handle); - - handle_data (&client); - client.close (); - return 0; -} - - -int main (int argc, char *argv[]) -{ - // Register to receive the <SIGTERM> signal. - ACE_Sig_Action sa ((ACE_SignalHandler)sigterm_handler, - SIGTERM); - - Process_Per_Connection_Logging_Server server; - - if (server.run (argc, argv) == -1 && errno != EINTR) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - - // Barrier synchronization. - return ACE_Process_Manager::instance ()->wait (); -} diff --git a/examples/C++NPv1/Process_Per_Connection_Logging_Server.h b/examples/C++NPv1/Process_Per_Connection_Logging_Server.h deleted file mode 100644 index 4d64d764bfd..00000000000 --- a/examples/C++NPv1/Process_Per_Connection_Logging_Server.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _PROCESS_PER_CONNECTION_LOGGING_SERVER_H -#define _PROCESS_PER_CONNECTION_LOGGING_SERVER_H - -#include "ace/INET_Addr.h" -#include "ace/Log_Record.h" -#include "ace/Process.h" -#include "ace/Process_Manager.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "ace/Signal.h" -#include "Logging_Server.h" - -class Logging_Process : public ACE_Process -{ -public: - Logging_Process (const char *prog_name, - const ACE_SOCK_Stream &logging_peer); - - virtual int prepare (ACE_Process_Options &options); - virtual void unmanage (); - -private: - Logging_Process (); // Force desired constructor to be used. - - char prog_name_[MAXPATHLEN + 1]; - ACE_SOCK_Stream logging_peer_; -}; - - -class Process_Per_Connection_Logging_Server : public Logging_Server -{ -protected: - char prog_name_[MAXPATHLEN + 1]; - -protected: - virtual int handle_connections (); - virtual int handle_data (ACE_SOCK_Stream *client = 0); - - int run_master (int argc, char *argv[]); - int run_worker (int argc, char *argv[]); - -public: - virtual int run (int argc, char *argv[]); - -}; - -#endif /* _PROCESS_PER_CONNECTION_LOGGING_SERVER_H */ diff --git a/examples/C++NPv1/README b/examples/C++NPv1/README deleted file mode 100644 index 747fa24ecfc..00000000000 --- a/examples/C++NPv1/README +++ /dev/null @@ -1,73 +0,0 @@ -(This is file $Id$) - -The files in this directory contain the source code from the book -``C++ Network Programming: Mastering Complexity Using ACE and -Patterns'' (C++NPv1) by Douglas C. Schmidt and Stephen D. Huston -(Addison-Wesley 2001, ISBN 0-201-60464-7). - -We have compiled and run these files on the following platforms: - - Sun Solaris 8 on SPARC using Sun Forte 6. - Redhat Linux 7.1 using g++ 2.96. - Microsoft Windows 2000 using Microsoft Visual C++ 6. - -You must have the ACE_ROOT environment variable set correctly to build -these examples. ACE_ROOT must refer to the top-level ACE_wrappers -directory. Please see $ACE_ROOT/ACE-INSTALL.html for instructions on -how to build the ACE toolkit. - -Mapping Source Files to Book Chapters -------------------------------------- - -The files in this directory map to the chapters in C++NPv1 as follows: - -Chapter 4 Logging_Client.h - Logging_Client.cpp - Logging_Handler.h - Logging_Handler.cpp - Iterative_Logging_Server.h - Iterative_Logging_Server.cpp - -Chapter 7 Reactive_Logging_Server.h - Reactive_Logging_Server.cpp - Reactive_Logging_Server_Ex.h - Reactive_Logging_Server_Ex.cpp - -Chapter 8 Process_Per_Connection_Logging_Server.h - Process_Per_Connection_Logging_Server.cpp - -Chapter 9 Thread_Per_Connection_Logging_Server.h - Thread_Per_Connection_Logging_Server.cpp - RT_Thread_Per_Connection_Logging_Server.h - RT_Thread_Per_Connection_Logging_Server.cpp - -Microsoft Visual C++ users: ---------------------------- - -The examples.dsw file is a Microsoft Visual C++ workspace file that -contains projects for the individual programs. You can either build -them separately, or use the Batch Build command to build multiple -projects at once. - -All other users: ----------------- - -Assuming that your system is configured correctly, you should be able -to type - -% make - -to compile all of the programs, and - -% make clean - -to remove all the files that were generated during compilation. - -There are also individual Makefiles for each separate example program. -These makefiles have a ".mak" suffix. For example, Logging_Client.mak -is the makefile for the Logging_Client program. - -All of the files in these directories are copyright Addison Wesley, -and they come with absolutely no warranty whatsoever. Permission is -hereby granted to use these programs for educational or commercial -purposes. diff --git a/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.cpp b/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.cpp deleted file mode 100644 index 465c8ae8f96..00000000000 --- a/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Auto_Ptr.h" -#include "ace/FILE_IO.h" -#include "ace/Log_Msg.h" -#include "ace/Sched_Params.h" -#include "ace/Signal.h" -#include "ace/Thread_Manager.h" - -#include "RT_Thread_Per_Connection_Logging_Server.h" -#include "Logging_Handler.h" - -#include <errno.h> - -namespace { - extern "C" void sigterm_handler (int /* signum */) { /* No-op. */ } -} - - -int -RT_Thread_Per_Connection_Logging_Server::open (u_short port) -{ - ACE_Sched_Params fifo_sched_params - (ACE_SCHED_FIFO, - ACE_Sched_Params::priority_min (ACE_SCHED_FIFO), - ACE_SCOPE_PROCESS); - - if (ACE_OS::sched_params (fifo_sched_params) != 0) { - if (errno == EPERM || errno == ENOTSUP) - ACE_DEBUG ((LM_DEBUG, - "Warning: user's not superuser, so " - "we're running in time-shared class\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", "ACE_OS::sched_params()"), -1); - } - // Initialize the parent classes. - return Thread_Per_Connection_Logging_Server::open (port); -} - - -int -RT_Thread_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client) -{ - int prio = - ACE_Sched_Params::next_priority - (ACE_SCHED_FIFO, - ACE_Sched_Params::priority_min (ACE_SCHED_FIFO), - ACE_SCOPE_THREAD); - ACE_OS::thr_setprio (prio); - return Thread_Per_Connection_Logging_Server::handle_data (client); -} - - -// For simplicity, the Thread_Per_Connection_Logging_Server methods -// are duplicated here. - -ACE_THR_FUNC_RETURN Thread_Per_Connection_Logging_Server::run_svc (void *arg) -{ - auto_ptr<Thread_Args> thread_args (static_cast<Thread_Args *> (arg)); - - thread_args->this_->handle_data (&thread_args->logging_peer_); - thread_args->logging_peer_.close (); - return 0; // Return value is ignored -} - - -int -Thread_Per_Connection_Logging_Server::handle_connections () -{ - auto_ptr<Thread_Args> thread_args (new Thread_Args (this)); - - if (acceptor ().accept (thread_args->logging_peer_) == -1) - return -1; - if (ACE_Thread_Manager::instance ()->spawn ( - // Pointer to function entry point. - Thread_Per_Connection_Logging_Server::run_svc, - // <run_svc> parameter. - static_cast<void *> (thread_args.get ()), - THR_DETACHED | THR_SCOPE_SYSTEM) == -1) - return -1; - thread_args.release (); // Spawned thread now owns memory - return 0; -} - - -int -Thread_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client) -{ - ACE_FILE_IO log_file; - // Client's hostname is logfile name. - make_log_file (log_file, client); - - // Place the connection into blocking mode since this - // thread isn't doing anything except handling this client. - client->disable (ACE_NONBLOCK); - - Logging_Handler logging_handler (log_file, *client); - - // Keep handling log records until client closes connection - // or this thread is asked to cancel itself. - ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance (); - ACE_thread_t me = ACE_Thread::self (); - while (!mgr->testcancel (me) && - logging_handler.log_record () != -1) - continue; - - log_file.close (); - return 0; -} - - -int main (int argc, char *argv[]) -{ - // Register to receive the <SIGTERM> signal. - ACE_Sig_Action sa ((ACE_SignalHandler) sigterm_handler, - SIGTERM); - - RT_Thread_Per_Connection_Logging_Server server; - - if (server.run (argc, argv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - - // Cooperative thread cancellation and barrier synchronization. - ACE_Thread_Manager::instance ()->cancel_all (); - return ACE_Thread_Manager::instance ()->wait (); -} - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr<Thread_Per_Connection_Logging_Server::Thread_Args>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr<Thread_Per_Connection_Logging_Server::Thread_Args> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.h b/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.h deleted file mode 100644 index 828a0e61a03..00000000000 --- a/examples/C++NPv1/RT_Thread_Per_Connection_Logging_Server.h +++ /dev/null @@ -1,22 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _RT_THREAD_PER_CONNECTION_LOGGING_SERVER_H -#define _RT_THREAD_PER_CONNECTION_LOGGING_SERVER_H - -#include "ace/SOCK_Stream.h" -#include "Logging_Server.h" -#include "Thread_Per_Connection_Logging_Server.h" - -class RT_Thread_Per_Connection_Logging_Server : - public Thread_Per_Connection_Logging_Server -{ -protected: - virtual int open (u_short port); - virtual int handle_data (ACE_SOCK_Stream * = 0); -}; - -#endif /* _RT_THREAD_PER_CONNECTION_LOGGING_SERVER_H */ diff --git a/examples/C++NPv1/Reactive_Logging_Server.cpp b/examples/C++NPv1/Reactive_Logging_Server.cpp deleted file mode 100644 index 39d2c6b51be..00000000000 --- a/examples/C++NPv1/Reactive_Logging_Server.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Log_Msg.h" -#include "Reactive_Logging_Server.h" - -int main (int argc, char *argv[]) -{ - Reactive_Logging_Server server; - - if (server.run (argc, argv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - return 0; -} diff --git a/examples/C++NPv1/Reactive_Logging_Server.h b/examples/C++NPv1/Reactive_Logging_Server.h deleted file mode 100644 index 482bcb32107..00000000000 --- a/examples/C++NPv1/Reactive_Logging_Server.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _REACTIVE_LOGGING_SERVER_H -#define _REACTIVE_LOGGING_SERVER_H - -#include "ace/INET_Addr.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "ace/Log_Record.h" -#include "ace/Handle_Set.h" -#include "ace/os_include/os_fcntl.h" -#include "Iterative_Logging_Server.h" - -class Reactive_Logging_Server : public Iterative_Logging_Server -{ -protected: - // Keep track of the acceptor socket handle and all the - // connected stream socket handles. - ACE_Handle_Set master_handle_set_; - - // Keep track of handles marked as active by <select>. - ACE_Handle_Set active_handles_; - - virtual int open (u_short logger_port) { - Iterative_Logging_Server::open (logger_port); - master_handle_set_.set_bit (acceptor ().get_handle ()); - acceptor ().enable (ACE_NONBLOCK); - return 0; - } - - virtual int wait_for_multiple_events () { - active_handles_ = master_handle_set_; - int width = (int)active_handles_.max_set () + 1; - if (select (width, - active_handles_.fdset (), - 0, // no write_fds - 0, // no except_fds - 0) == -1) // no timeout - return -1; - active_handles_.sync - ((ACE_HANDLE) ((int) active_handles_.max_set () + 1)); - return 0; - } - - virtual int handle_connections () { - if (active_handles_.is_set (acceptor ().get_handle ())) { - while (acceptor ().accept (logging_handler ().peer ()) == 0) - master_handle_set_.set_bit - (logging_handler ().peer ().get_handle ()); - - // Remove acceptor handle from further consideration. - active_handles_.clr_bit (acceptor ().get_handle ()); - } - return 0; - } - - virtual int handle_data (ACE_SOCK_Stream *) { - ACE_Handle_Set_Iterator peer_iterator (active_handles_); - - for (ACE_HANDLE handle; - (handle = peer_iterator ()) != ACE_INVALID_HANDLE; - ) { - logging_handler ().peer ().set_handle (handle); - if (logging_handler ().log_record () == -1) { - // Handle connection shutdown or comm failure. - master_handle_set_.clr_bit (handle); - logging_handler ().close (); - } - } - return 0; - } - -}; - -#endif /* _REACTIVE_LOGGING_SERVER_H */ diff --git a/examples/C++NPv1/Reactive_Logging_Server_Ex.cpp b/examples/C++NPv1/Reactive_Logging_Server_Ex.cpp deleted file mode 100644 index 8999d7a9651..00000000000 --- a/examples/C++NPv1/Reactive_Logging_Server_Ex.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Functor.h" -#include "ace/Log_Msg.h" - -#include "Reactive_Logging_Server_Ex.h" - -int main (int argc, char *argv[]) -{ - Reactive_Logging_Server_Ex server; - - if (server.run (argc, argv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - return 0; -} - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Hash_Map_Entry<ACE_HANDLE, ACE_FILE_IO *>; -template class ACE_Hash_Map_Manager<ACE_HANDLE, ACE_FILE_IO *, ACE_Null_Mutex>; -template class ACE_Hash_Map_Manager_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Base_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Iterator_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex>; -template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Hash_Map_Entry<ACE_HANDLE, ACE_FILE_IO *> -#pragma instantiate ACE_Hash_Map_Manager<ACE_HANDLE, ACE_FILE_IO *, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex> -#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_HANDLE, ACE_FILE_IO *, ACE_Hash<ACE_HANDLE>, ACE_Equal_To<ACE_HANDLE>, ACE_Null_Mutex> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/C++NPv1/Reactive_Logging_Server_Ex.h b/examples/C++NPv1/Reactive_Logging_Server_Ex.h deleted file mode 100644 index c839b2453fc..00000000000 --- a/examples/C++NPv1/Reactive_Logging_Server_Ex.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _REACTIVE_LOGGING_SERVER_EX_H -#define _REACTIVE_LOGGING_SERVER_EX_H - -#include "ace/ACE.h" -#include "ace/FILE_IO.h" -#include "ace/Handle_Set.h" -#include "ace/Hash_Map_Manager.h" -#include "ace/INET_Addr.h" -#include "ace/Log_Record.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "Logging_Server.h" -#include "Logging_Handler.h" -#include "ace/Null_Mutex.h" -#include "ace/os_include/os_fcntl.h" - -typedef ACE_Hash_Map_Manager<ACE_HANDLE, - ACE_FILE_IO *, - ACE_Null_Mutex> LOG_MAP; - -class Reactive_Logging_Server_Ex : public Logging_Server -{ -protected: - // Associate an active handle to an <ACE_FILE_IO> pointer. - LOG_MAP log_map_; - - // Keep track of acceptor socket and all the connected - // stream socket handles. - ACE_Handle_Set master_handle_set_; - - // Keep track of read handles marked as active by <select>. - ACE_Handle_Set active_read_handles_; - - virtual int open (u_short port) { - Logging_Server::open (port); - master_handle_set_.set_bit (acceptor ().get_handle ()); - acceptor ().enable (ACE_NONBLOCK); - return 0; - } - - virtual int wait_for_multiple_events () { - active_read_handles_ = master_handle_set_; - int width = (int) active_read_handles_.max_set () + 1; - - return ACE::select (width, active_read_handles_); - } - - virtual int handle_connections () { - ACE_SOCK_Stream logging_peer; - - while (acceptor ().accept (logging_peer) != -1) { - ACE_FILE_IO *log_file = new ACE_FILE_IO; - - // Use the client's hostname as the logfile name. - make_log_file (*log_file, &logging_peer); - - // Add the new <logging_peer>'s handle to the map and - // to the set of handles we <select> for input. - log_map_.bind (logging_peer.get_handle (), log_file); - master_handle_set_.set_bit (logging_peer.get_handle ()); - } - active_read_handles_.clr_bit (acceptor ().get_handle ()); - return 0; - } - - virtual int handle_data (ACE_SOCK_Stream *) { - ACE_Handle_Set_Iterator peer_iterator (active_read_handles_); - - for (ACE_HANDLE handle; - (handle = peer_iterator ()) != ACE_INVALID_HANDLE; - ) { - ACE_FILE_IO *log_file = 0; - log_map_.find (handle, log_file); - Logging_Handler logging_handler (*log_file, handle); - - if (logging_handler.log_record () == -1) { - logging_handler.close (); - master_handle_set_.clr_bit (handle); - log_map_.unbind (handle); - log_file->close (); - delete log_file; - } - } - return 0; - } - -}; - -#endif /* _REACTIVE_LOGGING_SERVER_EX_H */ diff --git a/examples/C++NPv1/Thread_Per_Connection_Logging_Server.cpp b/examples/C++NPv1/Thread_Per_Connection_Logging_Server.cpp deleted file mode 100644 index e2c37bb0ef2..00000000000 --- a/examples/C++NPv1/Thread_Per_Connection_Logging_Server.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Auto_Ptr.h" -#include "ace/FILE_IO.h" -#include "ace/Log_Msg.h" -#include "ace/Signal.h" -#include "ace/Thread_Manager.h" - -#include "Thread_Per_Connection_Logging_Server.h" -#include "Logging_Handler.h" - -#include <errno.h> - -namespace { - extern "C" void sigterm_handler (int /* signum */) { /* No-op. */ } -} - - -ACE_THR_FUNC_RETURN Thread_Per_Connection_Logging_Server::run_svc (void *arg) -{ - auto_ptr<Thread_Args> thread_args (static_cast<Thread_Args *> (arg)); - - thread_args->this_->handle_data (&thread_args->logging_peer_); - thread_args->logging_peer_.close (); - return 0; // Return value is ignored -} - - -int -Thread_Per_Connection_Logging_Server::handle_connections () -{ - auto_ptr<Thread_Args> thread_args (new Thread_Args (this)); - - if (acceptor ().accept (thread_args->logging_peer_) == -1) - return -1; - if (ACE_Thread_Manager::instance ()->spawn ( - // Pointer to function entry point. - Thread_Per_Connection_Logging_Server::run_svc, - // <run_svc> parameter. - static_cast<void *> (thread_args.get ()), - THR_DETACHED | THR_SCOPE_SYSTEM) == -1) - return -1; - thread_args.release (); // Spawned thread now owns memory - return 0; -} - - -int -Thread_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client) -{ - ACE_FILE_IO log_file; - // Client's hostname is logfile name. - make_log_file (log_file, client); - - // Place the connection into blocking mode since this - // thread isn't doing anything except handling this client. - client->disable (ACE_NONBLOCK); - - Logging_Handler logging_handler (log_file, *client); - - // Keep handling log records until client closes connection - // or this thread is asked to cancel itself. - ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance (); - ACE_thread_t me = ACE_Thread::self (); - while (!mgr->testcancel (me) && - logging_handler.log_record () != -1) - continue; - - log_file.close (); - return 0; -} - - -int main (int argc, char *argv[]) -{ - // Register to receive the <SIGTERM> signal. - ACE_Sig_Action sa ((ACE_SignalHandler) sigterm_handler, - SIGTERM); - - Thread_Per_Connection_Logging_Server server; - - if (server.run (argc, argv) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "server.run()"), 1); - - // Cooperative thread cancellation and barrier synchronization. - ACE_Thread_Manager::instance ()->cancel_all (); - return ACE_Thread_Manager::instance ()->wait (); -} - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class auto_ptr<Thread_Per_Connection_Logging_Server::Thread_Args>; -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate auto_ptr<Thread_Per_Connection_Logging_Server::Thread_Args> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/examples/C++NPv1/Thread_Per_Connection_Logging_Server.h b/examples/C++NPv1/Thread_Per_Connection_Logging_Server.h deleted file mode 100644 index edf3651cf46..00000000000 --- a/examples/C++NPv1/Thread_Per_Connection_Logging_Server.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -** $Id$ -** -** Copyright 2001 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _THREAD_PER_CONNECTION_LOGGING_SERVER_H -#define _THREAD_PER_CONNECTION_LOGGING_SERVER_H - -#include "ace/SOCK_Stream.h" -#include "Logging_Server.h" - -class Thread_Per_Connection_Logging_Server : public Logging_Server -{ -private: - struct Thread_Args { - Thread_Args (Thread_Per_Connection_Logging_Server *lsp) : this_ (lsp) {} - - Thread_Per_Connection_Logging_Server *this_; - ACE_SOCK_Stream logging_peer_; - }; - - // Passed as a parameter to <ACE_Thread_Manager::spawn>. - static ACE_THR_FUNC_RETURN run_svc (void *arg); - -protected: - virtual int handle_connections (); - virtual int handle_data (ACE_SOCK_Stream * = 0); - -public: - // Template Method that runs logging server's event loop. Need to - // reimplement this here because the threads spawned from handle_connections - // call handle_data; therefore, this method must not. - virtual int run (int argc, char *argv[]) { - if (open (argc > 1 ? atoi (argv[1]) : 0) == -1) - return -1; - - for (;;) { - if (wait_for_multiple_events () == -1) - return -1; - if (handle_connections () == -1) - return -1; - } - - return 0; - } -}; - -#endif /* _THREAD_PER_CONNECTION_LOGGING_SERVER_H */ |