summaryrefslogtreecommitdiff
path: root/examples/IOStream
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-02-05 05:38:00 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-02-05 05:38:00 +0000
commit23eea7175fd038181864af0efcfc78eb36c26d60 (patch)
treebda9096e9261f9aca4c715ae00b6031bf2513564 /examples/IOStream
parentc1baec3caf72d4ab17bb68ed7320273e49e5185d (diff)
downloadATCD-23eea7175fd038181864af0efcfc78eb36c26d60.tar.gz
foo
Diffstat (limited to 'examples/IOStream')
-rw-r--r--examples/IOStream/Makefile25
-rw-r--r--examples/IOStream/client/Makefile67
-rw-r--r--examples/IOStream/client/iostream_client.cpp44
-rw-r--r--examples/IOStream/server/Makefile104
-rw-r--r--examples/IOStream/server/iostream_server.cpp141
5 files changed, 381 insertions, 0 deletions
diff --git a/examples/IOStream/Makefile b/examples/IOStream/Makefile
new file mode 100644
index 00000000000..699113be687
--- /dev/null
+++ b/examples/IOStream/Makefile
@@ -0,0 +1,25 @@
+#----------------------------------------------------------------------------
+# @(#)Makefile 1.1 10/18/96
+#
+# Makefile for the ACE IOStream examples
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+INFO = README
+
+DIRS = client \
+ server
+
+#----------------------------------------------------------------------------
+# 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.nested.GNU
+include $(WRAPPER_ROOT)/include/makeinclude/rules.nolocal.GNU
+
diff --git a/examples/IOStream/client/Makefile b/examples/IOStream/client/Makefile
new file mode 100644
index 00000000000..fe48a7d2a30
--- /dev/null
+++ b/examples/IOStream/client/Makefile
@@ -0,0 +1,67 @@
+#----------------------------------------------------------------------------
+# @(#)Makefile 1.1 10/18/96
+#
+# Makefile for IOStream test client
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+BIN = iostream_client
+
+LSRC = $(addsuffix .cpp,$(BIN))
+
+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.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/iostream_client.o .shobj/iostream_client.so: iostream_client.cpp \
+ $(WRAPPER_ROOT)/ace/SOCK_Connector.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/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/Time_Value.h \
+ $(WRAPPER_ROOT)/ace/SOCK_Connector.i \
+ $(WRAPPER_ROOT)/ace/IOStream.h
+
+# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/examples/IOStream/client/iostream_client.cpp b/examples/IOStream/client/iostream_client.cpp
new file mode 100644
index 00000000000..0b3d983e73e
--- /dev/null
+++ b/examples/IOStream/client/iostream_client.cpp
@@ -0,0 +1,44 @@
+#include "ace/SOCK_Connector.h"
+#include "ace/IOStream.h"
+
+int main (int argc, char *argv[])
+{
+ u_short server_port = argc > 1 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT;
+ char *server_host = argc > 2 ? argv[3] : ACE_DEFAULT_SERVER_HOST;
+
+ ACE_IOStream<ACE_SOCK_Stream> server;
+ ACE_SOCK_Connector connector;
+ ACE_INET_Addr addr (server_port, server_host);
+
+ if (connector.connect (server, addr) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1);
+
+ server << "1 2.3 testing" << endl; // Command the server to execute function 'foo'
+ server.sync (); // Force the data to the server.
+
+ int i;
+ float f;
+
+#if defined (__GNUC__)
+ String s1;
+ QuotedString s2;
+ server >> s1 >> i >> f >> s2;
+
+ cerr << "Server said:\n\t";
+ cerr << s1 << " ";
+ cerr << i << " ";
+ cerr << f << " ";
+ cerr << s2 << endl;
+#else
+ server >> i >> f;
+
+ cerr << "Server said:\n\t";
+ cerr << i << " ";
+ cerr << f << endl;
+#endif /* __GNUC__ */
+
+ if (server.close () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1);
+
+ return 0;
+}
diff --git a/examples/IOStream/server/Makefile b/examples/IOStream/server/Makefile
new file mode 100644
index 00000000000..339997d2371
--- /dev/null
+++ b/examples/IOStream/server/Makefile
@@ -0,0 +1,104 @@
+#----------------------------------------------------------------------------
+# @(#)Makefile 1.1 10/18/96
+#
+# Makefile for IOStream test server
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+BIN = iostream_server
+
+LSRC = $(addsuffix .cpp,$(BIN))
+
+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.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/iostream_server.o .shobj/iostream_server.so: iostream_server.cpp \
+ $(WRAPPER_ROOT)/ace/Acceptor.h \
+ $(WRAPPER_ROOT)/ace/Service_Config.h \
+ $(WRAPPER_ROOT)/ace/Service_Object.h \
+ $(WRAPPER_ROOT)/ace/Shared_Object.h \
+ $(WRAPPER_ROOT)/ace/ACE.h \
+ $(WRAPPER_ROOT)/ace/OS.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/Event_Handler.h \
+ $(WRAPPER_ROOT)/ace/Thread_Manager.h \
+ $(WRAPPER_ROOT)/ace/Thread.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/Signal.h \
+ $(WRAPPER_ROOT)/ace/Set.h \
+ $(WRAPPER_ROOT)/ace/Reactor.h \
+ $(WRAPPER_ROOT)/ace/Handle_Set.h \
+ $(WRAPPER_ROOT)/ace/Timer_Queue.h \
+ $(WRAPPER_ROOT)/ace/Time_Value.h \
+ $(WRAPPER_ROOT)/ace/Token.h \
+ $(WRAPPER_ROOT)/ace/Pipe.h \
+ $(WRAPPER_ROOT)/ace/Pipe.i \
+ $(WRAPPER_ROOT)/ace/SOCK_Stream.h \
+ $(WRAPPER_ROOT)/ace/SOCK_IO.h \
+ $(WRAPPER_ROOT)/ace/SOCK.h \
+ $(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/Proactor.h \
+ $(WRAPPER_ROOT)/ace/Message_Block.h \
+ $(WRAPPER_ROOT)/ace/Malloc.h \
+ $(WRAPPER_ROOT)/ace/Malloc_T.h \
+ $(WRAPPER_ROOT)/ace/Memory_Pool.h \
+ $(WRAPPER_ROOT)/ace/Mem_Map.h \
+ $(WRAPPER_ROOT)/ace/ReactorEx.h \
+ $(WRAPPER_ROOT)/ace/Message_Queue.h \
+ $(WRAPPER_ROOT)/ace/IO_Cntl_Msg.h \
+ $(WRAPPER_ROOT)/ace/Strategies.h \
+ $(WRAPPER_ROOT)/ace/Strategies_T.h \
+ $(WRAPPER_ROOT)/ace/Svc_Conf_Tokens.h \
+ $(WRAPPER_ROOT)/ace/Svc_Handler.h \
+ $(WRAPPER_ROOT)/ace/Synch_Options.h \
+ $(WRAPPER_ROOT)/ace/Task.h \
+ $(WRAPPER_ROOT)/ace/Task_T.h \
+ $(WRAPPER_ROOT)/ace/Acceptor.i \
+ $(WRAPPER_ROOT)/ace/SOCK_Acceptor.h \
+ $(WRAPPER_ROOT)/ace/IOStream.h
+
+# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/examples/IOStream/server/iostream_server.cpp b/examples/IOStream/server/iostream_server.cpp
new file mode 100644
index 00000000000..81dc8555663
--- /dev/null
+++ b/examples/IOStream/server/iostream_server.cpp
@@ -0,0 +1,141 @@
+// This is a simple example of using the ACE_IOStream and
+// ACE_streambuf templates to create an object based on ACE_*_Stream
+// classes which mimic a C++ iostream.
+
+#include "ace/Acceptor.h"
+#include "ace/SOCK_Acceptor.h"
+#include "ace/Service_Config.h"
+#include "ace/IOStream.h"
+
+// Declare a new type which will case an ACE_SOCK_Stream to behave
+// like an iostream. The new type (ACE_SOCK_IOStream) can be used
+// anywhere an ACE_SOCK_Stream is used.
+
+typedef ACE_IOStream<ACE_SOCK_Stream> ACE_SOCK_IOStream ;
+
+// Create a service handler object based on our new
+// iostream/SOCK_Stream hybrid.
+
+typedef ACE_Svc_Handler<ACE_SOCK_IOStream, ACE_INET_Addr, ACE_NULL_SYNCH>
+ Service_Handler;
+
+class Handler : public Service_Handler
+ // = TITLE
+ // Extend the <Service_Handler> object to do our bidding. All of
+ // this is fairly standard until we get to the <handle_input>
+ // where we begin using the iostream characteristics of the
+ // peer.
+{
+public:
+ Handler (void) {}
+
+ virtual int open (void *)
+ {
+ if (this->reactor () ->register_handler
+ (this, ACE_Event_Handler::READ_MASK) == - 1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "registering connection handler with ACE_Reactor\n"),
+ - 1);
+
+ return 0;
+ }
+
+ virtual void destroy (void)
+ {
+ this->peer ().close ();
+ delete this ;
+ }
+
+ virtual int close (u_long)
+ {
+ this->destroy ();
+ return 0 ;
+ }
+
+ virtual int handle_input (ACE_HANDLE)
+ {
+ int i;
+ float f;
+
+#if defined (__GNUC__)
+ String s;
+
+ if (!(this -> peer () >> i >> f >> s))
+ {
+ cerr << "Error getting data" << endl ;
+ return - 1 ;
+ }
+
+ cerr << "Received (" << i << ") (" << f << ") (" << s << ")" << endl ;
+
+ if (!(this -> peer () << "Received (" << i << ") (" << f << ") (" << s << ")" << endl))
+ {
+ cerr << __LINE__ << "Error sending data" << endl ;
+ return - 1 ;
+ }
+#else
+ if (!(this -> peer () >> i >> f))
+ {
+ cerr << "Error getting data" << endl ;
+ return - 1 ;
+ }
+
+ cerr << "Received (" << i << ") (" << f << ")" << endl;
+
+ if (!(this -> peer () << "Received (" << i << ") (" << f << ")" << endl))
+ {
+ cerr << __LINE__ << "Error sending data" << endl ;
+ return - 1 ;
+ }
+#endif /* __GNUC__ */
+ // In order to flush the output to the peer, we have to use the
+ // sync () function. Some iostreams implementations let us use a
+ // 'flush' function much like the 'endl' function.
+
+ this->peer ().sync ();
+ return 0;
+ }
+};
+
+// Create an object which will accept new connection requests and
+// create handler objects for us.
+
+typedef ACE_Acceptor<Handler, ACE_SOCK_ACCEPTOR> Logging_Acceptor;
+
+static const u_short PORT = 10003;
+
+int
+main (int argc, char *argv [])
+{
+ ACE_Service_Config daemon;
+
+ // Create an adapter to end the event loop.
+ ACE_Sig_Adapter sa ((ACE_Sig_Handler_Ex) ACE_Service_Config::end_reactor_event_loop);
+
+ ACE_Sig_Set sig_set;
+ sig_set.sig_add (SIGINT);
+ sig_set.sig_add (SIGQUIT);
+
+ // Register ourselves to receive SIGINT and SIGQUIT so we can shut
+ // down gracefully via signals.
+ if (ACE_Service_Config::reactor ()->register_handler (sig_set, &sa) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n"), -1);
+
+ Logging_Acceptor peer_acceptor ;
+
+ if (peer_acceptor.open (ACE_INET_Addr (argc > 1 ? atoi (argv[1]) : PORT)) == - 1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), - 1);
+
+ else if (ACE_Service_Config::reactor ()->register_handler
+ (&peer_acceptor, ACE_Event_Handler::READ_MASK) == - 1)
+ ACE_ERROR_RETURN ((LM_ERROR, "registering service with ACE_Reactor\n"), - 1);
+
+ ACE_DEBUG ((LM_DEBUG, " (%P|%t) starting up daemon\n"));
+
+ daemon.run_reactor_event_loop ();
+
+ ACE_DEBUG ((LM_DEBUG, " (%P|%t) shutting down server daemon\n"));
+
+ return 0;
+}
+