diff options
Diffstat (limited to 'ACE/examples/C++NPv2')
45 files changed, 0 insertions, 4565 deletions
diff --git a/ACE/examples/C++NPv2/AC_CLD_export.h b/ACE/examples/C++NPv2/AC_CLD_export.h deleted file mode 100644 index 0f2b35ca4c4..00000000000 --- a/ACE/examples/C++NPv2/AC_CLD_export.h +++ /dev/null @@ -1,54 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl AC_CLD -// ------------------------------ -#ifndef AC_CLD_EXPORT_H -#define AC_CLD_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (AC_CLD_HAS_DLL) -# define AC_CLD_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! AC_CLD_HAS_DLL */ - -#if !defined (AC_CLD_HAS_DLL) -# define AC_CLD_HAS_DLL 1 -#endif /* ! AC_CLD_HAS_DLL */ - -#if defined (AC_CLD_HAS_DLL) && (AC_CLD_HAS_DLL == 1) -# if defined (AC_CLD_BUILD_DLL) -# define AC_CLD_Export ACE_Proper_Export_Flag -# define AC_CLD_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define AC_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* AC_CLD_BUILD_DLL */ -# define AC_CLD_Export ACE_Proper_Import_Flag -# define AC_CLD_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define AC_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* AC_CLD_BUILD_DLL */ -#else /* AC_CLD_HAS_DLL == 1 */ -# define AC_CLD_Export -# define AC_CLD_SINGLETON_DECLARATION(T) -# define AC_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* AC_CLD_HAS_DLL == 1 */ - -// Set AC_CLD_NTRACE = 0 to turn on library specific tracing even if -// tracing is turned off for ACE. -#if !defined (AC_CLD_NTRACE) -# if (ACE_NTRACE == 1) -# define AC_CLD_NTRACE 1 -# else /* (ACE_NTRACE == 1) */ -# define AC_CLD_NTRACE 0 -# endif /* (ACE_NTRACE == 1) */ -#endif /* !AC_CLD_NTRACE */ - -#if (AC_CLD_NTRACE == 1) -# define AC_CLD_TRACE(X) -#else /* (AC_CLD_NTRACE == 1) */ -# define AC_CLD_TRACE(X) ACE_TRACE_IMPL(X) -#endif /* (AC_CLD_NTRACE == 1) */ - -#endif /* AC_CLD_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.cpp b/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.cpp deleted file mode 100644 index e3ab37451c6..00000000000 --- a/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.cpp +++ /dev/null @@ -1,429 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_unistd.h" -#include "ace/OS_NS_sys_socket.h" -#include "ace/OS_NS_sys_time.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Stream.h" -#include "ace/Acceptor.h" -#include "ace/Connector.h" -#include "ace/Get_Opt.h" -#include "ace/Handle_Set.h" -#include "ace/Log_Record.h" -#include "ace/Message_Block.h" -#include "ace/Reactor.h" -#include "ace/Service_Object.h" -#include "ace/Signal.h" -#include "ace/Svc_Handler.h" -#include "ace/Thread_Manager.h" -#include "ace/os_include/os_netdb.h" -#include "Logging_Handler.h" -#include "AC_CLD_export.h" - -#include "AC_Client_Logging_Daemon.h" - -#include <openssl/ssl.h> - - -class AC_CLD_Acceptor - : public ACE_Acceptor<AC_Input_Handler, ACE_SOCK_ACCEPTOR> { -public: - // Constructor. - AC_CLD_Acceptor (AC_Output_Handler *handler = 0) - : output_handler_ (handler), input_handler_ (handler) {} - -protected: - typedef ACE_Acceptor<AC_Input_Handler, ACE_SOCK_ACCEPTOR> - PARENT; - - // <ACE_Acceptor> factory method. - virtual int make_svc_handler (AC_Input_Handler *&sh); - - // <ACE_Reactor> close hook method. - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - - // Pointer to the output handler. - AC_Output_Handler *output_handler_; - - // Single input handler. - AC_Input_Handler input_handler_; -}; - -class AC_CLD_Connector - : public ACE_Connector<AC_Output_Handler, ACE_SOCK_CONNECTOR> { -public: - typedef ACE_Connector<AC_Output_Handler, ACE_SOCK_CONNECTOR> - PARENT; - - // Constructor. - AC_CLD_Connector (AC_Output_Handler *handler = 0) - : handler_ (handler), ssl_ctx_ (0), ssl_ (0) {} - - // Destructor frees the SSL resources. - virtual ~AC_CLD_Connector (void) { - SSL_free (ssl_); - SSL_CTX_free (ssl_ctx_); - } - - //FUZZ: disable check_for_lack_ACE_OS - // Initialize the Connector. - virtual int open (ACE_Reactor *r = ACE_Reactor::instance (), - int flags = 0); - //FUZZ: enable check_for_lack_ACE_OS - - // Re-establish a connection to the logging server. - int reconnect (); - -protected: - // Connection establishment and authentication hook method. - virtual int connect_svc_handler - (AC_Output_Handler *&svc_handler, - const ACE_SOCK_Connector::PEER_ADDR &remote_addr, - ACE_Time_Value *timeout, - const ACE_SOCK_Connector::PEER_ADDR &local_addr, - int reuse_addr, int flags, int perms); - - virtual int connect_svc_handler - (AC_Output_Handler *&svc_handler, - AC_Output_Handler *&sh_copy, - const ACE_SOCK_Connector::PEER_ADDR &remote_addr, - ACE_Time_Value *timeout, - const ACE_SOCK_Connector::PEER_ADDR &local_addr, - int reuse_addr, int flags, int perms); - - // Pointer to <AC_Output_Handler> we're connecting. - AC_Output_Handler *handler_; - - // Address at which logging server listens for connections. - ACE_INET_Addr remote_addr_; - - // The SSL "context" data structure. - SSL_CTX *ssl_ctx_; - - // The SSL data structure corresponding to authenticated SSL - // connections. - SSL *ssl_; -}; - -class AC_Client_Logging_Daemon : public ACE_Service_Object { -protected: - // Factory that passively connects the <AC_Input_Handler>. - AC_CLD_Acceptor acceptor_; - - // Factory that actively connects the <AC_Output_Handler>. - AC_CLD_Connector connector_; - - // The <AC_Output_Handler> connected by <AC_CLD_Connector>. - AC_Output_Handler output_handler_; - -public: - // Constructor. - AC_Client_Logging_Daemon () - : acceptor_ (&output_handler_), - connector_ (&output_handler_) {} - - // Service Configurator hook methods. - virtual int init (int argc, ACE_TCHAR *argv[]); - virtual int fini (); - //virtual int info (ACE_TCHAR **bufferp, size_t length = 0) const; - //virtual int suspend (); - //virtual int resume (); -}; - -/******************************************************/ - -#if !defined (FLUSH_TIMEOUT) -#define FLUSH_TIMEOUT 120 /* 120 seconds == 2 minutes. */ -#endif /* FLUSH_TIMEOUT */ - -int AC_Output_Handler::open (void *connector) { - connector_ = - static_cast<AC_CLD_Connector *> (connector); - int bufsiz = ACE_DEFAULT_MAX_SOCKET_BUFSIZ; - peer ().set_option (SOL_SOCKET, SO_SNDBUF, - &bufsiz, sizeof bufsiz); - if (reactor ()->register_handler - (this, ACE_Event_Handler::READ_MASK) == -1) - return -1; - if (msg_queue ()->activate () - == ACE_Message_Queue_Base::ACTIVATED) { - msg_queue ()->high_water_mark (QUEUE_MAX); - return activate (THR_SCOPE_SYSTEM); - } else return 0; -} - -int AC_Output_Handler::put (ACE_Message_Block *mb, - ACE_Time_Value *timeout) { - int retval; - while ((retval = putq (mb, timeout)) == -1) { - if (msg_queue ()->state () != ACE_Message_Queue_Base::PULSED) - break; - } - return retval; -} - -int AC_Output_Handler::handle_input (ACE_HANDLE h) { - peer ().close (); - reactor ()->remove_handler - (h, ACE_Event_Handler::READ_MASK - | ACE_Event_Handler::DONT_CALL); - msg_queue ()->pulse (); - return 0; -} - -int AC_Output_Handler::svc () { - ACE_Message_Block *chunk[ACE_IOV_MAX]; - size_t message_index = 0; - ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ()); - ACE_Time_Value timeout; - ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN); - ACE_Sig_Action original_action; - no_sigpipe.register_action (SIGPIPE, &original_action); - - for (;;) { - if (message_index == 0) { - timeout = ACE_OS::gettimeofday (); - timeout += FLUSH_TIMEOUT; - } - ACE_Message_Block *mblk = 0; - if (getq (mblk, &timeout) == -1) { - if (errno == ESHUTDOWN) { - if (connector_->reconnect () == -1) break; - continue; - } else if (errno != EWOULDBLOCK) break; - else if (message_index == 0) continue; - } else { - if (mblk->size () == 0 - && mblk->msg_type () == ACE_Message_Block::MB_STOP) - { mblk->release (); break; } - chunk[message_index] = mblk; - ++message_index; - } - if (message_index >= ACE_IOV_MAX || - (ACE_OS::gettimeofday () - time_of_last_send - >= ACE_Time_Value(FLUSH_TIMEOUT))) { - if (this->send (chunk, message_index) == -1) break; - time_of_last_send = ACE_OS::gettimeofday (); - } - } - - if (message_index > 0) - this->send (chunk, message_index); - no_sigpipe.restore_action (SIGPIPE, original_action); - return 0; -} - -int AC_Output_Handler::send (ACE_Message_Block *chunk[], size_t &count) { - iovec iov[ACE_IOV_MAX]; - size_t iov_size; - int result = 0; - - for (iov_size = 0; iov_size < count; ++iov_size) { - iov[iov_size].iov_base = chunk[iov_size]->rd_ptr (); - iov[iov_size].iov_len = chunk[iov_size]->length (); - } - while (peer ().sendv_n (iov, iov_size) == -1) - if (connector_->reconnect () == -1) { - result = -1; - break; - } - - while (iov_size > 0) { - chunk[--iov_size]->release (); chunk[iov_size] = 0; - } - count = iov_size; - return result; -} - -/******************************************************/ - -int AC_Input_Handler::open (void *) { - ACE_HANDLE handle = peer ().get_handle (); - if (reactor ()->register_handler - (handle, this, ACE_Event_Handler::READ_MASK) == -1) - return -1; - connected_clients_.set_bit (handle); - return 0; -} - -int AC_Input_Handler::close (u_long) { - ACE_Message_Block *shutdown_message = 0; - ACE_NEW_RETURN - (shutdown_message, - ACE_Message_Block (0, ACE_Message_Block::MB_STOP), -1); - output_handler_->put (shutdown_message); - - reactor ()->remove_handler - (connected_clients_, ACE_Event_Handler::READ_MASK); - return output_handler_->wait (); -} - -int AC_Input_Handler::handle_input (ACE_HANDLE handle) { - ACE_Message_Block *mblk = 0; - Logging_Handler logging_handler (handle); - - if (logging_handler.recv_log_record (mblk) != -1) - if (output_handler_->put (mblk->cont ()) != -1) { - mblk->cont (0); - mblk->release (); - return 0; // Success return. - } else mblk->release (); - return -1; // Error return. -} - -int AC_Input_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask) { - connected_clients_.clr_bit (handle); - return ACE_OS::closesocket (handle); -} - -/********************************************************/ - -int AC_CLD_Acceptor::make_svc_handler (AC_Input_Handler *&sh) -{ sh = &input_handler_; return 0; } - - -int AC_CLD_Acceptor::handle_close (ACE_HANDLE, - ACE_Reactor_Mask) { - PARENT::handle_close (); - input_handler_.close (); - return 0; -} - -/*******************************************************/ - -#if !defined (CLD_CERTIFICATE_FILENAME) -# define CLD_CERTIFICATE_FILENAME "cld-cert.pem" -#endif /* !CLD_CERTIFICATE_FILENAME */ -#if !defined (CLD_KEY_FILENAME) -# define CLD_KEY_FILENAME "cld-key.pem" -#endif /* !CLD_KEY_FILENAME */ - -int AC_CLD_Connector::open (ACE_Reactor *r, int flags) { - if (PARENT::open (r, flags) != 0) return -1; - OpenSSL_add_ssl_algorithms (); - ssl_ctx_ = SSL_CTX_new (SSLv3_client_method ()); - if (ssl_ctx_ == 0) return -1; - - if (SSL_CTX_use_certificate_file (ssl_ctx_, - CLD_CERTIFICATE_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || SSL_CTX_use_PrivateKey_file (ssl_ctx_, - CLD_KEY_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || !SSL_CTX_check_private_key (ssl_ctx_)) - return -1; - - ssl_ = SSL_new (ssl_ctx_); - if (ssl_ == 0) return -1; - return 0; -} - -int AC_CLD_Connector::connect_svc_handler - (AC_Output_Handler *&svc_handler, - const ACE_SOCK_Connector::PEER_ADDR &remote_addr, - ACE_Time_Value *timeout, - const ACE_SOCK_Connector::PEER_ADDR &local_addr, - int reuse_addr, int flags, int perms) { - if (PARENT::connect_svc_handler - (svc_handler, remote_addr, timeout, - local_addr, reuse_addr, flags, perms) == -1) return -1; - SSL_clear (ssl_); -#if defined (ACE_WIN32) - // ACE_WIN32 is the only platform where ACE_HANDLE is not an int. - // See ace/config-lite.h for the typedefs. - SSL_set_fd (ssl_, - reinterpret_cast<int> (svc_handler->get_handle ())); -#else - SSL_set_fd (ssl_, svc_handler->get_handle ()); -#endif /* ACE_WIN32 */ - - SSL_set_verify (ssl_, SSL_VERIFY_PEER, 0); - - if (SSL_connect (ssl_) == -1 - || SSL_shutdown (ssl_) == -1) return -1; - remote_addr_ = remote_addr; - return 0; -} - -int AC_CLD_Connector::connect_svc_handler - (AC_Output_Handler *&svc_handler, - AC_Output_Handler *&sh_copy, - const ACE_SOCK_Connector::PEER_ADDR &remote_addr, - ACE_Time_Value *timeout, - const ACE_SOCK_Connector::PEER_ADDR &local_addr, - int reuse_addr, int flags, int perms) { - sh_copy = svc_handler; - return this->connect_svc_handler (svc_handler, remote_addr, timeout, - local_addr, reuse_addr, flags, perms); -} - -int AC_CLD_Connector::reconnect () { - // Maximum number of times to retry connect. - const size_t MAX_RETRIES = 5; - ACE_Time_Value timeout (1); - size_t i; - for (i = 0; i < MAX_RETRIES; ++i) { - ACE_Synch_Options options (ACE_Synch_Options::USE_TIMEOUT, - timeout); - if (i > 0) ACE_OS::sleep (timeout); - if (this->connect (handler_, remote_addr_, options) == 0) - break; - timeout *= 2; // Exponential backoff. - } - return i == MAX_RETRIES ? -1 : 0; -} - -/******************************************************/ - -int AC_Client_Logging_Daemon::init - (int argc, ACE_TCHAR *argv[]) { - u_short cld_port = ACE_DEFAULT_SERVICE_PORT; - u_short sld_port = ACE_DEFAULT_LOGGING_SERVER_PORT; - ACE_TCHAR sld_host[MAXHOSTNAMELEN]; - ACE_OS::strcpy (sld_host, ACE_LOCALHOST); - - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:r:s:"), 0); - get_opt.long_option (ACE_TEXT ("client_port"), 'p', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_port"), 'r', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_name"), 's', - ACE_Get_Opt::ARG_REQUIRED); - - for (int c; (c = get_opt ()) != -1;) - switch (c) { - case 'p': // Client logging daemon acceptor port number. - cld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 'r': // Server logging daemon acceptor port number. - sld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 's': // Server logging daemon hostname. - ACE_OS::strsncpy - (sld_host, get_opt.opt_arg (), MAXHOSTNAMELEN); - break; - } - - ACE_INET_Addr cld_addr (cld_port); - ACE_INET_Addr sld_addr (sld_port, sld_host); - - if (acceptor_.open (cld_addr) == -1) return -1; - AC_Output_Handler *oh = &output_handler_; - if (connector_.connect (oh, sld_addr) == -1) - { acceptor_.close (); return -1; } - return 0; -} - -int AC_Client_Logging_Daemon::fini () -{ return acceptor_.close (); } - -ACE_FACTORY_DEFINE (AC_CLD, AC_Client_Logging_Daemon) diff --git a/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.h b/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.h deleted file mode 100644 index 20f3581f623..00000000000 --- a/ACE/examples/C++NPv2/AC_Client_Logging_Daemon.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _AC_CLIENT_LOGGING_DAEMON_H -#define _AC_CLIENT_LOGGING_DAEMON_H - -#include "ace/Handle_Set.h" -#include "ace/Log_Record.h" -#include "ace/SOCK_Stream.h" -#include "ace/Svc_Handler.h" -#include "ace/Synch_Traits.h" - -class AC_CLD_Connector; - -class AC_Output_Handler - : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH> { -public: - enum { QUEUE_MAX = sizeof (ACE_Log_Record) * ACE_IOV_MAX }; - - virtual int open (void *); // Initialization hook method. - - // Entry point into the <AC_Output_Handler>. - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - -protected: - AC_CLD_Connector *connector_; - - // Handle disconnects from the logging server. - virtual int handle_input (ACE_HANDLE handle); - - // Hook method forwards log records to server logging daemon. - virtual int svc (); - - // Send the buffered log records using a gather-write operation. - virtual int send (ACE_Message_Block *chunk[], size_t &count); -}; - -class AC_Input_Handler - : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> { -public: - AC_Input_Handler (AC_Output_Handler *handler = 0) - : output_handler_ (handler) {} - virtual int open (void *); // Initialization hook method. - virtual int close (u_long = 0); // Shutdown hook method. - -protected: - // Reactor hook methods. - virtual int handle_input (ACE_HANDLE handle); - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - - // Pointer to the output handler. - AC_Output_Handler *output_handler_; - - // Keep track of connected client handles. - ACE_Handle_Set connected_clients_; -}; - -#endif /* _AC_CLIENT_LOGGING_DAEMON_H */ diff --git a/ACE/examples/C++NPv2/AIO_CLD_export.h b/ACE/examples/C++NPv2/AIO_CLD_export.h deleted file mode 100644 index 315bc287cf3..00000000000 --- a/ACE/examples/C++NPv2/AIO_CLD_export.h +++ /dev/null @@ -1,54 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl AIO_CLD -// ------------------------------ -#ifndef AIO_CLD_EXPORT_H -#define AIO_CLD_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (AIO_CLD_HAS_DLL) -# define AIO_CLD_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! AIO_CLD_HAS_DLL */ - -#if !defined (AIO_CLD_HAS_DLL) -# define AIO_CLD_HAS_DLL 1 -#endif /* ! AIO_CLD_HAS_DLL */ - -#if defined (AIO_CLD_HAS_DLL) && (AIO_CLD_HAS_DLL == 1) -# if defined (AIO_CLD_BUILD_DLL) -# define AIO_CLD_Export ACE_Proper_Export_Flag -# define AIO_CLD_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define AIO_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* AIO_CLD_BUILD_DLL */ -# define AIO_CLD_Export ACE_Proper_Import_Flag -# define AIO_CLD_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define AIO_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* AIO_CLD_BUILD_DLL */ -#else /* AIO_CLD_HAS_DLL == 1 */ -# define AIO_CLD_Export -# define AIO_CLD_SINGLETON_DECLARATION(T) -# define AIO_CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* AIO_CLD_HAS_DLL == 1 */ - -// Set AIO_CLD_NTRACE = 0 to turn on library specific tracing even if -// tracing is turned off for ACE. -#if !defined (AIO_CLD_NTRACE) -# if (ACE_NTRACE == 1) -# define AIO_CLD_NTRACE 1 -# else /* (ACE_NTRACE == 1) */ -# define AIO_CLD_NTRACE 0 -# endif /* (ACE_NTRACE == 1) */ -#endif /* !AIO_CLD_NTRACE */ - -#if (AIO_CLD_NTRACE == 1) -# define AIO_CLD_TRACE(X) -#else /* (AIO_CLD_NTRACE == 1) */ -# define AIO_CLD_TRACE(X) ACE_TRACE_IMPL(X) -#endif /* (AIO_CLD_NTRACE == 1) */ - -#endif /* AIO_CLD_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.cpp b/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.cpp deleted file mode 100644 index 3d7e36cb239..00000000000 --- a/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/config-all.h" - -#if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS)) - -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_sys_socket.h" -#include "ace/Asynch_Acceptor.h" -#include "ace/Asynch_Connector.h" -#include "ace/Asynch_IO.h" -#include "ace/CDR_Stream.h" -#include "ace/Get_Opt.h" -#include "ace/INET_Addr.h" -#include "ace/Message_Block.h" -#include "ace/Null_Condition.h" -#include "ace/Null_Mutex.h" -#include "ace/Proactor.h" -#include "ace/SOCK_Stream.h" -#include "ace/Service_Object.h" -#include "ace/Signal.h" -#include "ace/Singleton.h" -#include "ace/Task.h" -#include "ace/Thread_Manager.h" -#include "ace/Unbounded_Set.h" -#include "ace/os_include/os_netdb.h" -#include "AIO_CLD_export.h" -#include "AIO_Client_Logging_Daemon.h" -#include <openssl/ssl.h> - - - -class AIO_CLD_Acceptor - : public ACE_Asynch_Acceptor<AIO_Input_Handler> { -public: - //FUZZ: disable check_for_lack_ACE_OS - // Cancel accept and close all clients. - void close (void); - //FUZZ: enable check_for_lack_ACE_OS - - // Remove handler from client set. - void remove (AIO_Input_Handler *ih) - { clients_.remove (ih); } - -protected: - // Service handler factory method. - virtual AIO_Input_Handler *make_handler (void); - - // Set of all connected clients - ACE_Unbounded_Set<AIO_Input_Handler *> clients_; -}; - - -class AIO_Client_Logging_Daemon : public ACE_Task<ACE_NULL_SYNCH> { -protected: - ACE_INET_Addr cld_addr_; - ACE_INET_Addr sld_addr_; - - // Factory that passively connects the <AIO_Input_Handler>. - AIO_CLD_Acceptor acceptor_; - -public: - // Service Configurator hook methods. - virtual int init (int argc, ACE_TCHAR *argv[]); - virtual int fini (); - virtual int svc (void); -}; - -/******************************************************/ - -AIO_Output_Handler::~AIO_Output_Handler () { - reader_.cancel (); - writer_.cancel (); - ACE_OS::closesocket (handle ()); -} - -int AIO_Output_Handler::put (ACE_Message_Block *mb, - ACE_Time_Value *timeout) { - if (can_write_) { start_write (mb); return 0; } - return putq (mb, timeout); -} - -void AIO_Output_Handler::open - (ACE_HANDLE new_handle, ACE_Message_Block &) { - ACE_SOCK_Stream peer (new_handle); - int bufsiz = ACE_DEFAULT_MAX_SOCKET_BUFSIZ; - peer.set_option (SOL_SOCKET, SO_SNDBUF, - &bufsiz, sizeof bufsiz); - - reader_.open (*this, new_handle, 0, proactor ()); - writer_.open (*this, new_handle, 0, proactor ()); - - ACE_Message_Block *mb; - ACE_NEW (mb, ACE_Message_Block (1)); - reader_.read (*mb, 1); - ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN); - no_sigpipe.register_action (SIGPIPE, 0); - can_write_ = 1; - start_write (0); -} - -void AIO_Output_Handler::start_write (ACE_Message_Block *mblk) { - if (mblk == 0) { - ACE_Time_Value nonblock (0); - getq (mblk, &nonblock); - } - if (mblk != 0) { - can_write_ = 0; - if (writer_.write (*mblk, mblk->length ()) == -1) - ungetq (mblk); - } -} - -void AIO_Output_Handler::handle_read_stream - (const ACE_Asynch_Read_Stream::Result &result) { - result.message_block ().release (); - writer_.cancel (); - ACE_OS::closesocket (result.handle ()); - handle (ACE_INVALID_HANDLE); - can_write_ = 0; - CLD_CONNECTOR::instance ()->reconnect (); -} - -void AIO_Output_Handler::handle_write_stream - (const ACE_Asynch_Write_Stream::Result &result) { - ACE_Message_Block &mblk = result.message_block (); - if (!result.success ()) { - mblk.rd_ptr (mblk.base ()); - ungetq (&mblk); - } - else { - can_write_ = handle () == result.handle (); - if (mblk.length () == 0) { - mblk.release (); - if (can_write_) start_write (); - } - else if (can_write_) start_write (&mblk); - else { mblk.rd_ptr (mblk.base ()); ungetq (&mblk); } - } -} - -/******************************************************/ - -AIO_Input_Handler::~AIO_Input_Handler () { - reader_.cancel (); - ACE_OS::closesocket (handle ()); - if (mblk_ != 0) mblk_->release (); - mblk_ = 0; - acceptor_->remove (this); -} - -void AIO_Input_Handler::open - (ACE_HANDLE new_handle, ACE_Message_Block &) { - reader_.open (*this, new_handle, 0, proactor ()); - ACE_NEW_NORETURN - (mblk_, ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE)); - // Align the Message Block for a CDR stream - ACE_CDR::mb_align (mblk_); - reader_.read (*mblk_, LOG_HEADER_SIZE); -} - -void AIO_Input_Handler::handle_read_stream - (const ACE_Asynch_Read_Stream::Result &result) { - if (!result.success () || result.bytes_transferred () == 0) - delete this; - else if (result.bytes_transferred () < result.bytes_to_read ()) - reader_.read (*mblk_, result.bytes_to_read () - - result.bytes_transferred ()); - else if (mblk_->length () == LOG_HEADER_SIZE) { - ACE_InputCDR cdr (mblk_); - - ACE_CDR::Boolean byte_order; - cdr >> ACE_InputCDR::to_boolean (byte_order); - cdr.reset_byte_order (byte_order); - - ACE_CDR::ULong length; - cdr >> length; - - mblk_->size (length + LOG_HEADER_SIZE); - reader_.read (*mblk_, length); - } - else { - if (OUTPUT_HANDLER::instance ()->put (mblk_) == -1) - mblk_->release (); - - ACE_NEW_NORETURN - (mblk_, ACE_Message_Block (ACE_DEFAULT_CDR_BUFSIZE)); - ACE_CDR::mb_align (mblk_); - reader_.read (*mblk_, LOG_HEADER_SIZE); - } -} - -/********************************************************/ - -void AIO_CLD_Acceptor::close (void) { - ACE_Unbounded_Set_Iterator<AIO_Input_Handler *> - iter (clients_.begin ()); - AIO_Input_Handler **ih; - while (iter.next (ih)) - delete *ih; -} - -AIO_Input_Handler * AIO_CLD_Acceptor::make_handler (void) { - AIO_Input_Handler *ih; - ACE_NEW_RETURN (ih, AIO_Input_Handler (this), 0); - if (clients_.insert (ih) == -1) - { delete ih; return 0; } - return ih; -} - -/*******************************************************/ - -#if !defined (CLD_CERTIFICATE_FILENAME) -# define CLD_CERTIFICATE_FILENAME "cld-cert.pem" -#endif /* !CLD_CERTIFICATE_FILENAME */ -#if !defined (CLD_KEY_FILENAME) -# define CLD_KEY_FILENAME "cld-key.pem" -#endif /* !CLD_KEY_FILENAME */ - - -int AIO_CLD_Connector::validate_connection - (const ACE_Asynch_Connect::Result& result, - const ACE_INET_Addr &remote, const ACE_INET_Addr&) { - - remote_addr_ = remote; - if (!result.success ()) { - ACE_Time_Value delay (retry_delay_); - retry_delay_ *= 2; - if (retry_delay_ > MAX_RETRY_DELAY) - retry_delay_ = MAX_RETRY_DELAY; - proactor ()->schedule_timer (*this, 0, delay); - return -1; - } - retry_delay_ = INITIAL_RETRY_DELAY; - - if (ssl_ctx_ == 0) { - OpenSSL_add_ssl_algorithms (); - ssl_ctx_ = SSL_CTX_new (SSLv3_client_method ()); - if (ssl_ctx_ == 0) return -1; - - if (SSL_CTX_use_certificate_file (ssl_ctx_, - CLD_CERTIFICATE_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || SSL_CTX_use_PrivateKey_file (ssl_ctx_, - CLD_KEY_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || !SSL_CTX_check_private_key (ssl_ctx_)) { - SSL_CTX_free (ssl_ctx_); - ssl_ctx_ = 0; - return -1; - } - ssl_ = SSL_new (ssl_ctx_); - if (ssl_ == 0) { - SSL_CTX_free (ssl_ctx_); ssl_ctx_ = 0; - return -1; - } - } - - SSL_clear (ssl_); -#if defined (ACE_WIN32) - // ACE_WIN32 is the only platform where ACE_HANDLE is not an int. - // See ace/config-lite.h for the typedefs. - SSL_set_fd (ssl_, reinterpret_cast<int> (result.connect_handle ())); -#else - SSL_set_fd (ssl_, result.connect_handle ()); -#endif /* ACE_WIN32 */ - SSL_set_verify (ssl_, SSL_VERIFY_PEER, 0); - - if (SSL_connect (ssl_) == -1 - || SSL_shutdown (ssl_) == -1) return -1; - return 0; -} - -void AIO_CLD_Connector::handle_time_out -(const ACE_Time_Value&, const void *) { - this->connect (remote_addr_); -} - -/******************************************************/ - -int AIO_Client_Logging_Daemon::init - (int argc, ACE_TCHAR *argv[]) { - u_short cld_port = ACE_DEFAULT_SERVICE_PORT; - u_short sld_port = ACE_DEFAULT_LOGGING_SERVER_PORT; - ACE_TCHAR sld_host[MAXHOSTNAMELEN]; - ACE_OS::strcpy (sld_host, ACE_LOCALHOST); - - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:r:s:"), 0); - get_opt.long_option (ACE_TEXT ("client_port"), 'p', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_port"), 'r', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_name"), 's', - ACE_Get_Opt::ARG_REQUIRED); - - for (int c; (c = get_opt ()) != -1;) - switch (c) { - case 'p': // Client logging daemon acceptor port number. - cld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 'r': // Server logging daemon acceptor port number. - sld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 's': // Server logging daemon hostname. - ACE_OS::strsncpy - (sld_host, get_opt.opt_arg (), MAXHOSTNAMELEN); - break; - } - - if (cld_addr_.set (cld_port) == -1 || - sld_addr_.set (sld_port, sld_host) == -1) - return -1; - return activate (); -} - -int AIO_Client_Logging_Daemon::fini () { - ACE_Proactor::instance ()->proactor_end_event_loop (); - this->wait (); - return 0; -} - -int AIO_Client_Logging_Daemon::svc (void) { - if (acceptor_.open (cld_addr_) == -1) return -1; - if (CLD_CONNECTOR::instance ()->connect (sld_addr_) == 0) - ACE_Proactor::instance ()->proactor_run_event_loop (); - acceptor_.close (); - CLD_CONNECTOR::close (); - OUTPUT_HANDLER::close (); - return 0; -} - -#else /* There's no AIO support on this platform */ - -#include "ace/Task.h" -#include "ace/Service_Object.h" -#include "ace/Synch_Traits.h" -#include "AIO_CLD_export.h" - -class AIO_Client_Logging_Daemon : public ACE_Task<ACE_NULL_SYNCH> { -public: - // Service Configurator hook methods. - virtual int init (int, ACE_TCHAR *[]); - virtual int fini (); -}; - -int AIO_Client_Logging_Daemon::init (int, ACE_TCHAR *[]) { - - ACE_ERROR_RETURN - ((LM_ERROR, ACE_TEXT ("This service requires AIO support\n")), -1); -} - -int AIO_Client_Logging_Daemon::fini () { - return 0; -} - -ACE_FACTORY_DEFINE (AIO_CLD, AIO_Client_Logging_Daemon) - -#endif /* (ACE_WIN32 && !ACE_HAS_WINCE) || ACE_HAS_AIO_CALLS */ diff --git a/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.h b/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.h deleted file mode 100644 index 7c0d81da606..00000000000 --- a/ACE/examples/C++NPv2/AIO_Client_Logging_Daemon.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _AIO_CLIENT_LOGGING_DAEMON_H -#define _AIO_CLIENT_LOGGING_DAEMON_H - -#include "ace/Asynch_Connector.h" -#include "ace/Asynch_IO.h" -#include "ace/Message_Block.h" -#include "ace/Null_Mutex.h" -#include "ace/Proactor.h" -#include "ace/Singleton.h" -#include "ace/Synch_Traits.h" -#include "ace/Task.h" - -#include <openssl/ssl.h> - -class AIO_CLD_Acceptor; - -class AIO_Input_Handler : public ACE_Service_Handler { -public: - AIO_Input_Handler (AIO_CLD_Acceptor *acc = 0) - : acceptor_ (acc), mblk_ (0) {} - - virtual ~AIO_Input_Handler (); - - // Called by ACE_Asynch_Acceptor when a client connects. - virtual void open (ACE_HANDLE new_handle, - ACE_Message_Block &message_block); - -protected: - enum { LOG_HEADER_SIZE = 8 }; // Length of CDR header - AIO_CLD_Acceptor *acceptor_; // Our creator - ACE_Message_Block *mblk_; // Block to receive log record - ACE_Asynch_Read_Stream reader_; // Async read factory - - // Handle input from logging clients. - virtual void handle_read_stream - (const ACE_Asynch_Read_Stream::Result &result); -}; - - -class AIO_Output_Handler - : public ACE_Task<ACE_NULL_SYNCH>, - public ACE_Service_Handler { -public: - AIO_Output_Handler () : can_write_ (0) {} - - virtual ~AIO_Output_Handler (); - - // Entry point into the <AIO_Output_Handler>. - virtual int put (ACE_Message_Block *, ACE_Time_Value * = 0); - - // Hook method called when server connection is established. - using ACE_Service_Handler::open; - virtual void open (ACE_HANDLE new_handle, - ACE_Message_Block &message_block); - -protected: - ACE_Asynch_Read_Stream reader_; // Detects connection loss - ACE_Asynch_Write_Stream writer_; // Sends to server - int can_write_; // Safe to begin send a log record? - - // Initiate the send of a log record - void start_write (ACE_Message_Block *mblk = 0); - - // Handle disconnects from the logging server. - virtual void handle_read_stream - (const ACE_Asynch_Read_Stream::Result &result); - - // Handle completed write to logging server. - virtual void handle_write_stream - (const ACE_Asynch_Write_Stream::Result &result); -}; - -typedef ACE_Unmanaged_Singleton<AIO_Output_Handler, ACE_Null_Mutex> - OUTPUT_HANDLER; - - -class AIO_CLD_Connector - : public ACE_Asynch_Connector<AIO_Output_Handler> { -public: - enum { INITIAL_RETRY_DELAY = 3, MAX_RETRY_DELAY = 60 }; - - // Constructor. - AIO_CLD_Connector () - : retry_delay_ (INITIAL_RETRY_DELAY), ssl_ctx_ (0), ssl_ (0) - { open (); } - - // Destructor frees the SSL resources. - virtual ~AIO_CLD_Connector (void) { - SSL_free (ssl_); - SSL_CTX_free (ssl_ctx_); - proactor ()->cancel_timer (*this); - } - - // Hook method to detect failure and validate peer before - // opening handler. - virtual int validate_connection - (const ACE_Asynch_Connect::Result& result, - const ACE_INET_Addr &remote, const ACE_INET_Addr& local); - - // Re-establish a connection to the logging server. - int reconnect (void) { return connect (remote_addr_); } - -protected: - // Hook method called on timer expiration - retry connect - virtual void handle_time_out - (const ACE_Time_Value&, const void *); - - // Template method to create a new handler - virtual AIO_Output_Handler *make_handler (void) - { return OUTPUT_HANDLER::instance (); } - - // Address at which logging server listens for connections. - ACE_INET_Addr remote_addr_; - - // Seconds to wait before trying the next connect - int retry_delay_; - - // The SSL "context" data structure. - SSL_CTX *ssl_ctx_; - - // The SSL data structure corresponding to authenticated SSL - // connections. - SSL *ssl_; -}; - -typedef ACE_Unmanaged_Singleton<AIO_CLD_Connector, ACE_Null_Mutex> - CLD_CONNECTOR; - -#endif /* _AIO_CLIENT_LOGGING_DAEMON_H */ diff --git a/ACE/examples/C++NPv2/C++NPv2.mpc b/ACE/examples/C++NPv2/C++NPv2.mpc deleted file mode 100644 index 690fede986e..00000000000 --- a/ACE/examples/C++NPv2/C++NPv2.mpc +++ /dev/null @@ -1,184 +0,0 @@ -// -*- MPC -*- -// $Id$ - -// The specific section for gnuace is here to avoid problems -// with parallel builds. Since the libraries in question share source -// files, we need to ensure that one of them is built before all others. -// Also, a specific section was used because you can't set build order -// without setting a build dependency within vc6 and the like. - -project(*AC_CLD) : acelib, ssl { - requires += threads - avoids += uses_wchar - sharedname = AC_CLD - dynamicflags = AC_CLD_BUILD_DLL - specific(gnuace) { - after += *CLD - } - Source_Files { - AC_Client_Logging_Daemon.cpp - Logging_Handler.cpp - } -} - -project(*AIO_CLD) : acelib, ssl { - sharedname = AIO_CLD - dynamicflags = AIO_CLD_BUILD_DLL - Source_Files { - AIO_Client_Logging_Daemon.cpp - } -} - -project(*CLD) : acelib { - avoids += uses_wchar ace_for_tao - sharedname = CLD - dynamicflags = CLD_BUILD_DLL - Source_Files { - Client_Logging_Daemon.cpp - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Handler.cpp - } -} - -project(*Configurable_Log_Server) : aceexe { - avoids += uses_wchar - exename = configurable_logging_server - Source_Files { - Configurable_Logging_Server.cpp - Service_Reporter.cpp - } -} - -project(*Display_Logfile) : aceexe { - avoids += ace_for_tao - exename = display_logfile - Source_Files { - display_logfile.cpp - } -} - -project(*Reactor_Log_Server) : aceexe { - avoids += uses_wchar ace_for_tao - exename = reactor_logging_server - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Event_Handler_Ex.cpp - Logging_Handler.cpp - Reactor_Logging_Server.cpp - } -} - -project(*Select_Reactor_Log_Server) : aceexe { - avoids += uses_wchar ace_for_tao - exename = select_reactor_logging_server - specific(gnuace) { - after += *Reactor_Log_Server - } - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Event_Handler_Ex.cpp - Logging_Handler.cpp - Select_Reactor_Logging_Server.cpp - } -} - -project(*SLD) : acelib { - avoids += uses_wchar ace_for_tao - sharedname = SLD - dynamicflags = SLD_BUILD_DLL - specific(gnuace) { - after += *CLD - } - Source_Files { - SLD.cpp - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Handler.cpp - } -} - -project(*SLDex) : acelib { - avoids += uses_wchar ace_for_tao - sharedname = SLDex - dynamicflags = SLDEX_BUILD_DLL - specific(gnuace) { - after += *CLD - } - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Event_Handler_Ex.cpp - Logging_Handler.cpp - Reactor_Logging_Server_Adapter.cpp - Server_Shutdown.cpp - SLDex.cpp - } -} - -project(*SR_Configurable_Log_Server) : aceexe { - exename = sr_configurable_logging_server - Source_Files { - SR_Configurable_Logging_Server.cpp - } -} - -project(*TP_Reactor_Log_Server) : aceexe { - avoids += uses_wchar ace_for_tao - exename = tp_reactor_logging_server - specific(gnuace) { - after += *Reactor_Log_Server - } - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Event_Handler_Ex.cpp - Logging_Handler.cpp - TP_Reactor_Logging_Server.cpp - } -} - -project(*TPCLS) : acelib, ssl { - avoids += uses_wchar - sharedname = TPCLS - dynamicflags = TPCLS_BUILD_DLL - specific(gnuace) { - after += *CLD - } - Source_Files { - TPC_Logging_Server.cpp - Logging_Handler.cpp - } -} - -project(*TPLS) : acelib { - avoids += uses_wchar ace_for_tao - sharedname = TPLS - dynamicflags = TPLS_BUILD_DLL - specific(gnuace) { - after += *CLD - } - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Handler.cpp - TP_Logging_Server.cpp - } -} - -project(*WFMO_Reactor_Log_Server) : aceexe, wfmo { - avoids += uses_wchar ace_for_tao - exename = wfmo_reactor_logging_server - specific(gnuace) { - after += *Reactor_Log_Server - } - Source_Files { - Logging_Acceptor.cpp - Logging_Event_Handler.cpp - Logging_Event_Handler_Ex.cpp - Logging_Handler.cpp - WFMO_Reactor_Logging_Server.cpp - } -} diff --git a/ACE/examples/C++NPv2/CLD_export.h b/ACE/examples/C++NPv2/CLD_export.h deleted file mode 100644 index 3920094e133..00000000000 --- a/ACE/examples/C++NPv2/CLD_export.h +++ /dev/null @@ -1,38 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl CLD -// ------------------------------ -#ifndef CLD_EXPORT_H -#define CLD_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (CLD_HAS_DLL) -# define CLD_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! CLD_HAS_DLL */ - -#if !defined (CLD_HAS_DLL) -# define CLD_HAS_DLL 1 -#endif /* ! CLD_HAS_DLL */ - -#if defined (CLD_HAS_DLL) && (CLD_HAS_DLL == 1) -# if defined (CLD_BUILD_DLL) -# define CLD_Export ACE_Proper_Export_Flag -# define CLD_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* CLD_BUILD_DLL */ -# define CLD_Export ACE_Proper_Import_Flag -# define CLD_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* CLD_BUILD_DLL */ -#else /* CLD_HAS_DLL == 1 */ -# define CLD_Export -# define CLD_SINGLETON_DECLARATION(T) -# define CLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* CLD_HAS_DLL == 1 */ - -#endif /* CLD_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/Client_Logging_Daemon.cpp b/ACE/examples/C++NPv2/Client_Logging_Daemon.cpp deleted file mode 100644 index b17f8c455f0..00000000000 --- a/ACE/examples/C++NPv2/Client_Logging_Daemon.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/os_include/os_netdb.h" -#include "ace/OS_NS_sys_time.h" -#include "ace/OS_NS_sys_socket.h" -#include "ace/OS_NS_unistd.h" -#include "ace/OS_NS_string.h" -#include "ace/Event_Handler.h" -#include "ace/INET_Addr.h" -#include "ace/Get_Opt.h" -#include "ace/Log_Record.h" -#include "ace/Message_Block.h" -#include "ace/Message_Queue.h" -#include "ace/Reactor.h" -#include "ace/Service_Object.h" -#include "ace/Signal.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Stream.h" -#include "ace/Thread_Manager.h" -#include "Logging_Acceptor.h" -#include "CLD_export.h" - -#if !defined (FLUSH_TIMEOUT) -#define FLUSH_TIMEOUT 120 /* 120 seconds == 2 minutes. */ -#endif /* FLUSH_TIMEOUT */ - - -class CLD_Connector; - -class CLD_Handler : public ACE_Event_Handler { -public: - enum { QUEUE_MAX = sizeof (ACE_Log_Record) * ACE_IOV_MAX }; - - //FUZZ: disable check_for_lack_ACE_OS - // Initialization hook method. - virtual int open (CLD_Connector *); - virtual int close (); // Shut down hook method. - //FUZZ: enable check_for_lack_ACE_OS - - // Accessor to the connection to the logging server. - virtual ACE_SOCK_Stream &peer () { return peer_; } - - // Reactor hook methods. - virtual int handle_input (ACE_HANDLE handle); - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - -protected: - // Forward log records to the server logging daemon. - virtual ACE_THR_FUNC_RETURN forward (); - - //FUZZ: disable check_for_lack_ACE_OS - // Send the buffered log records using a gather-write operation. - virtual int send (ACE_Message_Block *chunk[], size_t &count); - //FUZZ: enable check_for_lack_ACE_OS - - // Entry point into forwarder thread of control. - static ACE_THR_FUNC_RETURN run_svc (void *arg); - - // A synchronized <ACE_Message_Queue> that queues messages. - ACE_Message_Queue<ACE_SYNCH> msg_queue_; - - // Manage the forwarder thread. - ACE_Thread_Manager thr_mgr_; - - // Pointer to our <CLD_Connector>. - CLD_Connector *connector_; - - // Connection to the logging server. - ACE_SOCK_Stream peer_; -}; - - -class CLD_Connector { -public: - //FUZZ: disable check_for_lack_ACE_OS - // Establish a connection to the logging server - // at the <remote_addr>. - int connect (CLD_Handler *handler, - const ACE_INET_Addr &remote_addr); - //FUZZ: enable check_for_lack_ACE_OS - - // Re-establish a connection to the logging server. - int reconnect (); - -private: - // Pointer to the <CLD_Handler> that we're connecting. - CLD_Handler *handler_; - - // Address at which the logging server is listening - // for connections. - ACE_INET_Addr remote_addr_; -}; - - -class CLD_Acceptor : public ACE_Event_Handler { -public: - //FUZZ: disable check_for_lack_ACE_OS - // Initialization hook method. - virtual int open (CLD_Handler *, const ACE_INET_Addr &, - ACE_Reactor * = ACE_Reactor::instance ()); - //FUZZ: enable check_for_lack_ACE_OS - - // Reactor hook methods. - virtual int handle_input (ACE_HANDLE handle); - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - virtual ACE_HANDLE get_handle () const; - -protected: - // Factory that passively connects <ACE_SOCK_Stream>s. - ACE_SOCK_Acceptor acceptor_; - - // Pointer to the handler of log records. - CLD_Handler *handler_; -}; - -/****************************************************/ - -int CLD_Handler::handle_input (ACE_HANDLE handle) { - ACE_Message_Block *mblk = 0; - Logging_Handler logging_handler (handle); - - if (logging_handler.recv_log_record (mblk) != -1) - if (msg_queue_.enqueue_tail (mblk->cont ()) != -1) { - mblk->cont (0); - mblk->release (); - return 0; // Success return. - } else mblk->release (); - return -1; // Error return. -} - - -int CLD_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask) -{ return ACE_OS::closesocket (handle); } - - -int CLD_Handler::open (CLD_Connector *connector) { - connector_ = connector; - int bufsiz = ACE_DEFAULT_MAX_SOCKET_BUFSIZ; - peer ().set_option (SOL_SOCKET, SO_SNDBUF, - &bufsiz, sizeof bufsiz); - msg_queue_.high_water_mark (CLD_Handler::QUEUE_MAX); - return thr_mgr_.spawn (&CLD_Handler::run_svc, - this, THR_SCOPE_SYSTEM); -} - - -ACE_THR_FUNC_RETURN CLD_Handler::run_svc (void *arg) { - CLD_Handler *handler = static_cast<CLD_Handler *> (arg); - return handler->forward (); -} - - -ACE_THR_FUNC_RETURN CLD_Handler::forward () { - ACE_Message_Block *chunk[ACE_IOV_MAX]; - size_t message_index = 0; - ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ()); - ACE_Time_Value timeout; - ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN); - ACE_Sig_Action original_action; - no_sigpipe.register_action (SIGPIPE, &original_action); - - for (;;) { - if (message_index == 0) { - timeout = ACE_OS::gettimeofday (); - timeout += FLUSH_TIMEOUT; - } - ACE_Message_Block *mblk = 0; - if (msg_queue_.dequeue_head (mblk, &timeout) == -1) { - if (errno != EWOULDBLOCK) break; - else if (message_index == 0) continue; - } else { - if (mblk->size () == 0 - && mblk->msg_type () == ACE_Message_Block::MB_STOP) - { mblk->release (); break; } - chunk[message_index] = mblk; - ++message_index; - } - if (message_index >= ACE_IOV_MAX || - (ACE_OS::gettimeofday () - time_of_last_send - >= ACE_Time_Value(FLUSH_TIMEOUT))) { - if (this->send (chunk, message_index) == -1) break; - time_of_last_send = ACE_OS::gettimeofday (); - } - } - - if (message_index > 0) - this->send (chunk, message_index); - - msg_queue_.close (); - no_sigpipe.restore_action (SIGPIPE, original_action); - return 0; -} - - -int CLD_Handler::send (ACE_Message_Block *chunk[], size_t &count) { - iovec iov[ACE_IOV_MAX]; - size_t iov_size; - int result = 0; - - for (iov_size = 0; iov_size < count; ++iov_size) { - iov[iov_size].iov_base = chunk[iov_size]->rd_ptr (); - iov[iov_size].iov_len = chunk[iov_size]->length (); - } - while (peer ().sendv_n (iov, iov_size) == -1) - if (connector_->reconnect () == -1) { - result = -1; - break; - } - - while (iov_size > 0) { - chunk[--iov_size]->release (); chunk[iov_size] = 0; - } - count = iov_size; - return result; -} - - -int CLD_Handler::close () { - ACE_Message_Block *shutdown_message = 0; - ACE_NEW_RETURN - (shutdown_message, - ACE_Message_Block (0, ACE_Message_Block::MB_STOP), -1); - msg_queue_.enqueue_tail (shutdown_message); - return thr_mgr_.wait (); -} - -/**************************************************************/ - - -int CLD_Acceptor::open (CLD_Handler *handler, - const ACE_INET_Addr &local_addr, - ACE_Reactor *r) { - reactor (r); // Store the reactor pointer. - handler_ = handler; - if (acceptor_.open (local_addr) == -1 - || reactor ()->register_handler - (this, ACE_Event_Handler::ACCEPT_MASK) == -1) - return -1; - return 0; -} - - -ACE_HANDLE CLD_Acceptor::get_handle () const -{ return acceptor_.get_handle (); } - - -int CLD_Acceptor::handle_input (ACE_HANDLE) { - ACE_SOCK_Stream peer_stream; - if (acceptor_.accept (peer_stream) == -1) return -1; - else if (reactor ()->register_handler - (peer_stream.get_handle (), - handler_, - ACE_Event_Handler::READ_MASK) == -1) - return -1; - else return 0; -} - - -int CLD_Acceptor::handle_close (ACE_HANDLE, ACE_Reactor_Mask) { - acceptor_.close (); - handler_->close (); - return 0; -} - - -/***************************************************/ - - -int CLD_Connector::connect - (CLD_Handler *handler, - const ACE_INET_Addr &remote_addr) { - ACE_SOCK_Connector connector; - - if (connector.connect (handler->peer (), remote_addr) == -1) - return -1; - else if (handler->open (this) == -1) - { handler->handle_close (); return -1; } - handler_ = handler; - remote_addr_ = remote_addr; - return 0; -} - - -int CLD_Connector::reconnect () { - // Maximum number of times to retry connect. - const size_t MAX_RETRIES = 5; - - ACE_SOCK_Connector connector; - ACE_Time_Value timeout (1); // Start with 1 second timeout. - size_t i; - for (i = 0; i < MAX_RETRIES; ++i) { - if (i > 0) ACE_OS::sleep (timeout); - if (connector.connect (handler_->peer (), remote_addr_, - &timeout) == -1) - timeout *= 2; // Exponential backoff. - else { - int bufsiz = ACE_DEFAULT_MAX_SOCKET_BUFSIZ; - handler_->peer ().set_option (SOL_SOCKET, SO_SNDBUF, - &bufsiz, sizeof bufsiz); - break; - } - } - return i == MAX_RETRIES ? -1 : 0; -} - - -/*******************************************************/ - -class Client_Logging_Daemon : public ACE_Service_Object { -public: - virtual ~Client_Logging_Daemon () {} // Turn off g++ warnings. - - // Service Configurator hook methods. - virtual int init (int argc, ACE_TCHAR *argv[]); - virtual int fini (); -#if 0 - // Implementing these methods is left as an exercise for the reader. - virtual int info (ACE_TCHAR **bufferp, size_t length = 0) const; - virtual int suspend (); - virtual int resume (); -#endif - -protected: - // Receives, processes, and forwards log records. - CLD_Handler handler_; - - // Factory that passively connects the <CLD_Handler>. - CLD_Acceptor acceptor_; - - // Factory that actively connects the <CLD_Handler>. - CLD_Connector connector_; -}; - - -int Client_Logging_Daemon::init (int argc, ACE_TCHAR *argv[]) { - u_short cld_port = ACE_DEFAULT_SERVICE_PORT; - u_short sld_port = ACE_DEFAULT_LOGGING_SERVER_PORT; - ACE_TCHAR sld_host[MAXHOSTNAMELEN]; - ACE_OS::strcpy (sld_host, ACE_LOCALHOST); - - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:r:s:"), 0); - get_opt.long_option (ACE_TEXT ("client_port"), 'p', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_port"), 'r', - ACE_Get_Opt::ARG_REQUIRED); - get_opt.long_option (ACE_TEXT ("server_name"), 's', - ACE_Get_Opt::ARG_REQUIRED); - - for (int c; (c = get_opt ()) != -1;) - switch (c) { - case 'p': // Client logging daemon acceptor port number. - cld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 'r': // Server logging daemon acceptor port number. - sld_port = static_cast<u_short> (ACE_OS::atoi (get_opt.opt_arg ())); - break; - case 's': // Server logging daemon hostname. - ACE_OS::strsncpy - (sld_host, get_opt.opt_arg (), MAXHOSTNAMELEN); - break; - } - - ACE_INET_Addr cld_addr (cld_port); - ACE_INET_Addr sld_addr (sld_port, sld_host); - - if (acceptor_.open (&handler_, cld_addr) == -1) - return -1; - else if (connector_.connect (&handler_, sld_addr) == -1) - { acceptor_.handle_close (); return -1; } - return 0; -} - - -int Client_Logging_Daemon::fini () { - acceptor_.handle_close (); - handler_.close (); - return 0; -} - - -ACE_FACTORY_DEFINE (CLD, Client_Logging_Daemon) diff --git a/ACE/examples/C++NPv2/Configurable_Logging_Server.cpp b/ACE/examples/C++NPv2/Configurable_Logging_Server.cpp deleted file mode 100644 index bcd6d42b884..00000000000 --- a/ACE/examples/C++NPv2/Configurable_Logging_Server.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_main.h" -#include "ace/Service_Config.h" -#include "ace/Reactor.h" - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - - ACE_STATIC_SVC_REGISTER (Reporter_Descriptor); - - ACE_Service_Config::open - (argc, argv, ACE_DEFAULT_LOGGER_KEY, 0); - - ACE_Reactor::instance ()->run_reactor_event_loop (); - return 0; -} diff --git a/ACE/examples/C++NPv2/Logging_Acceptor.cpp b/ACE/examples/C++NPv2/Logging_Acceptor.cpp deleted file mode 100644 index 2e7b7479603..00000000000 --- a/ACE/examples/C++NPv2/Logging_Acceptor.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "Logging_Acceptor.h" -#include "Logging_Event_Handler.h" - - -int Logging_Acceptor::open (const ACE_INET_Addr &local_addr) { - if (acceptor_.open (local_addr) == -1) return -1; - return reactor ()->register_handler - (this, ACE_Event_Handler::ACCEPT_MASK); -} - -int Logging_Acceptor::handle_input (ACE_HANDLE) { - Logging_Event_Handler *peer_handler = 0; - ACE_NEW_RETURN (peer_handler, - Logging_Event_Handler (reactor ()), - -1); - - if (acceptor_.accept (peer_handler->peer ()) == -1) { - delete peer_handler; - return -1; - } else if (peer_handler->open () == -1) { - peer_handler->handle_close (); - return -1; - } - return 0; -} - -int Logging_Acceptor::handle_close (ACE_HANDLE, - ACE_Reactor_Mask) { - acceptor_.close (); - delete this; - return 0; -} diff --git a/ACE/examples/C++NPv2/Logging_Acceptor.h b/ACE/examples/C++NPv2/Logging_Acceptor.h deleted file mode 100644 index 7d38439e3eb..00000000000 --- a/ACE/examples/C++NPv2/Logging_Acceptor.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_ACCEPTOR_H -#define _LOGGING_ACCEPTOR_H - -#include "ace/Event_Handler.h" -#include "ace/INET_Addr.h" -#include "ace/Log_Record.h" -#include "ace/Reactor.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" -#include "Logging_Handler.h" - -class Logging_Acceptor : public ACE_Event_Handler -{ -protected: - // Factory that connects <ACE_SOCK_Stream>s passively. - ACE_SOCK_Acceptor acceptor_; - -protected: - virtual ~Logging_Acceptor () {}; // No-op destructor. - -public: - typedef ACE_INET_Addr PEER_ADDR; - - // Simple constructor. - Logging_Acceptor (ACE_Reactor *r = ACE_Reactor::instance ()) - : ACE_Event_Handler (r) {}; - - // Initialization method. - virtual int open (const ACE_INET_Addr &local_addr); - - // Called by a reactor when there's a new connection to accept. - virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); - - // Called when this object is destroyed, e.g., when it's - // removed from a reactor. - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - - // Return the passive-mode socket's I/O handle. - virtual ACE_HANDLE get_handle () const - { return acceptor_.get_handle (); }; - - // Returns a reference to the underlying <acceptor_>. - ACE_SOCK_Acceptor &acceptor () { return acceptor_; }; -}; - -#endif /* _LOGGING_ACCEPTOR_H */ diff --git a/ACE/examples/C++NPv2/Logging_Acceptor_Ex.h b/ACE/examples/C++NPv2/Logging_Acceptor_Ex.h deleted file mode 100644 index 913ae385db6..00000000000 --- a/ACE/examples/C++NPv2/Logging_Acceptor_Ex.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_ACCEPTOR_EX_H -#define _LOGGING_ACCEPTOR_EX_H - -#include "ace/INET_Addr.h" -#include "ace/Reactor.h" - -#include "Logging_Acceptor.h" -#include "Logging_Event_Handler_Ex.h" - -class Logging_Acceptor_Ex : public Logging_Acceptor -{ -public: - typedef ACE_INET_Addr PEER_ADDR; - - // Simple constructor to pass ACE_Reactor to base class. - Logging_Acceptor_Ex (ACE_Reactor *r = ACE_Reactor::instance ()) - : Logging_Acceptor (r) {} - - int handle_input (ACE_HANDLE) { - Logging_Event_Handler_Ex *peer_handler = 0; - ACE_NEW_RETURN (peer_handler, - Logging_Event_Handler_Ex (reactor ()), - -1); - if (acceptor_.accept (peer_handler->peer ()) == -1) { - delete peer_handler; - return -1; - } else if (peer_handler->open () == -1) { - peer_handler->handle_close (); - return -1; - } - return 0; - } -}; - -#endif /* _LOGGING_ACCEPTOR_EX_H */ diff --git a/ACE/examples/C++NPv2/Logging_Event_Handler.cpp b/ACE/examples/C++NPv2/Logging_Event_Handler.cpp deleted file mode 100644 index d805e776390..00000000000 --- a/ACE/examples/C++NPv2/Logging_Event_Handler.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/FILE_Connector.h" - -#include "Logging_Event_Handler.h" -#include "ace/OS_NS_string.h" -#include "ace/os_include/os_netdb.h" - -int Logging_Event_Handler::open () { - - static const char LOGFILE_SUFFIX[] = ".log"; - char filename[MAXHOSTNAMELEN + sizeof (LOGFILE_SUFFIX)]; - ACE_INET_Addr logging_peer_addr; - - logging_handler_.peer ().get_remote_addr (logging_peer_addr); - logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN); - ACE_OS::strcat (filename, LOGFILE_SUFFIX); - - ACE_FILE_Connector connector; - connector.connect (log_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); - - return reactor ()->register_handler - (this, ACE_Event_Handler::READ_MASK); -} - -int Logging_Event_Handler::handle_input (ACE_HANDLE) -{ return logging_handler_.log_record (); } - -int Logging_Event_Handler::handle_close (ACE_HANDLE, - ACE_Reactor_Mask) { - logging_handler_.close (); - log_file_.close (); - delete this; - return 0; -} diff --git a/ACE/examples/C++NPv2/Logging_Event_Handler.h b/ACE/examples/C++NPv2/Logging_Event_Handler.h deleted file mode 100644 index f1a71364be5..00000000000 --- a/ACE/examples/C++NPv2/Logging_Event_Handler.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_EVENT_HANDLER_H -#define _LOGGING_EVENT_HANDLER_H - -#include "ace/Event_Handler.h" -#include "ace/FILE_IO.h" -#include "ace/Reactor.h" -#include "ace/SOCK_Stream.h" - -#include "Logging_Handler.h" - -class Logging_Event_Handler : public ACE_Event_Handler -{ -protected: - // File where log records are written. - ACE_FILE_IO log_file_; - - // Connection to remote peer. - Logging_Handler logging_handler_; - -public: - // Initialize the base class and logging handler. - Logging_Event_Handler (ACE_Reactor *reactor) - : ACE_Event_Handler (reactor), - logging_handler_ (log_file_) {}; - - virtual ~Logging_Event_Handler () {}; // No-op destructor. - - // Activate the object. - virtual int open (); - - // Called by a reactor when logging events arrive. - virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); - - // Called when this object is destroyed, e.g., when it's - // removed from a reactor. - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); - - // Return socket handle of the contained <Logging_Handler>. - virtual ACE_HANDLE get_handle (void) const { - // Need a non-const reference to call peer(), but that's - // safe since we call a const method using it. - Logging_Handler& h = - const_cast<Logging_Handler&> (logging_handler_); - return h.peer ().get_handle (); - }; - - // Get a reference to the contained <ACE_SOCK_Stream>. - ACE_SOCK_Stream &peer () { return logging_handler_.peer (); }; - - // Return a reference to the <log_file_>. - ACE_FILE_IO &log_file () { return log_file_; }; -}; - -#endif /* _LOGGING_EVENT_HANDLER_H */ diff --git a/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.cpp b/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.cpp deleted file mode 100644 index 858e615e9d9..00000000000 --- a/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "Logging_Event_Handler_Ex.h" -#include "ace/Timer_Queue.h" - -int Logging_Event_Handler_Ex::handle_input (ACE_HANDLE h) { - time_of_last_log_record_ = - reactor ()->timer_queue ()->gettimeofday (); - return PARENT::handle_input (h); -} - -int Logging_Event_Handler_Ex::open () { - int result = PARENT::open (); - if (result != -1) { - ACE_Time_Value reschedule (max_client_timeout_.sec () / 4); - result = - reactor ()->schedule_timer - (this, - 0, - max_client_timeout_, // Initial timeout. - reschedule); // Subsequent timeouts. - } - return result; -} - -int Logging_Event_Handler_Ex::handle_timeout - (const ACE_Time_Value &now, const void *) { - if (now - time_of_last_log_record_ >= max_client_timeout_) - reactor ()->remove_handler (this, ACE_Event_Handler::READ_MASK); - return 0; -} - -int Logging_Event_Handler_Ex::handle_close (ACE_HANDLE, - ACE_Reactor_Mask) { - reactor ()->cancel_timer (this); - return PARENT::handle_close (); -} diff --git a/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.h b/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.h deleted file mode 100644 index d6639cf78d2..00000000000 --- a/ACE/examples/C++NPv2/Logging_Event_Handler_Ex.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _LOGGING_EVENT_HANDLER_EX_H -#define _LOGGING_EVENT_HANDLER_EX_H - -#include "ace/Reactor.h" -#include "ace/Time_Value.h" -#include "ace/Recursive_Thread_Mutex.h" - -#include "Logging_Event_Handler.h" - -class Logging_Event_Handler_Ex : public Logging_Event_Handler -{ -private: - // Time when a client last sent a log record. - ACE_Time_Value time_of_last_log_record_; - - // Maximum time to wait for a client log record. - const ACE_Time_Value max_client_timeout_; - -public: - typedef Logging_Event_Handler PARENT; - - // 3600 seconds == one hour. - enum { MAX_CLIENT_TIMEOUT = 3600 }; - - Logging_Event_Handler_Ex - (ACE_Reactor *reactor, - const ACE_Time_Value &max_client_timeout - = ACE_Time_Value (MAX_CLIENT_TIMEOUT)) - : Logging_Event_Handler (reactor), - time_of_last_log_record_ (0), - max_client_timeout_ (max_client_timeout) {} - - virtual ~Logging_Event_Handler_Ex () {} - - virtual int open (); // Activate the event handler. - - // Called by a reactor when logging events arrive. - virtual int handle_input (ACE_HANDLE); - - // Called when a timeout expires to check if the client has - // been idle for an excessive amount of time. - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *act); - - // Called when this object is destroyed, e.g., when it's - // removed from a reactor. - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = 0); -}; - -#endif /* _LOGGING_EVENT_HANDLER_EX_H */ diff --git a/ACE/examples/C++NPv2/Logging_Handler.cpp b/ACE/examples/C++NPv2/Logging_Handler.cpp deleted file mode 100644 index a3febb8234d..00000000000 --- a/ACE/examples/C++NPv2/Logging_Handler.cpp +++ /dev/null @@ -1,110 +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" - -// FUZZ: disable check_for_streams_include -#include "ace/streams.h" - -#include "Logging_Handler.h" -#include "ace/os_include/os_netdb.h" -#include "ace/OS_NS_string.h" - -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 (ACE_OS::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/ACE/examples/C++NPv2/Logging_Handler.h b/ACE/examples/C++NPv2/Logging_Handler.h deleted file mode 100644 index 41945c3a182..00000000000 --- a/ACE/examples/C++NPv2/Logging_Handler.h +++ /dev/null @@ -1,57 +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" - -ACE_BEGIN_VERSIONED_NAMESPACE_DECL -class ACE_Message_Block; -ACE_END_VERSIONED_NAMESPACE_DECL - -class Logging_Handler -{ -protected: - ACE_FILE_IO *log_file_; // Pointer 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) {}; - Logging_Handler (const ACE_SOCK_Stream &logging_peer) - : log_file_ (0), 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/ACE/examples/C++NPv2/Makefile.am b/ACE/examples/C++NPv2/Makefile.am deleted file mode 100644 index f6c3d89bc4e..00000000000 --- a/ACE/examples/C++NPv2/Makefile.am +++ /dev/null @@ -1,427 +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: -## ./bin/mwc.pl -type automake -noreldefs ACE.mwc - -ACE_BUILDDIR = $(top_builddir) -ACE_ROOT = $(top_srcdir) - -noinst_HEADERS = -noinst_LTLIBRARIES = -noinst_PROGRAMS = - -## Makefile.C++NPv2_AC_CLD.am - -if BUILD_SSL -if BUILD_THREADS -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libAC_CLD.la - -libAC_CLD_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DACE_HAS_SSL=1 \ - @ACE_TLS_CPPFLAGS@ \ - -DAC_CLD_BUILD_DLL - -libAC_CLD_la_SOURCES = \ - AC_Client_Logging_Daemon.cpp \ - Logging_Handler.cpp - -libAC_CLD_la_LDFLAGS = \ - @ACE_TLS_LDFLAGS@ - -noinst_HEADERS += \ - AC_Client_Logging_Daemon.h \ - Logging_Handler.h \ - Reactor_Logging_Server_T.cpp - -endif !BUILD_USES_WCHAR -endif BUILD_THREADS -endif BUILD_SSL - -## Makefile.C++NPv2_AIO_CLD.am - -if BUILD_SSL - -noinst_LTLIBRARIES += libAIO_CLD.la - -libAIO_CLD_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DACE_HAS_SSL=1 \ - @ACE_TLS_CPPFLAGS@ \ - -DAIO_CLD_BUILD_DLL - -libAIO_CLD_la_SOURCES = \ - AIO_Client_Logging_Daemon.cpp - -libAIO_CLD_la_LDFLAGS = \ - @ACE_TLS_LDFLAGS@ - -noinst_HEADERS += \ - AIO_Client_Logging_Daemon.h \ - Reactor_Logging_Server_T.cpp - -endif BUILD_SSL - -## Makefile.C++NPv2_CLD.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libCLD.la - -libCLD_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DCLD_BUILD_DLL - -libCLD_la_SOURCES = \ - Client_Logging_Daemon.cpp \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Handler.cpp - -noinst_HEADERS += \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Handler.h \ - Reactor_Logging_Server_T.cpp - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_Configurable_Log_Server.am - -if !BUILD_USES_WCHAR - -noinst_PROGRAMS += configurable_logging_server - -configurable_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -configurable_logging_server_SOURCES = \ - Configurable_Logging_Server.cpp \ - Service_Reporter.cpp \ - Service_Reporter.h - -configurable_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_USES_WCHAR - -## Makefile.C++NPv2_Display_Logfile.am - -if !BUILD_ACE_FOR_TAO - -noinst_PROGRAMS += display_logfile - -display_logfile_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -display_logfile_SOURCES = \ - display_logfile.cpp \ - AC_CLD_export.h \ - AC_Client_Logging_Daemon.h \ - AIO_CLD_export.h \ - AIO_Client_Logging_Daemon.h \ - CLD_export.h \ - Logging_Acceptor.h \ - Logging_Acceptor_Ex.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h \ - Reactor_Logging_Server_Adapter.h \ - Reactor_Logging_Server_T.h \ - SLDEX_export.h \ - SLD_export.h \ - Service_Reporter.h \ - TPCLS_export.h \ - TPC_Logging_Server.h \ - TPLS_export.h \ - TP_Logging_Server.h - -display_logfile_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_Reactor_Log_Server.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_PROGRAMS += reactor_logging_server - -reactor_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -reactor_logging_server_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Event_Handler_Ex.cpp \ - Logging_Handler.cpp \ - Reactor_Logging_Server.cpp \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h - -reactor_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_SLD.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libSLD.la - -libSLD_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DSLD_BUILD_DLL - -libSLD_la_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Handler.cpp \ - SLD.cpp - -noinst_HEADERS += \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Handler.h \ - Reactor_Logging_Server_T.cpp - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_SLDex.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libSLDex.la - -libSLDex_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DSLDEX_BUILD_DLL - -libSLDex_la_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Event_Handler_Ex.cpp \ - Logging_Handler.cpp \ - Reactor_Logging_Server_Adapter.cpp \ - SLDex.cpp \ - Server_Shutdown.cpp - -noinst_HEADERS += \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h \ - Reactor_Logging_Server_Adapter.h \ - Reactor_Logging_Server_T.cpp - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_SR_Configurable_Log_Server.am - -noinst_PROGRAMS += sr_configurable_logging_server - -sr_configurable_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -sr_configurable_logging_server_SOURCES = \ - SR_Configurable_Logging_Server.cpp \ - AC_CLD_export.h \ - AC_Client_Logging_Daemon.h \ - AIO_CLD_export.h \ - AIO_Client_Logging_Daemon.h \ - CLD_export.h \ - Logging_Acceptor.h \ - Logging_Acceptor_Ex.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h \ - Reactor_Logging_Server_Adapter.h \ - Reactor_Logging_Server_T.h \ - SLDEX_export.h \ - SLD_export.h \ - Service_Reporter.h \ - TPCLS_export.h \ - TPC_Logging_Server.h \ - TPLS_export.h \ - TP_Logging_Server.h - -sr_configurable_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -## Makefile.C++NPv2_Select_Reactor_Log_Server.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_PROGRAMS += select_reactor_logging_server - -select_reactor_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -select_reactor_logging_server_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Event_Handler_Ex.cpp \ - Logging_Handler.cpp \ - Select_Reactor_Logging_Server.cpp \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h - -select_reactor_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_TPCLS.am - -if BUILD_SSL -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libTPCLS.la - -libTPCLS_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DACE_HAS_SSL=1 \ - @ACE_TLS_CPPFLAGS@ \ - -DTPCLS_BUILD_DLL - -libTPCLS_la_SOURCES = \ - Logging_Handler.cpp \ - TPC_Logging_Server.cpp - -libTPCLS_la_LDFLAGS = \ - @ACE_TLS_LDFLAGS@ - -noinst_HEADERS += \ - Logging_Handler.h \ - Reactor_Logging_Server_T.cpp \ - TPC_Logging_Server.h - -endif !BUILD_USES_WCHAR -endif BUILD_SSL - -## Makefile.C++NPv2_TPLS.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_LTLIBRARIES += libTPLS.la - -libTPLS_la_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) \ - -DTPLS_BUILD_DLL - -libTPLS_la_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Handler.cpp \ - TP_Logging_Server.cpp - -noinst_HEADERS += \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Handler.h \ - Reactor_Logging_Server_T.cpp \ - TP_Logging_Server.h - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_TP_Reactor_Log_Server.am - -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_PROGRAMS += tp_reactor_logging_server - -tp_reactor_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -tp_reactor_logging_server_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Event_Handler_Ex.cpp \ - Logging_Handler.cpp \ - TP_Reactor_Logging_Server.cpp \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h - -tp_reactor_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO - -## Makefile.C++NPv2_WFMO_Reactor_Log_Server.am - -if BUILD_WFMO -if !BUILD_ACE_FOR_TAO -if !BUILD_USES_WCHAR - -noinst_PROGRAMS += wfmo_reactor_logging_server - -wfmo_reactor_logging_server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -wfmo_reactor_logging_server_SOURCES = \ - Logging_Acceptor.cpp \ - Logging_Event_Handler.cpp \ - Logging_Event_Handler_Ex.cpp \ - Logging_Handler.cpp \ - WFMO_Reactor_Logging_Server.cpp \ - Logging_Acceptor.h \ - Logging_Event_Handler.h \ - Logging_Event_Handler_Ex.h \ - Logging_Handler.h - -wfmo_reactor_logging_server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -endif !BUILD_USES_WCHAR -endif !BUILD_ACE_FOR_TAO -endif BUILD_WFMO - -## 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/ACE/examples/C++NPv2/README b/ACE/examples/C++NPv2/README deleted file mode 100644 index a2d8759dd80..00000000000 --- a/ACE/examples/C++NPv2/README +++ /dev/null @@ -1,99 +0,0 @@ -(This is file $Id$) - -The files in this directory contain the source code from the book -``C++ Network Programming: Systematic Reuse with ACE and Frameworks'' -(C++NPv2) by Douglas C. Schmidt and Stephen D. Huston (Addison-Wesley -2001, ISBN 0-201-79525-6). - -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++NPv2 as follows: - -Chapter 3 Logging_Acceptor.cpp - Logging_Acceptor.h - Logging_Acceptor_Ex.h - Logging_Event_Handler.cpp - Logging_Event_Handler.h - Logging_Event_Handler_Ex.cpp - Logging_Event_Handler_Ex.h - Logging_Handler.cpp - Logging_Handler.h - Reactor_Logging_Server.cpp - Reactor_Logging_Server_T.h - Reactor_Logging_Server_T.cpp - -Chapter 4 Select_Reactor_Logging_Server.cpp - TP_Reactor_Logging_Server.cpp - WFMO_Reactor_Logging_Server.cpp - -Chapter 5 Configurable_Logging_Server.cpp - Reactor_Logging_Server_Adapter.cpp - Reactor_Logging_Server_Adapter.h - Service_Reporter.cpp - Service_Reporter.h - Server_Shutdown.cpp - SLD.cpp - SLDEX_export.h - SLD_export.h - SLDex.cpp - -Chapter 6 Client_Logging_Daemon.cpp - CLD_export.h - TPLS_export.h - TP_Logging_Server.cpp - TP_Logging_Server.h - -Chapter 7 AC_CLD_export.h - AC_Client_Logging_Daemon.cpp - SR_Configurable_Logging_Server.cpp - TPC_Logging_Server.cpp - TPC_Logging_Server.h - TPCLS_export.h - -Chapter 8 AIO_CLD_export.h - AIO_Client_Logging_Daemon.cpp - -Chapter 9 display_logfile.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, display_logfile.mak -is the makefile for the display_logfile 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/ACE/examples/C++NPv2/Reactor_Logging_Server.cpp b/ACE/examples/C++NPv2/Reactor_Logging_Server.cpp deleted file mode 100644 index 269e158d243..00000000000 --- a/ACE/examples/C++NPv2/Reactor_Logging_Server.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "Reactor_Logging_Server_T.h" -#include "Logging_Acceptor_Ex.h" -#include "ace/Log_Msg.h" - -typedef Reactor_Logging_Server<Logging_Acceptor_Ex> - Server_Logging_Daemon; - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - ACE_Reactor reactor; - Server_Logging_Daemon *server; - // Ignore argv[0]... - --argc; ++argv; - ACE_NEW_RETURN (server, - Server_Logging_Daemon (argc, argv, &reactor), - 1); - - if (reactor.run_reactor_event_loop () == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", - "run_reactor_event_loop()"), 1); - return 0; -} - diff --git a/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.cpp b/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.cpp deleted file mode 100644 index 128ad5cabd3..00000000000 --- a/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _REACTOR_LOGGING_SERVER_ADAPTER_C -#define _REACTOR_LOGGING_SERVER_ADAPTER_C - -#include "ace/ACE.h" -#include "ace/Auto_Ptr.h" -#include "ace/INET_Addr.h" -#include "Reactor_Logging_Server_Adapter.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_stdio.h" - -template <class ACCEPTOR> int -Reactor_Logging_Server_Adapter<ACCEPTOR>::init (int argc, - ACE_TCHAR *argv[]) { - int i; - char **array = 0; - ACE_NEW_RETURN (array, char*[argc], -1); - ACE_Auto_Array_Ptr<char *> char_argv (array); - - for (i = 0; i < argc; ++i) - char_argv[i] = ACE::strnew (ACE_TEXT_ALWAYS_CHAR (argv[i])); - ACE_NEW_NORETURN (server_, Reactor_Logging_Server<ACCEPTOR> - (i, char_argv.get (), - ACE_Reactor::instance ())); - for (i = 0; i < argc; ++i) ACE::strdelete (char_argv[i]); - return server_ == 0 ? -1 : 0; -} - - -template <class ACCEPTOR> int -Reactor_Logging_Server_Adapter<ACCEPTOR>::fini () -{ server_->handle_close (); server_ = 0; return 0; } - - -template <class ACCEPTOR> int -Reactor_Logging_Server_Adapter<ACCEPTOR>::info - (ACE_TCHAR **bufferp, size_t length) const { - ACE_INET_Addr local_addr; - server_->acceptor ().get_local_addr (local_addr); - - ACE_TCHAR buf[BUFSIZ]; - ACE_OS::sprintf (buf, - ACE_TEXT ("%hu"), - local_addr.get_port_number ()); - ACE_OS::strcat - (buf, ACE_TEXT ("/tcp # Reactor-based logging server\n")); - if (*bufferp == 0) - *bufferp = ACE::strnew (buf); - else - ACE_OS::strncpy (*bufferp, buf, length); - return ACE_OS::strlen (*bufferp); -} - - -template <class ACCEPTOR> int -Reactor_Logging_Server_Adapter<ACCEPTOR>::suspend () -{ return server_->reactor ()->suspend_handler (server_); } - - -template <class ACCEPTOR> int -Reactor_Logging_Server_Adapter<ACCEPTOR>::resume () -{ return server_->reactor ()->resume_handler (server_); } - -#endif /* _REACTOR_LOGGING_SERVER_ADAPTER_C */ diff --git a/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.h b/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.h deleted file mode 100644 index aeda81205ab..00000000000 --- a/ACE/examples/C++NPv2/Reactor_Logging_Server_Adapter.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _REACTOR_LOGGING_SERVER_ADAPTER_H -#define _REACTOR_LOGGING_SERVER_ADAPTER_H - -#include "ace/Service_Object.h" -#include "Reactor_Logging_Server_T.h" - -template <class ACCEPTOR> -class Reactor_Logging_Server_Adapter : public ACE_Service_Object { -public: - // Hook methods inherited from <ACE_Service_Object>. - virtual int init (int argc, ACE_TCHAR *argv[]); - virtual int fini (); - virtual int info (ACE_TCHAR **, size_t) const; - virtual int suspend (); - virtual int resume (); - -private: - Reactor_Logging_Server<ACCEPTOR> *server_; -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Reactor_Logging_Server_Adapter.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Reactor_Logging_Server_Adapter.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#endif /* _REACTOR_LOGGING_SERVER_ADAPTER_H */ diff --git a/ACE/examples/C++NPv2/Reactor_Logging_Server_T.cpp b/ACE/examples/C++NPv2/Reactor_Logging_Server_T.cpp deleted file mode 100644 index fb054d64d28..00000000000 --- a/ACE/examples/C++NPv2/Reactor_Logging_Server_T.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -// Implementations for Reactor_Logging_Server<> - -template <class ACCEPTOR> -Reactor_Logging_Server<ACCEPTOR>::Reactor_Logging_Server - (int argc, char *argv[], ACE_Reactor *reactor) - : ACCEPTOR (reactor) { - u_short logger_port = argc > 0 ? ACE_OS::atoi (argv[0]) : 0; - typename ACCEPTOR::PEER_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) - result = ACCEPTOR::open (server_addr); - if (result == -1) reactor->end_reactor_event_loop (); -} diff --git a/ACE/examples/C++NPv2/Reactor_Logging_Server_T.h b/ACE/examples/C++NPv2/Reactor_Logging_Server_T.h deleted file mode 100644 index ee16f8a061e..00000000000 --- a/ACE/examples/C++NPv2/Reactor_Logging_Server_T.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _REACTOR_LOGGING_SERVER_T_H -#define _REACTOR_LOGGING_SERVER_T_H - -#include "ace/ACE.h" -#include "ace/Reactor.h" - -template <class ACCEPTOR> -class Reactor_Logging_Server : public ACCEPTOR -{ -public: - Reactor_Logging_Server (int argc, char *argv[], - ACE_Reactor *reactor); -}; - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -#include "Reactor_Logging_Server_T.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -#pragma implementation ("Reactor_Logging_Server_T.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#endif /* _REACTOR_LOGGING_SERVER_T_H */ diff --git a/ACE/examples/C++NPv2/SLD.cpp b/ACE/examples/C++NPv2/SLD.cpp deleted file mode 100644 index 3aef89d0df6..00000000000 --- a/ACE/examples/C++NPv2/SLD.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Log_Msg.h" - -#include "Reactor_Logging_Server_Adapter.h" -#include "Logging_Acceptor.h" -#include "SLD_export.h" - -typedef Reactor_Logging_Server_Adapter<Logging_Acceptor> - Server_Logging_Daemon; - -ACE_FACTORY_DEFINE (SLD, Server_Logging_Daemon) - diff --git a/ACE/examples/C++NPv2/SLDEX_export.h b/ACE/examples/C++NPv2/SLDEX_export.h deleted file mode 100644 index b6cfca66b04..00000000000 --- a/ACE/examples/C++NPv2/SLDEX_export.h +++ /dev/null @@ -1,38 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl SLDEX -// ------------------------------ -#ifndef SLDEX_EXPORT_H -#define SLDEX_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (SLDEX_HAS_DLL) -# define SLDEX_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! SLDEX_HAS_DLL */ - -#if !defined (SLDEX_HAS_DLL) -# define SLDEX_HAS_DLL 1 -#endif /* ! SLDEX_HAS_DLL */ - -#if defined (SLDEX_HAS_DLL) && (SLDEX_HAS_DLL == 1) -# if defined (SLDEX_BUILD_DLL) -# define SLDEX_Export ACE_Proper_Export_Flag -# define SLDEX_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define SLDEX_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* SLDEX_BUILD_DLL */ -# define SLDEX_Export ACE_Proper_Import_Flag -# define SLDEX_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define SLDEX_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* SLDEX_BUILD_DLL */ -#else /* SLDEX_HAS_DLL == 1 */ -# define SLDEX_Export -# define SLDEX_SINGLETON_DECLARATION(T) -# define SLDEX_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* SLDEX_HAS_DLL == 1 */ - -#endif /* SLDEX_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/SLD_export.h b/ACE/examples/C++NPv2/SLD_export.h deleted file mode 100644 index 77f7467b43a..00000000000 --- a/ACE/examples/C++NPv2/SLD_export.h +++ /dev/null @@ -1,38 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl SLD -// ------------------------------ -#ifndef SLD_EXPORT_H -#define SLD_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (SLD_HAS_DLL) -# define SLD_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! SLD_HAS_DLL */ - -#if !defined (SLD_HAS_DLL) -# define SLD_HAS_DLL 1 -#endif /* ! SLD_HAS_DLL */ - -#if defined (SLD_HAS_DLL) && (SLD_HAS_DLL == 1) -# if defined (SLD_BUILD_DLL) -# define SLD_Export ACE_Proper_Export_Flag -# define SLD_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define SLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* SLD_BUILD_DLL */ -# define SLD_Export ACE_Proper_Import_Flag -# define SLD_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define SLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* SLD_BUILD_DLL */ -#else /* SLD_HAS_DLL == 1 */ -# define SLD_Export -# define SLD_SINGLETON_DECLARATION(T) -# define SLD_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* SLD_HAS_DLL == 1 */ - -#endif /* SLD_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/SLDex.cpp b/ACE/examples/C++NPv2/SLDex.cpp deleted file mode 100644 index fbaf7cb3111..00000000000 --- a/ACE/examples/C++NPv2/SLDex.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Log_Msg.h" - -#include "Reactor_Logging_Server_Adapter.h" -#include "Logging_Acceptor_Ex.h" -#include "SLDEX_export.h" - -typedef Reactor_Logging_Server_Adapter<Logging_Acceptor_Ex> - Server_Logging_Daemon_Ex; - -ACE_FACTORY_DEFINE (SLDEX, Server_Logging_Daemon_Ex) - diff --git a/ACE/examples/C++NPv2/SR_Configurable_Logging_Server.cpp b/ACE/examples/C++NPv2/SR_Configurable_Logging_Server.cpp deleted file mode 100644 index 97fc65d386e..00000000000 --- a/ACE/examples/C++NPv2/SR_Configurable_Logging_Server.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_main.h" -#include "ace/OS_Memory.h" -#include "ace/Reactor.h" -#include "ace/Select_Reactor.h" -#include "ace/Service_Config.h" - - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - ACE_Select_Reactor *select_reactor; - ACE_NEW_RETURN (select_reactor, ACE_Select_Reactor, 1); - ACE_Reactor *reactor; - ACE_NEW_RETURN (reactor, ACE_Reactor (select_reactor, 1), 1); - ACE_Reactor::close_singleton (); - ACE_Reactor::instance (reactor, 1); - - ACE_Service_Config::open (argc, argv); - - ACE_Reactor::instance ()->run_reactor_event_loop (); - return 0; -} diff --git a/ACE/examples/C++NPv2/Select_Reactor_Logging_Server.cpp b/ACE/examples/C++NPv2/Select_Reactor_Logging_Server.cpp deleted file mode 100644 index 322127670a4..00000000000 --- a/ACE/examples/C++NPv2/Select_Reactor_Logging_Server.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -// FUZZ: disable check_for_streams_include -#include "ace/streams.h" - -#include "ace/Reactor.h" -#include "ace/Select_Reactor.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ - defined (ACE_USES_OLD_IOSTREAMS)) -# include <stdio.h> -#else -# include <string> -#endif - -#include "Reactor_Logging_Server_T.h" -#include "Logging_Acceptor_Ex.h" - -typedef Reactor_Logging_Server<Logging_Acceptor_Ex> - Server_Logging_Daemon; - - -class Quit_Handler : public ACE_Event_Handler { -public: - Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {} - - virtual int handle_exception (ACE_HANDLE) { - reactor ()->end_reactor_event_loop (); - return -1; // Trigger call to handle_close() method. - } - - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) - { delete this; return 0; } - -protected: - - // Protected destructor ensures dynamic allocation. - virtual ~Quit_Handler () {} -}; - - -static ACE_THR_FUNC_RETURN event_loop (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - reactor->owner (ACE_OS::thr_self ()); - reactor->run_reactor_event_loop (); - return 0; -} - - -static ACE_THR_FUNC_RETURN controller (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - Quit_Handler *quit_handler = 0; - ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ - defined (ACE_USES_OLD_IOSTREAMS)) - for (;;) { - char user_input[80]; - ACE_OS::fgets (user_input, sizeof (user_input), stdin); - if (ACE_OS::strcmp (user_input, "quit") == 0) { - reactor->notify (quit_handler); - break; - } - } -#else - for (;;) { - std::string user_input; - std::getline (cin, user_input, '\n'); - if (user_input == "quit") { - reactor->notify (quit_handler); - break; - } - } -#endif - - return 0; -} - - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - ACE_Select_Reactor select_reactor; - ACE_Reactor reactor (&select_reactor); - - Server_Logging_Daemon *server; - // Ignore argv[0]... - --argc; ++argv; - ACE_NEW_RETURN (server, - Server_Logging_Daemon (argc, argv, &reactor), - 1); - ACE_Thread_Manager::instance ()->spawn (event_loop, &reactor); - ACE_Thread_Manager::instance ()->spawn (controller, &reactor); - return ACE_Thread_Manager::instance ()->wait (); -} - diff --git a/ACE/examples/C++NPv2/Server_Shutdown.cpp b/ACE/examples/C++NPv2/Server_Shutdown.cpp deleted file mode 100644 index 26ae437a31e..00000000000 --- a/ACE/examples/C++NPv2/Server_Shutdown.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/Event_Handler.h" -#include "ace/Reactor.h" -#include "ace/Service_Object.h" -#include "ace/Thread_Manager.h" -#include "ace/OS_NS_string.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) || \ - defined (ACE_USES_OLD_IOSTREAMS)) -# include <stdio.h> -#else -# include <string> -#endif - -#include "SLDEX_export.h" - - -class Quit_Handler : public ACE_Event_Handler { -public: - Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {} - - virtual int handle_exception (ACE_HANDLE) { - reactor ()->end_reactor_event_loop (); - return -1; // Trigger call to handle_close() method. - } - - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) - { delete this; return 0; } - -protected: - - // Protected destructor ensures dynamic allocation. - virtual ~Quit_Handler () {} -}; - - -static ACE_THR_FUNC_RETURN controller (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - Quit_Handler *quit_handler = 0; - ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ - defined (ACE_USES_OLD_IOSTREAMS)) - for (;;) { - char user_input[80]; - ACE_OS::fgets (user_input, sizeof (user_input), stdin); - if (ACE_OS::strcmp (user_input, "quit") == 0) { - reactor->notify (quit_handler); - break; - } - } -#else - for (;;) { - std::string user_input; - std::getline (cin, user_input, '\n'); - if (user_input == "quit") { - reactor->notify (quit_handler); - break; - } - } -#endif - - return 0; -} - - -class Server_Shutdown : public ACE_Service_Object { -public: - virtual int init (int, ACE_TCHAR *[]) { - reactor_ = ACE_Reactor::instance (); - return ACE_Thread_Manager::instance ()->spawn - (controller, reactor_, THR_DETACHED); - } - - virtual int fini () { - Quit_Handler *quit_handler = 0; - ACE_NEW_RETURN (quit_handler, - Quit_Handler (reactor_), -1); - return reactor_->notify (quit_handler); - } - -private: - ACE_Reactor *reactor_; -}; - -ACE_FACTORY_DEFINE (SLDEX, Server_Shutdown) diff --git a/ACE/examples/C++NPv2/Service_Reporter.cpp b/ACE/examples/C++NPv2/Service_Reporter.cpp deleted file mode 100644 index ad9cd05d26c..00000000000 --- a/ACE/examples/C++NPv2/Service_Reporter.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_NS_stdio.h" -#include "ace/OS_NS_string.h" -#include "ace/Get_Opt.h" -#include "ace/INET_Addr.h" -#include "ace/Log_Msg.h" -#include "ace/Service_Config.h" -#include "ace/Service_Repository.h" -#include "ace/Service_Types.h" -#include "ace/SOCK_Stream.h" -#include "Service_Reporter.h" - - -int Service_Reporter::init (int argc, ACE_TCHAR *argv[]) { - ACE_INET_Addr local_addr (Service_Reporter::DEFAULT_PORT); - - // Start at argv[0]. - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"), 0); - get_opt.long_option (ACE_TEXT ("port"), - 'p', - ACE_Get_Opt::ARG_REQUIRED); - - for (int c; (c = get_opt ()) != -1; ) - switch (c) { - case 'p': - local_addr.set_port_number - (ACE_OS::atoi (get_opt.opt_arg ())); - } - - acceptor_.open (local_addr); - return reactor ()->register_handler - (this, - ACE_Event_Handler::ACCEPT_MASK); -} - - -int Service_Reporter::handle_input (ACE_HANDLE) { - ACE_SOCK_Stream peer_stream; - acceptor_.accept (peer_stream); - - ACE_Service_Repository_Iterator iterator - (*ACE_Service_Repository::instance (), 0); - - for (const ACE_Service_Type *st; - iterator.next (st) != 0; - iterator.advance ()) { - iovec iov[3]; - iov[0].iov_base = const_cast<ACE_TCHAR *> (st->name ()); - iov[0].iov_len = - ACE_OS::strlen (st->name ()) * sizeof (ACE_TCHAR); - const ACE_TCHAR *state = st->active () ? - ACE_TEXT (" (active) ") : ACE_TEXT (" (paused) "); - iov[1].iov_base = const_cast<ACE_TCHAR *> (state); - iov[1].iov_len = - ACE_OS::strlen (state) * sizeof (ACE_TCHAR); - ACE_TCHAR *report = 0; // Ask info() to allocate buffer - int len = st->type ()->info (&report, 0); - iov[2].iov_base = static_cast<ACE_TCHAR *> (report); - iov[2].iov_len = static_cast<size_t> (len); - iov[2].iov_len *= sizeof (ACE_TCHAR); - peer_stream.sendv_n (iov, 3); - ACE::strdelete (report); - } - - peer_stream.close (); - return 0; -} - - -int Service_Reporter::info (ACE_TCHAR **bufferp, - size_t length) const { - ACE_INET_Addr local_addr; - acceptor_.get_local_addr (local_addr); - - ACE_TCHAR buf[BUFSIZ]; - ACE_OS::sprintf - (buf, ACE_TEXT ("%hu"), local_addr.get_port_number ()); - ACE_OS::strcat - (buf, ACE_TEXT ("/tcp # lists services in daemon\n")); - if (*bufferp == 0) - *bufferp = ACE::strnew (buf); - else - ACE_OS::strncpy (*bufferp, buf, length); - return ACE_OS::strlen (*bufferp); -} - - -int Service_Reporter::suspend () -{ return reactor ()->suspend_handler (this); } - -int Service_Reporter::resume () -{ return reactor ()->resume_handler (this); } - - -int Service_Reporter::fini () { - reactor ()->remove_handler - (this, - ACE_Event_Handler::ACCEPT_MASK - | ACE_Event_Handler::DONT_CALL); - return acceptor_.close (); -} - -// Define the service object make and gobble functions. -ACE_FACTORY_DEFINE (ACE_Local_Service, Service_Reporter) - -// Define the ACE_Static_Svc_Descriptor that conveys the service information -// to the ACE_Service_Config. -ACE_STATIC_SVC_DEFINE ( - Reporter_Descriptor, - ACE_TEXT ("Service_Reporter"), - ACE_SVC_OBJ_T, - &ACE_SVC_NAME (Service_Reporter), - ACE_Service_Type::DELETE_THIS - | ACE_Service_Type::DELETE_OBJ, - 0 // This object is not initially active. -) - -// Define the class that will register this service with ACE_Service_Config -// at program startup. -ACE_STATIC_SVC_REQUIRE (Reporter_Descriptor) diff --git a/ACE/examples/C++NPv2/Service_Reporter.h b/ACE/examples/C++NPv2/Service_Reporter.h deleted file mode 100644 index c6de7484767..00000000000 --- a/ACE/examples/C++NPv2/Service_Reporter.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _SERVICE_REPORTER_H -#define _SERVICE_REPORTER_H - -#include "ace/Reactor.h" -#include "ace/Service_Object.h" -#include "ace/SOCK_Acceptor.h" - - -class Service_Reporter : public ACE_Service_Object { -public: - Service_Reporter (ACE_Reactor *r = ACE_Reactor::instance ()) - : ACE_Service_Object (r) {} - -protected: - // Hook methods inherited from <ACE_Service_Object>. - virtual int init (int argc, ACE_TCHAR *argv[]); - virtual int fini (); - virtual int info (ACE_TCHAR **, size_t) const; - virtual int suspend (); - virtual int resume (); - - // Reactor hook methods. - virtual int handle_input (ACE_HANDLE); - virtual ACE_HANDLE get_handle () const - { return acceptor_.get_handle (); } - -private: - ACE_SOCK_Acceptor acceptor_; // Acceptor instance. - enum { DEFAULT_PORT = 9411 }; -}; - -#endif /* _SERVICE_REPORTER_H */ diff --git a/ACE/examples/C++NPv2/TPCLS_export.h b/ACE/examples/C++NPv2/TPCLS_export.h deleted file mode 100644 index b550ef28a95..00000000000 --- a/ACE/examples/C++NPv2/TPCLS_export.h +++ /dev/null @@ -1,54 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl TPCLS -// ------------------------------ -#ifndef TPCLS_EXPORT_H -#define TPCLS_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (TPCLS_HAS_DLL) -# define TPCLS_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! TPCLS_HAS_DLL */ - -#if !defined (TPCLS_HAS_DLL) -# define TPCLS_HAS_DLL 1 -#endif /* ! TPCLS_HAS_DLL */ - -#if defined (TPCLS_HAS_DLL) && (TPCLS_HAS_DLL == 1) -# if defined (TPCLS_BUILD_DLL) -# define TPCLS_Export ACE_Proper_Export_Flag -# define TPCLS_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define TPCLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* TPCLS_BUILD_DLL */ -# define TPCLS_Export ACE_Proper_Import_Flag -# define TPCLS_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define TPCLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* TPCLS_BUILD_DLL */ -#else /* TPCLS_HAS_DLL == 1 */ -# define TPCLS_Export -# define TPCLS_SINGLETON_DECLARATION(T) -# define TPCLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* TPCLS_HAS_DLL == 1 */ - -// Set TPCLS_NTRACE = 0 to turn on library specific tracing even if -// tracing is turned off for ACE. -#if !defined (TPCLS_NTRACE) -# if (ACE_NTRACE == 1) -# define TPCLS_NTRACE 1 -# else /* (ACE_NTRACE == 1) */ -# define TPCLS_NTRACE 0 -# endif /* (ACE_NTRACE == 1) */ -#endif /* !TPCLS_NTRACE */ - -#if (TPCLS_NTRACE == 1) -# define TPCLS_TRACE(X) -#else /* (TPCLS_NTRACE == 1) */ -# define TPCLS_TRACE(X) ACE_TRACE_IMPL(X) -#endif /* (TPCLS_NTRACE == 1) */ - -#endif /* TPCLS_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/TPC_Logging_Server.cpp b/ACE/examples/C++NPv2/TPC_Logging_Server.cpp deleted file mode 100644 index b6ce76e1d40..00000000000 --- a/ACE/examples/C++NPv2/TPC_Logging_Server.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* -** $Id$ -** -** This is the Thread-per-connection logging server example from Chapter 7. -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_NS_string.h" -#include "ace/FILE_Addr.h" -#include "ace/FILE_Connector.h" -#include "ace/os_include/os_netdb.h" -#include "Reactor_Logging_Server_Adapter.h" -#include "TPC_Logging_Server.h" -#include "TPCLS_export.h" - -int TPC_Logging_Handler::open (void *) { - static const ACE_TCHAR LOGFILE_SUFFIX[] = ACE_TEXT (".log"); - ACE_TCHAR filename[MAXHOSTNAMELEN + sizeof (LOGFILE_SUFFIX)]; - ACE_INET_Addr logging_peer_addr; - - peer ().get_remote_addr (logging_peer_addr); - logging_peer_addr.get_host_name (filename, MAXHOSTNAMELEN); - ACE_OS::strcat (filename, LOGFILE_SUFFIX); - - ACE_FILE_Connector connector; - connector.connect (log_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); - - logging_handler_.peer ().set_handle (peer ().get_handle ()); - - return activate (THR_NEW_LWP | THR_DETACHED); -} - - -#if !defined (TPC_CERTIFICATE_FILENAME) -# define TPC_CERTIFICATE_FILENAME "tpc-cert.pem" -#endif /* !TPC_CERTIFICATE_FILENAME */ -#if !defined (TPC_KEY_FILENAME) -# define TPC_KEY_FILENAME "tpc-key.pem" -#endif /* !TPC_KEY_FILENAME */ - -int TPC_Logging_Acceptor::open - (const ACE_SOCK_Acceptor::PEER_ADDR &local_addr, - ACE_Reactor *reactor, - int flags, int use_select, int reuse_addr) { - if (PARENT::open (local_addr, reactor, flags, - use_select, reuse_addr) != 0) - return -1; - OpenSSL_add_ssl_algorithms (); - ssl_ctx_ = SSL_CTX_new (SSLv3_server_method ()); - if (ssl_ctx_ == 0) return -1; - - if (SSL_CTX_use_certificate_file (ssl_ctx_, - TPC_CERTIFICATE_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || SSL_CTX_use_PrivateKey_file (ssl_ctx_, - TPC_KEY_FILENAME, - SSL_FILETYPE_PEM) <= 0 - || !SSL_CTX_check_private_key (ssl_ctx_)) - return -1; - ssl_ = SSL_new (ssl_ctx_); - return ssl_ == 0 ? -1 : 0; -} - - -int TPC_Logging_Acceptor::handle_close (ACE_HANDLE h, - ACE_Reactor_Mask mask) { - PARENT::handle_close (h, mask); - delete this; - return 0; -} - - -int TPC_Logging_Acceptor::accept_svc_handler - (TPC_Logging_Handler *sh) { - if (PARENT::accept_svc_handler (sh) == -1) return -1; - SSL_clear (ssl_); // Reset for new SSL connection. -#if defined (ACE_WIN32) - // ACE_WIN32 is the only platform where ACE_HANDLE is not an int. - // See ace/config-lite.h for the typedefs. - SSL_set_fd (ssl_, reinterpret_cast<int> (sh->get_handle ())); -#else - SSL_set_fd (ssl_, sh->get_handle ()); -#endif /* ACE_WIN32 */ - - SSL_set_verify - (ssl_, - SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, - 0); - if (SSL_accept (ssl_) == -1 - || SSL_shutdown (ssl_) == -1) return -1; - return 0; -} - - -typedef Reactor_Logging_Server_Adapter<TPC_Logging_Acceptor> - TPC_Logging_Server; - -ACE_FACTORY_DEFINE (TPCLS, TPC_Logging_Server) - diff --git a/ACE/examples/C++NPv2/TPC_Logging_Server.h b/ACE/examples/C++NPv2/TPC_Logging_Server.h deleted file mode 100644 index 2617c3b95ec..00000000000 --- a/ACE/examples/C++NPv2/TPC_Logging_Server.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -** $Id$ -** -** This is the Thread-per-connection logging server example from Chapter 7. -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _TPC_LOGGING_SERVER_H -#define _TPC_LOGGING_SERVER_H - -#include "ace/Acceptor.h" -#include "ace/INET_Addr.h" -#include "ace/Reactor.h" -#include "ace/Svc_Handler.h" -#include "ace/FILE_IO.h" -#include "Logging_Handler.h" - -#include "ace/SOCK_Acceptor.h" -#include <openssl/ssl.h> - -class TPC_Logging_Handler - : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> { -protected: - ACE_FILE_IO log_file_; // File of log records. - - // Connection to peer service handler. - Logging_Handler logging_handler_; - -public: - TPC_Logging_Handler () : logging_handler_ (log_file_) {} - - virtual int open (void *); - - virtual int svc (void) { - for (;;) - switch (logging_handler_.log_record ()) { - case -1: return -1; // Error. - case 0: return 0; // Client closed connection. - default: continue; // Default case. - } - /* NOTREACHED */ - return 0; - } -}; - - -class TPC_Logging_Acceptor - : public ACE_Acceptor<TPC_Logging_Handler, ACE_SOCK_ACCEPTOR> { -protected: - // The SSL ``context'' data structure. - SSL_CTX *ssl_ctx_; - - // The SSL data structure corresponding to authenticated - // SSL connections. - SSL *ssl_; - -public: - typedef ACE_Acceptor<TPC_Logging_Handler, ACE_SOCK_ACCEPTOR> - PARENT; - typedef ACE_SOCK_Acceptor::PEER_ADDR PEER_ADDR; - - // Constructor. - TPC_Logging_Acceptor (ACE_Reactor *r) - : PARENT (r), ssl_ctx_ (0), ssl_ (0) {} - - // Destructor frees the SSL resources. - virtual ~TPC_Logging_Acceptor (void) { - SSL_free (this->ssl_); - SSL_CTX_free (this->ssl_ctx_); - } - - // Initialize the acceptor instance. - virtual int open - (const ACE_SOCK_Acceptor::PEER_ADDR &local_addr, - ACE_Reactor *reactor = ACE_Reactor::instance (), - int flags = 0, int use_select = 1, int reuse_addr = 1); - - virtual int handle_close - (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); - - // Connection establishment and authentication hook method. - virtual int accept_svc_handler (TPC_Logging_Handler *sh); -}; - -#endif /* _TPC_LOGGING_SERVER_H */ diff --git a/ACE/examples/C++NPv2/TPLS_export.h b/ACE/examples/C++NPv2/TPLS_export.h deleted file mode 100644 index 71448e71a50..00000000000 --- a/ACE/examples/C++NPv2/TPLS_export.h +++ /dev/null @@ -1,38 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl TPLS -// ------------------------------ -#ifndef TPLS_EXPORT_H -#define TPLS_EXPORT_H - -#include "ace/config-all.h" - -#if defined (ACE_AS_STATIC_LIBS) && !defined (TPLS_HAS_DLL) -# define TPLS_HAS_DLL 0 -#endif /* ACE_AS_STATIC_LIBS && ! TPLS_HAS_DLL */ - -#if !defined (TPLS_HAS_DLL) -# define TPLS_HAS_DLL 1 -#endif /* ! TPLS_HAS_DLL */ - -#if defined (TPLS_HAS_DLL) && (TPLS_HAS_DLL == 1) -# if defined (TPLS_BUILD_DLL) -# define TPLS_Export ACE_Proper_Export_Flag -# define TPLS_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define TPLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* TPLS_BUILD_DLL */ -# define TPLS_Export ACE_Proper_Import_Flag -# define TPLS_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define TPLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* TPLS_BUILD_DLL */ -#else /* TPLS_HAS_DLL == 1 */ -# define TPLS_Export -# define TPLS_SINGLETON_DECLARATION(T) -# define TPLS_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* TPLS_HAS_DLL == 1 */ - -#endif /* TPLS_EXPORT_H */ - -// End of auto generated file. diff --git a/ACE/examples/C++NPv2/TP_Logging_Server.cpp b/ACE/examples/C++NPv2/TP_Logging_Server.cpp deleted file mode 100644 index 7342cf4c757..00000000000 --- a/ACE/examples/C++NPv2/TP_Logging_Server.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/OS_Memory.h" -#include "ace/Guard_T.h" -#include "ace/Message_Block.h" -#include "TP_Logging_Server.h" - -int TP_Logging_Handler::handle_input (ACE_HANDLE) { - ACE_Message_Block *mblk = 0; - if (logging_handler_.recv_log_record (mblk) != -1) { - ACE_Message_Block *log_blk = 0; - ACE_NEW_RETURN - (log_blk, ACE_Message_Block - (reinterpret_cast<char *> (this)), -1); - log_blk->cont (mblk); - ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1); - if (TP_LOGGING_TASK::instance ()->put (log_blk) == -1) - { log_blk->release (); return -1; } - ++queued_count_; - return 0; - } else return -1; -} - - -int -TP_Logging_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask) { - int close_now = 0; - if (handle != ACE_INVALID_HANDLE) { - ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1); - if (queued_count_ == 0) - close_now = 1; - else - deferred_close_ = 1; - } else { - ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, -1); - queued_count_--; - if (queued_count_ == 0) close_now = deferred_close_; - } - - if (close_now) - return Logging_Event_Handler::handle_close (); - return 0; -} - - -int TP_Logging_Task::svc () { - for (ACE_Message_Block *log_blk; getq (log_blk) != -1; ) { - TP_Logging_Handler *tp_handler = reinterpret_cast<TP_Logging_Handler *> (log_blk->rd_ptr ()); - Logging_Handler logging_handler (tp_handler->log_file ()); - logging_handler.write_log_record (log_blk->cont ()); - - log_blk->release (); - tp_handler->handle_close (ACE_INVALID_HANDLE, 0); - } - return 0; -} - -ACE_FACTORY_DEFINE (TPLS, TP_Logging_Server) - -#if defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) -template ACE_Singleton<TP_Logging_Task, ACE_Null_Mutex> * - ACE_Singleton<TP_Logging_Task, ACE_Null_Mutex>::singleton_; -template ACE_Unmanaged_Singleton<TP_Logging_Task, ACE_Null_Mutex> * - ACE_Unmanaged_Singleton<TP_Logging_Task, ACE_Null_Mutex>::singleton_; -#endif /* ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION */ diff --git a/ACE/examples/C++NPv2/TP_Logging_Server.h b/ACE/examples/C++NPv2/TP_Logging_Server.h deleted file mode 100644 index 9c4869cdcee..00000000000 --- a/ACE/examples/C++NPv2/TP_Logging_Server.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#ifndef _TP_LOGGING_SERVER_H -#define _TP_LOGGING_SERVER_H - -#include "ace/Auto_Ptr.h" -#include "ace/Singleton.h" -#include "ace/Synch.h" -#include "ace/Task.h" -#include "Logging_Acceptor.h" -#include "Logging_Event_Handler.h" -#include "Reactor_Logging_Server_T.h" -#include "TPLS_export.h" - -class TP_Logging_Task : public ACE_Task<ACE_SYNCH> { - // Instantiated with an MT synchronization trait. -public: - enum { MAX_THREADS = 4 }; - - virtual int open (void * = 0) - { return activate (THR_NEW_LWP, MAX_THREADS); } - - virtual int put (ACE_Message_Block *mblk, - ACE_Time_Value *timeout = 0) - { return putq (mblk, timeout); } - - virtual int svc (void); -}; - -typedef ACE_Unmanaged_Singleton<TP_Logging_Task, ACE_Null_Mutex> - TP_LOGGING_TASK; - -/*******************************************************/ - -class TP_Logging_Acceptor; - -class TP_Logging_Handler : public Logging_Event_Handler { - friend class TP_Logging_Acceptor; -protected: - virtual ~TP_Logging_Handler () {} // No-op destructor. - - // Number of pointers to this class instance that currently - // reside in the <TP_LOGGING_TASK> singleton's message queue. - int queued_count_; - - // Indicates whether <Logging_Event_Handler::handle_close()> - // must be called to cleanup and delete this object. - int deferred_close_; - - // Serialize access to <queued_count_> and <deferred_close_>. - ACE_SYNCH_MUTEX lock_; - -public: - TP_Logging_Handler (ACE_Reactor *reactor) - : Logging_Event_Handler (reactor), - queued_count_ (0), - deferred_close_ (0) {} - - // Called when input events occur, e.g., connection or data. - virtual int handle_input (ACE_HANDLE); - - // Called when this object is destroyed, e.g., when it's - // removed from a reactor. - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); -}; - -/*******************************************************/ - -class TP_Logging_Acceptor : public Logging_Acceptor { -public: - TP_Logging_Acceptor (ACE_Reactor *r = ACE_Reactor::instance ()) - : Logging_Acceptor (r) {} - - virtual int handle_input (ACE_HANDLE) { - TP_Logging_Handler *peer_handler = 0; - ACE_NEW_RETURN (peer_handler, - TP_Logging_Handler (reactor ()), -1); - if (acceptor_.accept (peer_handler->peer ()) == -1) { - delete peer_handler; - return -1; - } else if (peer_handler->open () == -1) - peer_handler->handle_close (ACE_INVALID_HANDLE, 0); - return 0; - } -}; - -/*******************************************************/ - -class TP_Logging_Server : public ACE_Service_Object { -protected: - // Contains the reactor, acceptor, and handlers. - typedef Reactor_Logging_Server<TP_Logging_Acceptor> - LOGGING_DISPATCHER; - LOGGING_DISPATCHER *logging_dispatcher_; - -public: - TP_Logging_Server (): logging_dispatcher_ (0) {} - - virtual int init (int argc, ACE_TCHAR *argv[]) { - int i; - char **array = 0; - ACE_NEW_RETURN (array, char*[argc], -1); - ACE_Auto_Array_Ptr<char *> char_argv (array); - - for (i = 0; i < argc; ++i) - char_argv[i] = ACE::strnew (ACE_TEXT_ALWAYS_CHAR (argv[i])); - ACE_NEW_NORETURN - (logging_dispatcher_, - TP_Logging_Server::LOGGING_DISPATCHER - (i, char_argv.get (), ACE_Reactor::instance ())); - for (i = 0; i < argc; ++i) ACE::strdelete (char_argv[i]); - if (logging_dispatcher_ == 0) return -1; - else return TP_LOGGING_TASK::instance ()->open (); - } - - virtual int fini () { - TP_LOGGING_TASK::instance ()->flush (); - TP_LOGGING_TASK::instance ()->wait (); - TP_LOGGING_TASK::close (); - delete logging_dispatcher_; - return 0; - } -}; - -ACE_FACTORY_DECLARE (TPLS, TP_Logging_Handler) - -#endif /* _TP_LOGGING_SERVER_H */ diff --git a/ACE/examples/C++NPv2/TP_Reactor_Logging_Server.cpp b/ACE/examples/C++NPv2/TP_Reactor_Logging_Server.cpp deleted file mode 100644 index 04d2c82fde1..00000000000 --- a/ACE/examples/C++NPv2/TP_Reactor_Logging_Server.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -// FUZZ: disable check_for_streams_include -#include "ace/streams.h" - -#include "ace/Auto_Ptr.h" -#include "ace/Reactor.h" -#include "ace/TP_Reactor.h" -#include "ace/Thread_Manager.h" - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ - defined (ACE_USES_OLD_IOSTREAMS)) -# include <stdio.h> -#else -# include <string> -#endif - -#include "Reactor_Logging_Server_T.h" -#include "Logging_Acceptor_Ex.h" - -typedef Reactor_Logging_Server<Logging_Acceptor_Ex> - Server_Logging_Daemon; - - -class Quit_Handler : public ACE_Event_Handler { -public: - Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {} - - virtual int handle_exception (ACE_HANDLE) { - reactor ()->end_reactor_event_loop (); - return -1; // Trigger call to handle_close() method. - } - - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) - { delete this; return 0; } - -protected: - - // Protected destructor ensures dynamic allocation. - virtual ~Quit_Handler () {} -}; - - -static ACE_THR_FUNC_RETURN event_loop (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - reactor->owner (ACE_OS::thr_self ()); - reactor->run_reactor_event_loop (); - return 0; -} - - -static ACE_THR_FUNC_RETURN controller (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - Quit_Handler *quit_handler = 0; - ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0); - -#if defined (ACE_WIN32) && (!defined (ACE_HAS_STANDARD_CPP_LIBRARY) || \ - (ACE_HAS_STANDARD_CPP_LIBRARY == 0) || \ - defined (ACE_USES_OLD_IOSTREAMS)) - for (;;) { - char user_input[80]; - ACE_OS::fgets (user_input, sizeof (user_input), stdin); - if (ACE_OS::strcmp (user_input, "quit") == 0) { - reactor->notify (quit_handler); - break; - } - } -#else - 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 (user_input == "quit") { - reactor->notify (quit_handler); - break; - } - } -#endif - - return 0; -} - - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - const size_t N_THREADS = 4; - ACE_TP_Reactor tp_reactor; - ACE_Reactor reactor (&tp_reactor); - auto_ptr<ACE_Reactor> delete_instance - (ACE_Reactor::instance (&reactor)); - - Server_Logging_Daemon *server; - // Ignore argv[0]... - --argc; ++argv; - ACE_NEW_RETURN (server, - Server_Logging_Daemon (argc, argv, - ACE_Reactor::instance ()), - 1); - ACE_Thread_Manager::instance ()->spawn_n - (N_THREADS, event_loop, ACE_Reactor::instance ()); - ACE_Thread_Manager::instance ()->spawn - (controller, ACE_Reactor::instance ()); - return ACE_Thread_Manager::instance ()->wait (); -} - diff --git a/ACE/examples/C++NPv2/WFMO_Reactor_Logging_Server.cpp b/ACE/examples/C++NPv2/WFMO_Reactor_Logging_Server.cpp deleted file mode 100644 index 46fff8bf083..00000000000 --- a/ACE/examples/C++NPv2/WFMO_Reactor_Logging_Server.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/config-all.h" - -#if defined (ACE_WIN32) - -#include "ace/Reactor.h" -#include "ace/WFMO_Reactor.h" -#include "ace/Thread_Manager.h" -#include "ace/OS_NS_string.h" - -#include "Reactor_Logging_Server_T.h" -#include "Logging_Acceptor_Ex.h" -#include "Logging_Event_Handler_Ex.h" - -class Quit_Handler : public ACE_Event_Handler { -private: - ACE_Manual_Event quit_seen_; - -public: - Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) { - SetConsoleMode (ACE_STDIN, ENABLE_LINE_INPUT - | ENABLE_ECHO_INPUT - | ENABLE_PROCESSED_INPUT); - if (reactor ()->register_handler - (this, quit_seen_.handle ()) == -1 - || ACE_Event_Handler::register_stdin_handler - (this, r, ACE_Thread_Manager::instance ()) == -1) - r->end_reactor_event_loop (); - } - - ~Quit_Handler () { - ACE_Event_Handler::remove_stdin_handler - (reactor (), ACE_Thread_Manager::instance ()); - reactor ()->remove_handler (quit_seen_.handle (), - ACE_Event_Handler::DONT_CALL); - } - - virtual int handle_input (ACE_HANDLE h) { - CHAR user_input[BUFSIZ]; - DWORD count; - if (!ReadFile (h, user_input, BUFSIZ, &count, 0)) - return -1; - - user_input[count] = '\0'; - if (ACE_OS::strncmp (user_input, "quit", 4) == 0) - return -1; - return 0; - } - - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask) { - quit_seen_.signal (); - return 0; - } - - virtual int handle_signal (int, siginfo_t *, ucontext_t *) { - reactor ()->end_reactor_event_loop (); - return 0; - } -}; - - -class Logging_Event_Handler_WFMO : public Logging_Event_Handler_Ex -{ -public: - Logging_Event_Handler_WFMO (ACE_Reactor *r) - : Logging_Event_Handler_Ex (r) {} - -protected: - int handle_input (ACE_HANDLE) { - ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, monitor, lock_, -1); - return logging_handler_.log_record (); - } - - ACE_Thread_Mutex lock_; // Serialize threads in thread pool. -}; - - -class Logging_Acceptor_WFMO : public Logging_Acceptor_Ex -{ -public: - // Simple constructor to pass ACE_Reactor to base class. - Logging_Acceptor_WFMO (ACE_Reactor *r = ACE_Reactor::instance ()) - : Logging_Acceptor_Ex (r) {}; - -protected: - virtual int handle_input (ACE_HANDLE) { - Logging_Event_Handler_WFMO *peer_handler = 0; - ACE_NEW_RETURN (peer_handler, - Logging_Event_Handler_WFMO (reactor ()), - -1); - - if (acceptor_.accept (peer_handler->peer ()) == -1) { - delete peer_handler; - return -1; - } else if (peer_handler->open () == -1) { - peer_handler->handle_close (); - return -1; - } - return 0; - } -}; - - -static ACE_THR_FUNC_RETURN event_loop (void *arg) { - ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg); - - reactor->owner (ACE_OS::thr_self ()); - reactor->run_reactor_event_loop (); - return 0; -} - - -typedef Reactor_Logging_Server<Logging_Acceptor_WFMO> - Server_Logging_Daemon; - - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - const size_t N_THREADS = 4; - ACE_WFMO_Reactor wfmo_reactor; - ACE_Reactor reactor (&wfmo_reactor); - - Server_Logging_Daemon *server; - // Ignore argv[0]... - --argc; ++argv; - ACE_NEW_RETURN (server, - Server_Logging_Daemon (argc, argv, &reactor), - 1); - Quit_Handler quit_handler (&reactor); - ACE_Thread_Manager::instance ()->spawn_n - (N_THREADS, event_loop, &reactor); - return ACE_Thread_Manager::instance ()->wait (); -} - -#else /* !ACE_WIN32 */ -int ACE_TMAIN (int, ACE_TCHAR *[]) -{ - return 0; -} -#endif /* ACE_WIN32 */ diff --git a/ACE/examples/C++NPv2/display_logfile.cpp b/ACE/examples/C++NPv2/display_logfile.cpp deleted file mode 100644 index d92d07b60f9..00000000000 --- a/ACE/examples/C++NPv2/display_logfile.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* -** $Id$ -** -** Copyright 2002 Addison Wesley. All Rights Reserved. -*/ - -#include "ace/ACE.h" -#include "ace/CDR_Stream.h" -#include "ace/FILE_Addr.h" -#include "ace/FILE_Connector.h" -#include "ace/FILE_IO.h" -#include "ace/Message_Block.h" -#include "ace/Module.h" -#include "ace/SString.h" -#include "ace/Stream.h" -#include "ace/Task.h" -#include "ace/Thread_Manager.h" -#include "ace/Lock_Adapter_T.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_time.h" - -template <class TASK> -class Logrec_Module : public ACE_Module<ACE_SYNCH> -{ -public: - Logrec_Module (const ACE_TCHAR *name) - { - this->open (name, - &task_, // Initialize writer-side task. - 0, // Ignore reader-side task. - 0, - ACE_Module<ACE_SYNCH>::M_DELETE_READER); - } -private: - TASK task_; -}; -#define LOGREC_MODULE(NAME) \ - typedef Logrec_Module<NAME> NAME##_Module - -class Logrec_Reader : public ACE_Task<ACE_SYNCH> -{ -private: - ACE_TString filename_; // Name of logfile. - ACE_FILE_IO logfile_; // File containing log records. - -public: - enum {MB_CLIENT = ACE_Message_Block::MB_USER, - MB_TYPE, MB_PID, MB_TIME, MB_TEXT}; - - Logrec_Reader (const ACE_TString &file): filename_ (file) {} - - //FUZZ: disable check_for_lack_ACE_OS - virtual int open (void *) { - //FUZZ: enable check_for_lack_ACE_OS - - ACE_FILE_Addr name (filename_.c_str ()); - ACE_FILE_Connector connector; - if (connector.connect (logfile_, name) == -1) - return -1; - return activate (); - } - - virtual int svc () { - const size_t FileReadSize = 8 * 1024; - ACE_Message_Block mblk (FileReadSize); - - for (;; mblk.crunch ()) { - // Read as much as will fit in the message block. - ssize_t bytes_read = logfile_.recv (mblk.wr_ptr (), - mblk.space ()); - if (bytes_read <= 0) - break; - mblk.wr_ptr (static_cast<size_t> (bytes_read)); - - // We have a bunch of data from the log file. The data is - // arranged like so: - // hostname\0 - // CDR-encoded log record - // So, first we scan for the end of the host name, then - // initialize another ACE_Message_Block aligned for CDR - // demarshaling and copy the remainder of the block into it. We - // can't use duplicate() because we need to be sure the data - // pointer is aligned properly for CDR demarshaling. If at any - // point, there's not enough data left in the message block to - // extract what's needed, crunch the block to move all remaining - // data to the beginning and read more from the file. - for (;;) { - size_t name_len = ACE_OS::strnlen - (mblk.rd_ptr (), mblk.length ()); - if (name_len == mblk.length ()) break; - - char *name_p = mblk.rd_ptr (); - ACE_Message_Block *rec, *head, *temp; - ACE_NEW_RETURN - (head, ACE_Message_Block (name_len, MB_CLIENT), 0); - head->copy (name_p, name_len); - mblk.rd_ptr (name_len + 1); // Skip nul also - - size_t need = mblk.length () + ACE_CDR::MAX_ALIGNMENT; - ACE_NEW_RETURN (rec, ACE_Message_Block (need), 0); - ACE_CDR::mb_align (rec); - rec->copy (mblk.rd_ptr (), mblk.length ()); - - // Now rec contains the remaining data we've read so far from - // the file. Create an ACE_InputCDR to start demarshaling the - // log record, header first to find the length, then the data. - // Since the ACE_InputCDR constructor increases the reference count - // on rec, we release it upon return to prevent leaks. - // The cdr 'read' methods return 0 on failure, 1 on success. - ACE_InputCDR cdr (rec); rec->release (); - ACE_CDR::Boolean byte_order; - if (!cdr.read_boolean (byte_order)) { - head->release (); rec->release (); break; - } - cdr.reset_byte_order (byte_order); - - // Now read the length of the record. From there, we'll know - // if rec contains the complete record or not. - ACE_CDR::ULong length; - if (!cdr.read_ulong (length)) { - head->release (); mblk.rd_ptr (name_p); break; - } - if (length > cdr.length ()) { - head->release (); mblk.rd_ptr (name_p); break; - } - - // The complete record is in rec... grab all the fields into - // separate, chained message blocks. - ACE_NEW_RETURN (temp, - ACE_Message_Block (length, MB_TEXT), - 0); - ACE_NEW_RETURN - (temp, - ACE_Message_Block (2 * sizeof (ACE_CDR::Long), - MB_TIME, temp), - 0); - ACE_NEW_RETURN - (temp, - ACE_Message_Block (sizeof (ACE_CDR::Long), - MB_PID, temp), - 0); - ACE_NEW_RETURN - (temp, - ACE_Message_Block (sizeof (ACE_CDR::Long), - MB_TYPE, temp), - 0); - head->cont (temp); - - // Extract the type - ACE_CDR::Long *lp; - lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); - cdr >> *lp; - temp->wr_ptr (sizeof (ACE_CDR::Long)); - temp = temp->cont (); - - // Extract the pid - lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); - cdr >> *lp; - temp->wr_ptr (sizeof (ACE_CDR::Long)); - temp = temp->cont (); - - // Extract the timestamp (2 Longs) - lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); - cdr >> *lp; ++lp; cdr >> *lp; - temp->wr_ptr (2 * sizeof (ACE_CDR::Long)); - temp = temp->cont (); - - // Demarshal the length of the message text, then demarshal - // the text into the block. - ACE_CDR::ULong text_len; - cdr >> text_len; - cdr.read_char_array (temp->wr_ptr (), text_len); - temp->wr_ptr (text_len); - - // Forward the whole lot to the next module. - if (put_next (head) == -1) break; - - // Move the file-content block's read pointer up past whatever - // was just processed. Although the mblk's rd_ptr has not been - // moved, cdr's has. Therefore, use its length() to determine - // how much is left. - mblk.rd_ptr (mblk.length () - cdr.length ()); - } - } - - // Now that the file is done, send a block down the stream to tell - // the other modules to stop. - ACE_Message_Block *stop; - ACE_NEW_RETURN - (stop, ACE_Message_Block (0, ACE_Message_Block::MB_STOP), - 0); - put_next (stop); - return 0; - } -}; - -class Logrec_Reader_Module : public ACE_Module<ACE_SYNCH> -{ -public: - Logrec_Reader_Module (const ACE_TString &filename) - : task_ (filename) - { - this->open (ACE_TEXT ("Logrec Reader"), - &task_, // Initialize writer-side. - 0, // Ignore reader-side. - 0, - ACE_Module<ACE_SYNCH>::M_DELETE_READER); - } -private: - Logrec_Reader task_; -}; - -class Logrec_Writer : public ACE_Task<ACE_SYNCH> -{ -public: - //FUZZ: disable check_for_lack_ACE_OS - // Initialization hook method. - virtual int open (void *) { return activate (); } - //FUZZ: enable check_for_lack_ACE_OS - - virtual int put (ACE_Message_Block *mblk, ACE_Time_Value *to) - { return putq (mblk, to); } - - virtual int svc () { - int stop = 0; - for (ACE_Message_Block *mb; !stop && getq (mb) != -1; ) { - if (mb->msg_type () == ACE_Message_Block::MB_STOP) - stop = 1; - else - ACE::write_n (ACE_STDOUT, mb); - put_next (mb); - } - return 0; - } -}; - -LOGREC_MODULE (Logrec_Writer); - -class Logrec_Formatter : public ACE_Task<ACE_SYNCH> -{ -public: - typedef void (*FORMATTER[5])(ACE_Message_Block *); -private: - static FORMATTER format_; // Array of format static methods. - -public: - virtual int put (ACE_Message_Block *mblk, ACE_Time_Value *) { - if (mblk->msg_type () == Logrec_Reader::MB_CLIENT) - for (ACE_Message_Block *temp = mblk; - temp != 0; - temp = temp->cont ()) { - int mb_type = - temp->msg_type () - ACE_Message_Block::MB_USER; - (*format_[mb_type])(temp); - } - return put_next (mblk); - } - - static void format_client (ACE_Message_Block *) { - return; - } - - static void format_type (ACE_Message_Block *mblk) { - ACE_CDR::Long type = * (ACE_CDR::Long *)mblk->rd_ptr (); - mblk->size (11); // Max size in ASCII of 32-bit word. - mblk->reset (); - mblk->wr_ptr ((size_t) ACE_OS::sprintf (mblk->wr_ptr (), "%d", type)); - } - - static void format_pid (ACE_Message_Block *mblk) { - ACE_CDR::Long pid = * (ACE_CDR::Long *)mblk->rd_ptr (); - mblk->size (11); // Max size in ASCII of 32-bit word. - mblk->reset (); - mblk->wr_ptr ((size_t) ACE_OS::sprintf (mblk->wr_ptr (), "%d", pid)); - } - - static void format_time (ACE_Message_Block *mblk) { - ACE_CDR::Long secs = * (ACE_CDR::Long *)mblk->rd_ptr (); - mblk->rd_ptr (sizeof (ACE_CDR::Long)); - ACE_CDR::Long usecs = * (ACE_CDR::Long *)mblk->rd_ptr (); - ACE_TCHAR timestamp_t[26]; - char timestamp[26]; // Max size of ctime_r() string. - time_t time_secs (secs); - ACE_OS::ctime_r (&time_secs, timestamp_t, sizeof timestamp_t); - ACE_OS::strcpy (timestamp, ACE_TEXT_ALWAYS_CHAR (timestamp_t)); - mblk->size (26); // Max size of ctime_r() string. - mblk->reset (); - timestamp[19] = '\0'; // NUL-terminate after the time. - timestamp[24] = '\0'; // NUL-terminate after the date. - size_t fmt_len (ACE_OS::sprintf (mblk->wr_ptr (), - "%s.%03d %s", - timestamp + 4, - usecs / 1000, - timestamp + 20)); - mblk->wr_ptr (fmt_len); - } - - static void format_data (ACE_Message_Block *) { - return; - } -}; - -Logrec_Formatter::FORMATTER Logrec_Formatter::format_ = { - format_client, format_type, format_pid, format_time, format_data -}; - -LOGREC_MODULE (Logrec_Formatter); - -class Logrec_Separator : public ACE_Task<ACE_SYNCH> -{ -private: - ACE_Lock_Adapter<ACE_SYNCH_MUTEX> lock_strategy_; - -public: - virtual int put (ACE_Message_Block *mblk, - ACE_Time_Value *) { - if (mblk->msg_type () != ACE_Message_Block::MB_STOP) { - ACE_Message_Block *separator; - ACE_NEW_RETURN - (separator, - ACE_Message_Block (ACE_OS::strlen ("|") + 1, - ACE_Message_Block::MB_DATA, - 0, 0, 0, &lock_strategy_), - -1); - separator->copy ("|"); - - ACE_Message_Block *dup = 0; - for (ACE_Message_Block *temp = mblk; temp != 0; ) { - dup = separator->duplicate (); - dup->cont (temp->cont ()); - temp->cont (dup); - temp = dup->cont (); - } - ACE_Message_Block *nl; - ACE_NEW_RETURN (nl, ACE_Message_Block (2), 0); - nl->copy ("\n"); - dup->cont (nl); - separator->release (); - } - return put_next (mblk); - } -}; - -LOGREC_MODULE (Logrec_Separator); - -int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - if (argc != 2) - ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s logfile\n", argv[0]), - 1); - ACE_TString logfile (argv[1]); - ACE_Stream<ACE_SYNCH> stream; - - if (stream.push - (new Logrec_Writer_Module (ACE_TEXT ("Writer"))) != -1 - && stream.push - (new Logrec_Separator_Module (ACE_TEXT ("Separator"))) != -1 - && stream.push - (new Logrec_Formatter_Module (ACE_TEXT ("Formatter"))) != -1 - && stream.push - (new Logrec_Reader_Module (logfile)) != -1) - return ACE_Thread_Manager::instance ()->wait () == 0 ? 0 : 1; - return 1; -} - diff --git a/ACE/examples/C++NPv2/svc.conf b/ACE/examples/C++NPv2/svc.conf deleted file mode 100644 index e97f3748cf6..00000000000 --- a/ACE/examples/C++NPv2/svc.conf +++ /dev/null @@ -1,8 +0,0 @@ -static Service_Reporter "-p $SERVICE_REPORTER_PORT" - -dynamic AIO_Client_Logging_Daemon Service_Object * -AIO_CLD:_make_AIO_Client_Logging_Daemon() - "-p 7777" - -dynamic Server_Logging_Daemon Service_Object * -TPCLS:_make_TPC_Logging_Server() |