diff options
Diffstat (limited to 'examples/Logger/simple-server')
-rw-r--r-- | examples/Logger/simple-server/Logging_Acceptor.cpp | 64 | ||||
-rw-r--r-- | examples/Logger/simple-server/Logging_Acceptor.h | 49 | ||||
-rw-r--r-- | examples/Logger/simple-server/Logging_Handler.cpp | 140 | ||||
-rw-r--r-- | examples/Logger/simple-server/Logging_Handler.h | 64 | ||||
-rw-r--r-- | examples/Logger/simple-server/Makefile | 135 | ||||
-rw-r--r-- | examples/Logger/simple-server/Reactor_Singleton.h | 27 | ||||
-rw-r--r-- | examples/Logger/simple-server/server_loggerd.cpp | 63 |
7 files changed, 0 insertions, 542 deletions
diff --git a/examples/Logger/simple-server/Logging_Acceptor.cpp b/examples/Logger/simple-server/Logging_Acceptor.cpp deleted file mode 100644 index 641ed58256c..00000000000 --- a/examples/Logger/simple-server/Logging_Acceptor.cpp +++ /dev/null @@ -1,64 +0,0 @@ - -// $Id$ - -#include "Logging_Acceptor.h" -#include "Logging_Handler.h" -#include "Reactor_Singleton.h" - -// Initialize peer_acceptor object. - -int -Logging_Acceptor::open (const ACE_INET_Addr &addr) -{ - // Reuse addr if already in use. - if (this->peer_acceptor_.open (addr, 1) == -1) - return -1; - else - return 0; -} - -// Default constructor. - -Logging_Acceptor::Logging_Acceptor (void) -{ -} - -// Performs termination activities. - -int -Logging_Acceptor::handle_close (ACE_HANDLE, ACE_Reactor_Mask) -{ - return this->peer_acceptor_.close (); -} - -Logging_Acceptor::~Logging_Acceptor (void) -{ - this->handle_close (ACE_INVALID_HANDLE, - ACE_Event_Handler::READ_MASK); -} - -// Returns underlying device descriptor. - -ACE_HANDLE -Logging_Acceptor::get_handle (void) const -{ - return this->peer_acceptor_.get_handle (); -} - -// Accepts connections from client and registers new object with the -// ACE_Reactor. - -int -Logging_Acceptor::handle_input (ACE_HANDLE) -{ - Logging_Handler *svc_handler = new Logging_Handler; - - // Accept the connection from a client client daemon. - - if (this->peer_acceptor_.accept (*svc_handler) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p", "accept failed"), -1); - else if (svc_handler->open () == -1) - svc_handler->close (); - - return 0; -} diff --git a/examples/Logger/simple-server/Logging_Acceptor.h b/examples/Logger/simple-server/Logging_Acceptor.h deleted file mode 100644 index b653774ddd0..00000000000 --- a/examples/Logger/simple-server/Logging_Acceptor.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Logging_Acceptor.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CLIENT_ACCEPTOR_H) -#define _CLIENT_ACCEPTOR_H - -#include "ace/SOCK_Acceptor.h" -#include "ace/Event_Handler.h" - -class Logging_Acceptor : public ACE_Event_Handler - // = TITLE - // Handle connection requests from remote client clients. - // - // = DESCRIPTION - // Accepts client connection requests, creates Logging_Handler's - // to process them, and registers these Handlers with the - // ACE_Reactor Singleton. -{ -friend class Logging_Handler; -public: - Logging_Acceptor (void); - ~Logging_Acceptor (void); - - int open (const ACE_INET_Addr &a); - -private: - virtual ACE_HANDLE get_handle (void) const; - virtual int handle_input (ACE_HANDLE); - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); - - ACE_SOCK_Acceptor peer_acceptor_; - // Passive connection acceptor factory. -}; - -#endif /* _CLIENT_ACCEPTOR_H */ diff --git a/examples/Logger/simple-server/Logging_Handler.cpp b/examples/Logger/simple-server/Logging_Handler.cpp deleted file mode 100644 index ceb88ac14da..00000000000 --- a/examples/Logger/simple-server/Logging_Handler.cpp +++ /dev/null @@ -1,140 +0,0 @@ - -// $Id$ - -#include "Logging_Handler.h" -#include "Reactor_Singleton.h" - -// Default constructor. - -Logging_Handler::Logging_Handler (void) -{ -} - -Logging_Handler::~Logging_Handler (void) -{ - REACTOR::instance ()->cancel_timer (this); - this->cli_stream_.close (); -} - -// Extract the underlying ACE_SOCK_Stream (e.g., for purposes of -// accept()). - -Logging_Handler::operator ACE_SOCK_Stream &() -{ - return this->cli_stream_; -} - -int -Logging_Handler::handle_timeout (const ACE_Time_Value &, - const void *arg) -{ - ACE_ASSERT (arg == this); - ACE_DEBUG ((LM_DEBUG, "(%P|%t) handling timeout from this = %u\n", this)); - return 0; -} - -// Perform the logging record receive. - -int -Logging_Handler::handle_input (ACE_HANDLE) -{ - ssize_t n; - size_t len; - - // Perform two recv's to emulate record-oriented semantics. Note - // that this code is not entirely portable since it relies on the - // fact that sizeof (ssize_t) is the same on both the sender and - // receiver side. To correctly handle this is painful, and we leave - // it as an exercise for the reader ;-). - - switch (n = this->cli_stream_.recv ((void *) &len, sizeof len)) - { - case -1: - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n", - "client logger", this->host_name_), -1); - /* NOTREACHED */ - case 0: - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) closing log daemon at host %s (fd = %d)\n", - this->host_name_, this->get_handle ()), -1); - /* NOTREACHED */ - case sizeof (size_t): - { - ACE_Log_Record lp; - - len = ntohl (len); - n = this->cli_stream_.recv_n ((void *) &lp, len); - if (n != len) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n", - "client logger", this->host_name_), -1); - /* NOTREACHED */ - - lp.decode (); - - if (lp.length () == n) - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) ")); - lp.print (this->host_name_, 1, cerr); - } - else - ACE_ERROR ((LM_ERROR, "(%P|%t) error, lp.length = %d, n = %d\n", - lp.length (), n)); - break; - } - default: - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p at host %s\n", - "client logger", this->host_name_), -1); - /* NOTREACHED */ - } - - return 0; -} - -// Extract underlying device descriptor. - -ACE_HANDLE -Logging_Handler::get_handle (void) const -{ - return this->cli_stream_.get_handle (); -} - -int -Logging_Handler::open (void) -{ - ACE_INET_Addr addr; - - if (this->cli_stream_.get_remote_addr (addr) == -1) - return -1; - else - { - ACE_OS::strncpy (this->host_name_, addr.get_host_name (), MAXHOSTNAMELEN + 1); - - if (REACTOR::instance ()->register_handler - (this, ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) can't register with reactor\n"), -1); - else if (REACTOR::instance ()->schedule_timer - (this, (const void *) this, ACE_Time_Value (2), ACE_Time_Value (2)) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "can'(%P|%t) t register with reactor\n"), -1); - else - ACE_DEBUG ((LM_DEBUG, "(%P|%t) connected with %s\n", this->host_name_)); - return 0; - } -} - -// Perform termination activities when deregistered from the ACE_Reactor. - -int -Logging_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) -{ - // Must be allocated dynamically! - delete this; - return 0; -} - -// Perform termination activities when close fails. - -int -Logging_Handler::close (void) -{ - return this->handle_close (ACE_INVALID_HANDLE, - ACE_Event_Handler::RWE_MASK); -} diff --git a/examples/Logger/simple-server/Logging_Handler.h b/examples/Logger/simple-server/Logging_Handler.h deleted file mode 100644 index 2d15b5a6295..00000000000 --- a/examples/Logger/simple-server/Logging_Handler.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Logging_Handler.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_CLIENT_HANDLER_H) -#define _CLIENT_HANDLER_H - -#include "ace/Event_Handler.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Stream.h" - -class Logging_Handler : public ACE_Event_Handler - // = TITLE - // Receive client message from the remote clients. - // - // = DESCRIPTION - // This class demonstrates how to receive messages from remote - // clients using the notification mechanisms in the - // <ACE_Reactor>. In addition, it also illustrates how to - // utilize the <ACE_Reactor> timer mechanisms, as well. -{ -public: - Logging_Handler (void); - - // = Hooks for opening and closing handlers. - virtual int open (void); - virtual int close (void); - - operator ACE_SOCK_Stream &(); - // Conversion operators. - -protected: - // = Demultiplexing hooks. - virtual ACE_HANDLE get_handle (void) const; - virtual int handle_input (ACE_HANDLE); - virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); - virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - - // = Really should be private... - virtual ~Logging_Handler (void); - // Ensure dynamic allocation. - -private: - char host_name_[MAXHOSTNAMELEN + 1]; - // Host we are connected to. - - ACE_SOCK_Stream cli_stream_; - // Connection with client -}; - -#endif /* _CLIENT_HANDLER_H */ diff --git a/examples/Logger/simple-server/Makefile b/examples/Logger/simple-server/Makefile deleted file mode 100644 index 21d55783684..00000000000 --- a/examples/Logger/simple-server/Makefile +++ /dev/null @@ -1,135 +0,0 @@ -#---------------------------------------------------------------------------- -# @(#)Makefile 1.1 10/18/96 -# -# Makefile for the Reactor Server Logging Daemon -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = server_loggerd - -FILES = Logging_Acceptor \ - Logging_Handler - -LSRC = $(addsuffix .cpp,$(FILES)) -LOBJ = $(addsuffix .o,$(FILES)) -SHOBJ = $(addsuffix .so,$(FILES)) - -LDLIBS = $(addprefix .shobj/,$(SHOBJ)) - -VLDLIBS = $(LDLIBS:%=%$(VAR)) - -BUILD = $(VBIN) - -#---------------------------------------------------------------------------- -# Include macros and targets -#---------------------------------------------------------------------------- - -include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU -include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU -include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU -include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU -include $(WRAPPER_ROOT)/include/makeinclude/rules.lib.GNU -include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU -include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU - -#---------------------------------------------------------------------------- -# Local targets -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Dependencies -#---------------------------------------------------------------------------- - -# DO NOT DELETE THIS LINE -- g++dep uses it. -# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. - -.obj/Logging_Acceptor.o .shobj/Logging_Acceptor.so: Logging_Acceptor.cpp Logging_Acceptor.h \ - $(WRAPPER_ROOT)/ace/SOCK_Acceptor.h \ - $(WRAPPER_ROOT)/ace/SOCK_Stream.h \ - $(WRAPPER_ROOT)/ace/SOCK_IO.h \ - $(WRAPPER_ROOT)/ace/SOCK.h \ - $(WRAPPER_ROOT)/ace/ACE.h \ - $(WRAPPER_ROOT)/ace/OS.h \ - $(WRAPPER_ROOT)/ace/Time_Value.h \ - $(WRAPPER_ROOT)/ace/config.h \ - $(WRAPPER_ROOT)/ace/stdcpp.h \ - $(WRAPPER_ROOT)/ace/Trace.h \ - $(WRAPPER_ROOT)/ace/Log_Msg.h \ - $(WRAPPER_ROOT)/ace/Log_Record.h \ - $(WRAPPER_ROOT)/ace/Log_Priority.h \ - $(WRAPPER_ROOT)/ace/Log_Record.i \ - $(WRAPPER_ROOT)/ace/ACE.i \ - $(WRAPPER_ROOT)/ace/Addr.h \ - $(WRAPPER_ROOT)/ace/IPC_SAP.h \ - $(WRAPPER_ROOT)/ace/IPC_SAP.i \ - $(WRAPPER_ROOT)/ace/SOCK.i \ - $(WRAPPER_ROOT)/ace/SOCK_IO.i \ - $(WRAPPER_ROOT)/ace/INET_Addr.h \ - $(WRAPPER_ROOT)/ace/SOCK_Stream.i \ - $(WRAPPER_ROOT)/ace/Event_Handler.h \ - Logging_Handler.h Reactor_Singleton.h \ - $(WRAPPER_ROOT)/ace/Singleton.h \ - $(WRAPPER_ROOT)/ace/Reactor.h \ - $(WRAPPER_ROOT)/ace/Handle_Set.h \ - $(WRAPPER_ROOT)/ace/Timer_Queue.h \ - $(WRAPPER_ROOT)/ace/Synch.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.i \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.i \ - $(WRAPPER_ROOT)/ace/Synch_T.h \ - $(WRAPPER_ROOT)/ace/Timer_Queue.i \ - $(WRAPPER_ROOT)/ace/Signal.h \ - $(WRAPPER_ROOT)/ace/Set.h \ - $(WRAPPER_ROOT)/ace/Thread.h \ - $(WRAPPER_ROOT)/ace/Token.h \ - $(WRAPPER_ROOT)/ace/Pipe.h \ - $(WRAPPER_ROOT)/ace/Pipe.i \ - $(WRAPPER_ROOT)/ace/Reactor.i -.obj/Logging_Handler.o .shobj/Logging_Handler.so: Logging_Handler.cpp Logging_Handler.h \ - $(WRAPPER_ROOT)/ace/Event_Handler.h \ - $(WRAPPER_ROOT)/ace/ACE.h \ - $(WRAPPER_ROOT)/ace/OS.h \ - $(WRAPPER_ROOT)/ace/Time_Value.h \ - $(WRAPPER_ROOT)/ace/config.h \ - $(WRAPPER_ROOT)/ace/stdcpp.h \ - $(WRAPPER_ROOT)/ace/Trace.h \ - $(WRAPPER_ROOT)/ace/Log_Msg.h \ - $(WRAPPER_ROOT)/ace/Log_Record.h \ - $(WRAPPER_ROOT)/ace/Log_Priority.h \ - $(WRAPPER_ROOT)/ace/Log_Record.i \ - $(WRAPPER_ROOT)/ace/ACE.i \ - $(WRAPPER_ROOT)/ace/INET_Addr.h \ - $(WRAPPER_ROOT)/ace/Addr.h \ - $(WRAPPER_ROOT)/ace/SOCK_Stream.h \ - $(WRAPPER_ROOT)/ace/SOCK_IO.h \ - $(WRAPPER_ROOT)/ace/SOCK.h \ - $(WRAPPER_ROOT)/ace/IPC_SAP.h \ - $(WRAPPER_ROOT)/ace/IPC_SAP.i \ - $(WRAPPER_ROOT)/ace/SOCK.i \ - $(WRAPPER_ROOT)/ace/SOCK_IO.i \ - $(WRAPPER_ROOT)/ace/SOCK_Stream.i \ - Reactor_Singleton.h \ - $(WRAPPER_ROOT)/ace/Singleton.h \ - $(WRAPPER_ROOT)/ace/Reactor.h \ - $(WRAPPER_ROOT)/ace/Handle_Set.h \ - $(WRAPPER_ROOT)/ace/Timer_Queue.h \ - $(WRAPPER_ROOT)/ace/Synch.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.h \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.i \ - $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.i \ - $(WRAPPER_ROOT)/ace/Synch_T.h \ - $(WRAPPER_ROOT)/ace/Timer_Queue.i \ - $(WRAPPER_ROOT)/ace/Signal.h \ - $(WRAPPER_ROOT)/ace/Set.h \ - $(WRAPPER_ROOT)/ace/Thread.h \ - $(WRAPPER_ROOT)/ace/Token.h \ - $(WRAPPER_ROOT)/ace/Pipe.h \ - $(WRAPPER_ROOT)/ace/Pipe.i \ - $(WRAPPER_ROOT)/ace/Reactor.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/examples/Logger/simple-server/Reactor_Singleton.h b/examples/Logger/simple-server/Reactor_Singleton.h deleted file mode 100644 index 44f2a91eda7..00000000000 --- a/examples/Logger/simple-server/Reactor_Singleton.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// ============================================================================ -// -// = LIBRARY -// examples -// -// = FILENAME -// Reactor_Singleton.h -// -// = AUTHOR -// Doug Schmidt -// -// ============================================================================ - -#if !defined (_REACTOR_SINGLETON_H) -#define _REACTOR_SINGLETON_H - -#include "ace/Singleton.h" -#include "ace/Reactor.h" - -// Our global Reactor Singleton. -typedef ACE_Singleton<ACE_Reactor, ACE_Null_Mutex> REACTOR; - -#endif /* _REACTOR_SINGLETON_H */ diff --git a/examples/Logger/simple-server/server_loggerd.cpp b/examples/Logger/simple-server/server_loggerd.cpp deleted file mode 100644 index 2d65a8b56db..00000000000 --- a/examples/Logger/simple-server/server_loggerd.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// This server daemon collects, formats, and displays logging -// $Id$ - -// information forwarded from client daemons running on other hosts in -// the network. - -// In addition, it also illustrates how the ACE_Reactor framework is -// used. - -#include "ace/Get_Opt.h" - -#include "Logging_Acceptor.h" -#include "Reactor_Singleton.h" - -static sig_atomic_t finished = 0; - -extern "C" void -handler (int) -{ - finished = 1; -} - -// It doesn't get anymore const than this.... -static const u_short PORT = ACE_DEFAULT_SERVER_PORT; - -int -main (int argc, char *argv[]) -{ - // Register a signal handler. - ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); - - Logging_Acceptor peer_acceptor; - ACE_INET_Addr addr (PORT); - - ACE_Get_Opt get_opt (argc, argv, "p:"); - - for (int c; (c = get_opt ()) != -1; ) - switch (c) - { - case 'p': - addr.set (ACE_OS::atoi (get_opt.optarg)); - break; - default: - break; - } - - if (peer_acceptor.open (addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); - else if (REACTOR::instance ()->register_handler - (&peer_acceptor, ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "registering service with ACE_Reactor\n"), -1); - - // Run forever, performing logging service. - - ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting up server logging daemon\n")); - - while (!finished) - REACTOR::instance ()->handle_events (); - - ACE_DEBUG ((LM_DEBUG, "(%P|%t) shutting down server logging daemon\n")); - - return 0; -} |