diff options
Diffstat (limited to 'examples/Reactor/Multicast')
-rw-r--r-- | examples/Reactor/Multicast/Log_Wrapper.cpp | 72 | ||||
-rw-r--r-- | examples/Reactor/Multicast/Log_Wrapper.h | 59 | ||||
-rw-r--r-- | examples/Reactor/Multicast/Makefile | 70 | ||||
-rw-r--r-- | examples/Reactor/Multicast/README | 15 | ||||
-rw-r--r-- | examples/Reactor/Multicast/client.cpp | 105 | ||||
-rw-r--r-- | examples/Reactor/Multicast/server.cpp | 157 |
6 files changed, 0 insertions, 478 deletions
diff --git a/examples/Reactor/Multicast/Log_Wrapper.cpp b/examples/Reactor/Multicast/Log_Wrapper.cpp deleted file mode 100644 index 38b4cdea09f..00000000000 --- a/examples/Reactor/Multicast/Log_Wrapper.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// $Id$ - -// client.C - -#include "Log_Wrapper.h" - -Log_Wrapper::Log_Wrapper (void) -{ - this->log_msg_.sequence_number = 0; - this->log_msg_.app_id = ACE_OS::getpid (); -} - -Log_Wrapper::~Log_Wrapper (void) -{ -} - -// Set the log_msg_ host address. - -int -Log_Wrapper::open (const int port, const char *mcast_addr) -{ - struct hostent *host_info; - struct utsname host_data; - - if (ACE_OS::uname (&host_data) < 0) - return -1; - - if ((host_info = ACE_OS::gethostbyname (host_data.nodename)) == NULL) - return -1; - else - ACE_OS::memcpy ((char *) &this->log_msg_.host, - (char *) host_info->h_addr, - host_info->h_length); - - // This starts out initialized to all zeros! - ACE_INET_Addr sockdg_addr; - - if (this->logger_.open (sockdg_addr) == -1) - return -1; - - if (this->server_.set (port, mcast_addr) == -1) - return -1; - - // success. - return 0; -} - -// Send the message to a logger object. -// This wrapper fills in all the log_record info for you. -// uses iovector stuff to make contiguous header and message. - -int -Log_Wrapper::log_message (ACE_Log_Priority type, char *message) -{ - this->log_msg_.type = type; this->log_msg_.time = time (0); - this->log_msg_.msg_length = strlen(message); - this->log_msg_.sequence_number++; - - iovec *iovp = new iovec[2]; - iovp[0].iov_base = (char *) &log_msg_; - iovp[0].iov_len = sizeof log_msg_; - iovp[1].iov_base = message; - iovp[1].iov_len = log_msg_.msg_length; - - logger_.send (iovp, 2, server_); - - delete iovp; - - // success. - return 0; -} - diff --git a/examples/Reactor/Multicast/Log_Wrapper.h b/examples/Reactor/Multicast/Log_Wrapper.h deleted file mode 100644 index 7fb0e78ceaa..00000000000 --- a/examples/Reactor/Multicast/Log_Wrapper.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - - -// log_wrapper.h -// wrapper around sending log messages via multicast - -#include "ace/Profile_Timer.h" -#include "ace/INET_Addr.h" -#include "ace/SOCK_Dgram.h" - -#if !defined (_LM_WRAPPER_H) -#define _LM_WRAPPER_H - -class Log_Wrapper -{ -public: - Log_Wrapper (void); - ~Log_Wrapper (void); - - // = Types of logging messages. - enum ACE_Log_Priority - { - LM_MESSAGE, - LM_DEBUG, - LM_WARNING, - LM_ERROR, - LM_EMERG - }; - - int open (const int port, const char* mcast_addr); - // get an object reference from an orbixd - - int log_message (ACE_Log_Priority type, char *message); - // send a string to the logger - - // = Format of the logging record. - struct ACE_Log_Record - { - unsigned long sequence_number; - ACE_Log_Priority type; - long host; - long time; - long app_id; - long msg_length; - }; - -private: - ACE_INET_Addr server_; - // Server address where records are logged. - - ACE_Log_Record log_msg_; - // One record used for many log messages. - - ACE_SOCK_Dgram logger_; - // A logger object. -}; - -#endif /* _LM_WRAPPER_H */ diff --git a/examples/Reactor/Multicast/Makefile b/examples/Reactor/Multicast/Makefile deleted file mode 100644 index 556086b9ebe..00000000000 --- a/examples/Reactor/Multicast/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -#---------------------------------------------------------------------------- -# @(#)Makefile 1.1 10/18/96 -# -# Makefile for the Reactor multicast tests -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# Local macros -#---------------------------------------------------------------------------- - -BIN = client server - -FILES = Log_Wrapper - -LSRC = $(addsuffix .cpp,$(FILES)) -LOBJ = $(addsuffix .o,$(FILES)) -SHOBJ = $(addsuffix .so,$(FILES)) - -LDLIBS = $(addprefix .shobj/,$(SHOBJ)) - -VLDLIBS = $(LDLIBS:%=%$(VAR)) - -BUILD = $(VBIN) - -#---------------------------------------------------------------------------- -# ACE stuff -#---------------------------------------------------------------------------- - -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/Log_Wrapper.o .shobj/Log_Wrapper.so: Log_Wrapper.cpp Log_Wrapper.h \ - $(WRAPPER_ROOT)/ace/Profile_Timer.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_Dgram.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_Dgram.i - -# IF YOU PUT ANYTHING HERE IT WILL GO AWAY diff --git a/examples/Reactor/Multicast/README b/examples/Reactor/Multicast/README deleted file mode 100644 index 85f64cc8120..00000000000 --- a/examples/Reactor/Multicast/README +++ /dev/null @@ -1,15 +0,0 @@ -The following test illustrates the SOCK Mcast multicast wrappers in -conjunction with the Reactor. This test was written by Tim Harrison -(harrison@cs.wustl.edu). - -To run the server type: - -% server & - -It will wait for the first message sent to it and then read for 5 seconds. - -To run the client type any of these: - -% client -m max_message_size -i iterations -% client < <filename> -% client diff --git a/examples/Reactor/Multicast/client.cpp b/examples/Reactor/Multicast/client.cpp deleted file mode 100644 index 7a116083336..00000000000 --- a/examples/Reactor/Multicast/client.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// $Id$ - -// This program reads in messages from stdin and sends them to a -// Log_Wrapper. - - -#include "Log_Wrapper.h" - -const char *MCAST_ADDR = ACE_DEFAULT_MULTICAST_ADDR; - -const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT; - -// maximum message size -static int max_message_size = BUFSIZ * 20; - -// number of times to send message of max_message_size -static int iterations = 0; - -static void -parse_args (int argc, char *argv[]) -{ - int c; - - ACE_LOG_MSG->open (argv[0]); - - while ((c = ACE_OS::getopt (argc, argv, "m:ui:")) != -1) - switch (c) - { - case 'm': - max_message_size = ACE_OS::atoi (optarg) * BUFSIZ; - break; - case 'i': - iterations = ACE_OS::atoi (optarg); - break; - case 'u': - // usage fallthrough - default: - ACE_ERROR ((LM_ERROR, "%n: -m max_message_size (in k) -i iterations\n%a", 1)); - /* NOTREACHED */ - } -} - -int -main (int argc, char **argv) -{ - int user_prompt; - - parse_args (argc,argv); - - ACE_DEBUG ((LM_DEBUG, "Max Buffer size = %d\n", max_message_size)); - - // Instantiate a log wrapper for logging - Log_Wrapper log; - - // make a connection to a logger via orbixd - if (log.open (UDP_PORT, MCAST_ADDR) == -1) - ACE_OS::perror ("connect failed"), ACE_OS::exit (1); - - char *buf; - - ACE_NEW_RETURN (buf, char[::max_message_size], -1); - - // If -i has been specified, send max_message_size messages - // iterations number of times. - if (iterations) - { - ACE_OS::memset (buf,1,::max_message_size); - while (iterations--) - if (log.log_message (Log_Wrapper::LM_DEBUG, buf) == -1) - perror("log failed."), exit(1); - } - - // otherwise, a file has been redirected, or give prompts - else - { - // If a file has been redirected, don't activate user prompts - if (ACE_OS::isatty (0)) - user_prompt = 1; - else - user_prompt = 0; - - int nbytes; - // continually read messages from stdin and log them. - while (1) - { - if (user_prompt) - ACE_DEBUG ((LM_DEBUG, "\nEnter message ('Q':quit):\n")); - - if ((nbytes = read (0, buf, max_message_size)) == 0) - break; // end of file - buf[nbytes] = '\0'; - - // quitting? - if (buf[0] == 'Q') - break; - - // send the message to the logger - else if (log.log_message (Log_Wrapper::LM_DEBUG, buf) == -1) - perror("log failed."), exit(1); - } // while(1) - } - - ACE_DEBUG ((LM_DEBUG, "Client done.\n")); - return 0; -} diff --git a/examples/Reactor/Multicast/server.cpp b/examples/Reactor/Multicast/server.cpp deleted file mode 100644 index b8fdcd06b07..00000000000 --- a/examples/Reactor/Multicast/server.cpp +++ /dev/null @@ -1,157 +0,0 @@ -// server.C (written by Tim Harrison) -// $Id$ - -// -// listens to multicast address. after first message received, will -// listen for 5 more seconds. prints Mbits/sec received from client. - -#include "ace/SOCK_Dgram.h" -#include "ace/INET_Addr.h" - -#include "ace/SOCK_Dgram_Mcast.h" -#include "ace/Reactor.h" -#include "Log_Wrapper.h" - -#if defined (ACE_HAS_IP_MULTICAST) -class Server_Events : public ACE_Event_Handler -{ -public: - Server_Events (u_short port, - const char *mcast_addr, - long time_interval = 0); - ~Server_Events (void); - - virtual int handle_input (ACE_HANDLE fd); - virtual ACE_HANDLE get_handle (void) const; - - ACE_Time_Value *wait_time (void); - -private: - char *message_; - Log_Wrapper::ACE_Log_Record *log_record_; - char buf_[4*BUFSIZ]; - - int interval_; - // time interval to log messages - - ACE_Time_Value *how_long_; - ACE_Reactor *reactor_; - ACE_SOCK_Dgram_Mcast mcast_dgram_; - ACE_INET_Addr remote_addr_; - ACE_INET_Addr mcast_addr_; - - // = statistics on messages received - double total_bytes_received_; - int total_messages_received_; - int last_sequence_number_; -}; - -ACE_HANDLE -Server_Events::get_handle (void) const -{ - return this->mcast_dgram_.get_handle (); -} - -ACE_Time_Value * -Server_Events::wait_time (void) -{ - return this->how_long_; -} - -Server_Events::Server_Events (u_short port, - const char *mcast_addr, - long time_interval) - : total_bytes_received_ (0), - interval_ (time_interval), - mcast_addr_ (port, mcast_addr) -{ - // use ACE_SOCK_Dgram_Mcast factory to subscribe to multicast group. - - if (this->mcast_dgram_.subscribe (this->mcast_addr_) == -1) - perror("can't subscribe to multicast group"), exit(1); - - // Point to NULL so that we block in the beginning. - this->how_long_ = 0; - - this->log_record_ = (Log_Wrapper::ACE_Log_Record *) &buf_; - this->message_ = &buf_[sizeof (Log_Wrapper::ACE_Log_Record)]; -} - -// A destructor that emacs refuses to color blue ;-) - -Server_Events::~Server_Events (void) -{ - this->mcast_dgram_.unsubscribe (); - - ACE_DEBUG ((LM_DEBUG, "total bytes received = %d after %d second\n", - this->total_bytes_received_, this->interval_)); - - ACE_DEBUG ((LM_DEBUG, "Mbits/sec = %.2f\n", - (float) (total_bytes_received_ * 8 / (float) (1024*1024*interval_)))); - - ACE_DEBUG ((LM_DEBUG, - "last sequence number = %d\ntotal messages received = %d\ndiff = %d\n", - this->last_sequence_number_, - this->total_messages_received_, - this->last_sequence_number_ - total_messages_received_)); -} - -int -Server_Events::handle_input (ACE_HANDLE) -{ - // after the first message, point this to a timer - // that way, the next time reactor::handle_events is called, - // a nonzero time value will be passed in. - if (this->how_long_ == 0) - this->how_long_ = new ACE_Time_Value (this->interval_); - - // receive message from multicast group - int retcode = this->mcast_dgram_.recv (this->buf_, - sizeof this->buf_, - this->remote_addr_); - if (retcode != -1) - { - total_messages_received_++; - total_bytes_received_ += retcode; - last_sequence_number_ = log_record_->sequence_number; - ACE_DEBUG ((LM_DEBUG, "sequence number = %d\n", - log_record_->sequence_number)); - return 0; - } - else - return -1; -} - -static const char MCAST_ADDR[] = ACE_DEFAULT_MULTICAST_ADDR; -static const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT; - -int -main(int, char *[]) -{ - int duration = 5; - - // Instantiate a server which will receive messages for 5 seconds. - Server_Events server_events (UDP_PORT, MCAST_ADDR, duration); - - // Instance of the ACE_Reactor. - ACE_Reactor reactor; - - if (reactor.register_handler (&server_events, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR ((LM_ERROR, "%p\n%a", "register_handler", 1)); - - for (;;) - reactor.handle_events (server_events.wait_time ()); - - /* NOTREACHED */ - return 0; -} -#else -int -main (int, char *argv[]) -{ - ACE_ERROR_RETURN ((LM_ERROR, - "error: %s must be run on a platform that support IP multicast\n", - argv[0]), -1); -} -#endif /* ACE_HAS_IP_MULTICAST */ |