summaryrefslogtreecommitdiff
path: root/ACE/examples/IOStream
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/examples/IOStream')
-rw-r--r--ACE/examples/IOStream/Makefile.am14
-rw-r--r--ACE/examples/IOStream/README22
-rw-r--r--ACE/examples/IOStream/client/.cvsignore2
-rw-r--r--ACE/examples/IOStream/client/IOStream_Client.mpc5
-rw-r--r--ACE/examples/IOStream/client/Makefile.am30
-rw-r--r--ACE/examples/IOStream/client/iostream_client.cpp71
-rw-r--r--ACE/examples/IOStream/server/.cvsignore2
-rw-r--r--ACE/examples/IOStream/server/IOStream_Server.mpc5
-rw-r--r--ACE/examples/IOStream/server/Makefile.am33
-rw-r--r--ACE/examples/IOStream/server/iostream_server.cpp132
-rw-r--r--ACE/examples/IOStream/server/iostream_server.h53
11 files changed, 369 insertions, 0 deletions
diff --git a/ACE/examples/IOStream/Makefile.am b/ACE/examples/IOStream/Makefile.am
new file mode 100644
index 00000000000..0a99932ce34
--- /dev/null
+++ b/ACE/examples/IOStream/Makefile.am
@@ -0,0 +1,14 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+SUBDIRS = \
+ client \
+ server
+
diff --git a/ACE/examples/IOStream/README b/ACE/examples/IOStream/README
new file mode 100644
index 00000000000..ab215fc779d
--- /dev/null
+++ b/ACE/examples/IOStream/README
@@ -0,0 +1,22 @@
+This example illustrates the use of the ACE_IOStream and
+ACE_Streambuf_T templates to create an object based on ACE_*_Stream
+classes. These classes provide C++ iostream functionality across a
+socket.
+
+To run the tests simply build the executables in the client and server
+directories and then do the following in separate windows:
+
+# Window 1
+% server/iostream_server
+(10049) starting up daemon
+
+# Window 2
+% client/iostream_client
+(10049) starting handler 456d0
+(10049) Client sent:
+ (1) (2.3)
+(10051) Server sent:
+ (1) (2.3)
+(10049) connection closed
+(10049) shutting down handler 456d0
+(10049) shutting down server daemon
diff --git a/ACE/examples/IOStream/client/.cvsignore b/ACE/examples/IOStream/client/.cvsignore
new file mode 100644
index 00000000000..e5eeb0703df
--- /dev/null
+++ b/ACE/examples/IOStream/client/.cvsignore
@@ -0,0 +1,2 @@
+iostream_client
+iostream_client
diff --git a/ACE/examples/IOStream/client/IOStream_Client.mpc b/ACE/examples/IOStream/client/IOStream_Client.mpc
new file mode 100644
index 00000000000..ca6b8ee6622
--- /dev/null
+++ b/ACE/examples/IOStream/client/IOStream_Client.mpc
@@ -0,0 +1,5 @@
+// -*- MPC -*-
+// $Id$
+
+project : aceexe {
+} \ No newline at end of file
diff --git a/ACE/examples/IOStream/client/Makefile.am b/ACE/examples/IOStream/client/Makefile.am
new file mode 100644
index 00000000000..e1225bbb6d5
--- /dev/null
+++ b/ACE/examples/IOStream/client/Makefile.am
@@ -0,0 +1,30 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+## Makefile.IOStream_Client.am
+noinst_LTLIBRARIES = libIOStream_Client.la
+
+libIOStream_Client_la_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR)
+
+libIOStream_Client_la_SOURCES = \
+ iostream_client.cpp
+
+## 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/IOStream/client/iostream_client.cpp b/ACE/examples/IOStream/client/iostream_client.cpp
new file mode 100644
index 00000000000..e8ddedf9b44
--- /dev/null
+++ b/ACE/examples/IOStream/client/iostream_client.cpp
@@ -0,0 +1,71 @@
+// $Id$
+
+#include "ace/SOCK_Connector.h"
+#include "ace/IOStream.h"
+#include "ace/Log_Msg.h"
+#include "ace/OS_NS_stdlib.h"
+#include "ace/OS_NS_unistd.h"
+
+ACE_RCSID (client,
+ iostream_client,
+ "$Id$")
+
+// This client is a simple example of using the ACE_IOStream and
+// ACE_Streambuf_T templates to create an object based on ACE_*_Stream
+// classes, which mimic a C++ iostream.
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+#if !defined (ACE_LACKS_ACE_IOSTREAM)
+ const ACE_TCHAR *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST;
+ u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT;
+
+ 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);
+
+ // Buffer up some things to send to the server.
+ server << "1 2.3 testing" << endl;
+
+ int i;
+ float f;
+
+#if defined (ACE_HAS_STRING_CLASS)
+ ACE_IOStream_String s1;
+ ACE_IOStream_String 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 << "(" << ACE_OS::getpid () << ") Server sent:\n\t";
+ cerr << "(" << i << ") ";
+ cerr << "(" << f << ")" << endl;
+#endif /* ACE_HAS_STRING_CLASS */
+
+ if (server.close () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "close"),
+ -1);
+#else
+ ACE_UNUSED_ARG (argc);
+ ACE_UNUSED_ARG (argv);
+ ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n"));
+#endif /* !ACE_LACKS_ACE_IOSTREAM */
+ return 0;
+}
+
diff --git a/ACE/examples/IOStream/server/.cvsignore b/ACE/examples/IOStream/server/.cvsignore
new file mode 100644
index 00000000000..e37ecb3f31b
--- /dev/null
+++ b/ACE/examples/IOStream/server/.cvsignore
@@ -0,0 +1,2 @@
+iostream_server
+iostream_server
diff --git a/ACE/examples/IOStream/server/IOStream_Server.mpc b/ACE/examples/IOStream/server/IOStream_Server.mpc
new file mode 100644
index 00000000000..ca6b8ee6622
--- /dev/null
+++ b/ACE/examples/IOStream/server/IOStream_Server.mpc
@@ -0,0 +1,5 @@
+// -*- MPC -*-
+// $Id$
+
+project : aceexe {
+} \ No newline at end of file
diff --git a/ACE/examples/IOStream/server/Makefile.am b/ACE/examples/IOStream/server/Makefile.am
new file mode 100644
index 00000000000..8b72a1adb62
--- /dev/null
+++ b/ACE/examples/IOStream/server/Makefile.am
@@ -0,0 +1,33 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+## Makefile.IOStream_Server.am
+noinst_LTLIBRARIES = libIOStream_Server.la
+
+libIOStream_Server_la_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR)
+
+libIOStream_Server_la_SOURCES = \
+ iostream_server.cpp
+
+noinst_HEADERS = \
+ iostream_server.h
+
+## 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/IOStream/server/iostream_server.cpp b/ACE/examples/IOStream/server/iostream_server.cpp
new file mode 100644
index 00000000000..656b432a579
--- /dev/null
+++ b/ACE/examples/IOStream/server/iostream_server.cpp
@@ -0,0 +1,132 @@
+// $Id$
+
+// This is a simple example of using the ACE_IOStream and
+// ACE_Streambuf_T 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/Signal.h"
+
+#include "iostream_server.h"
+#include "ace/OS_NS_unistd.h"
+
+ACE_RCSID(server, iostream_server, "$Id$")
+
+#if !defined (ACE_LACKS_ACE_IOSTREAM)
+
+int
+Handler::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;
+}
+
+Handler::Handler (void)
+{
+ ACE_DEBUG ((LM_DEBUG, "(%P) starting handler %x\n", this));
+}
+
+Handler::~Handler (void)
+{
+ ACE_DEBUG ((LM_DEBUG, "(%P) shutting down handler %x\n", this));
+ ACE_Reactor::end_event_loop ();
+}
+
+int
+Handler::handle_input (ACE_HANDLE)
+{
+ int i;
+ float f;
+
+ // Check to see if the socket is closed down.
+ if (this->peer ().eof ())
+ ACE_ERROR_RETURN ((LM_ERROR, "(%P) connection closed\n"), -1);
+
+#if defined (ACE_HAS_STRING_CLASS)
+ ACE_IOStream_String s;
+
+ if (!(this->peer () >> i >> f >> s))
+ ACE_ERROR_RETURN ((LM_ERROR, "(%P) %p\n", "error getting data"), -1);
+
+ cerr << "(" << ACE_OS::getpid () << ") Client sent:\n\t";
+ cerr << "(" << i << ") (" << f << ") (" << s << ")" << endl ;
+
+ if (!(this->peer () << "Received: " << i << " " << f << " " << s << endl))
+ ACE_ERROR_RETURN ((LM_ERROR, "(%P) %p\n", "error sending data"), -1);
+
+#else
+ if (!(this->peer () >> i >> f))
+ ACE_ERROR_RETURN ((LM_ERROR, "(%P) %p\n", "error getting data"), -1);
+
+ cerr << "(" << ACE_OS::getpid () << ") Client sent:\n\t";
+ cerr << "(" << i << ") (" << f << ")" << endl;
+
+ if (!(this->peer () << i << " " << f << endl))
+ ACE_ERROR_RETURN ((LM_ERROR, "(%P) %p\n", "error sending data"), -1);
+#endif /* ACE_HAS_STRING_CLASS */
+
+ // 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 a factory object that will accept new connection requests
+// and create handler objects for us.
+
+typedef ACE_Acceptor<Handler, ACE_SOCK_ACCEPTOR> IOStream_Acceptor;
+#endif /* !ACE_LACKS_ACE_IOSTREAM */
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv [])
+{
+#if !defined (ACE_LACKS_ACE_IOSTREAM)
+ ACE_Service_Config daemon;
+
+ // Create an adapter to end the event loop.
+ ACE_Sig_Adapter sa ((ACE_Sig_Handler_Ex) ACE_Reactor::end_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_Reactor::instance ()->register_handler (sig_set,
+ &sa) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n"), -1);
+
+ IOStream_Acceptor peer_acceptor;
+
+ ACE_INET_Addr addr (argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT);
+
+ if (peer_acceptor.open (addr) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "open"),
+ -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P) starting up daemon\n"));
+
+ ACE_Reactor::run_event_loop ();
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P) shutting down server daemon\n"));
+
+#else
+ ACE_UNUSED_ARG (argc);
+ ACE_UNUSED_ARG (argv);
+ ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform\n"));
+#endif /* !ACE_LACKS_ACE_IOSTREAM */
+ return 0;
+}
+
diff --git a/ACE/examples/IOStream/server/iostream_server.h b/ACE/examples/IOStream/server/iostream_server.h
new file mode 100644
index 00000000000..e5f4cbd63b9
--- /dev/null
+++ b/ACE/examples/IOStream/server/iostream_server.h
@@ -0,0 +1,53 @@
+// $Id$
+
+// This file defines the class needed for iostream_server.cpp - it's a separate
+// file to satisfy IBM's xlC template instantiation.
+
+#ifndef __IOSTREAM_SERVER_H
+#define __IOSTREAM_SERVER_H
+
+#include "ace/INET_Addr.h"
+#include "ace/IOStream.h"
+#include "ace/SOCK_Stream.h"
+#include "ace/Svc_Handler.h"
+
+#if !defined (ACE_LACKS_ACE_IOSTREAM)
+
+// Declare a new type which will case an ACE_SOCK_Stream to behave
+// like an iostream. The new ACE_SOCK_IOStream type can be used
+// anywhere an ACE_SOCK_Stream is used.
+
+typedef ACE_IOStream<ACE_SOCK_Stream> ACE_SOCK_IOStream;
+
+// Need to handle brain-dead C++ compilers.
+#if defined (ACE_HAS_TEMPLATE_TYPEDEFS)
+#define ACE_SOCK_IOSTREAM ACE_SOCK_IOStream
+#else
+#define ACE_SOCK_IOSTREAM ACE_SOCK_IOStream, ACE_INET_Addr
+#endif /* ACE_HAS_TYPENAME_KEYWORD */
+
+class Handler : public ACE_Svc_Handler<ACE_SOCK_IOSTREAM, ACE_NULL_SYNCH>
+ // = TITLE
+ // Extend the <ACE_Svc_Handler> template to do our bidding.
+ //
+ // = DESCRIPTION
+ // Create an <ACE_Svc_Handler> object based on our
+ // iostream/SOCK_Stream hybrid. All of this is fairly standard
+ // until we get to the <handle_input> where we begin using the
+ // iostream characteristics of the peer.
+{
+public:
+ // = Initialization and termination methods.
+ Handler (void);
+ ~Handler (void);
+
+ // = <Svc_Handler> hooks.
+ virtual int open (void *);
+
+ // = <Event_Handler> hooks.
+ virtual int handle_input (ACE_HANDLE);
+};
+
+#endif /* ACE_LACKS_ACE_IOSTREAM */
+
+#endif /* __IOSTREAM_SERVER_H */