summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoeh <joeh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-07 18:57:27 +0000
committerjoeh <joeh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-07 18:57:27 +0000
commit6ebd54cf095b9b485219180f5f189b26ddf4347e (patch)
treebd7204e79f05bf8a1a5388de0434726b8dfb7217
parent149a34a006c1548e7580d7250ad73e29f443ecaf (diff)
downloadATCD-6ebd54cf095b9b485219180f5f189b26ddf4347e.tar.gz
.
-rw-r--r--examples/IPC_SAP/TLI_SAP/CPP-ATM-client.cpp126
-rw-r--r--examples/IPC_SAP/TLI_SAP/CPP-ATM-server.cpp87
-rw-r--r--examples/IPC_SAP/TLI_SAP/Makefile4
3 files changed, 216 insertions, 1 deletions
diff --git a/examples/IPC_SAP/TLI_SAP/CPP-ATM-client.cpp b/examples/IPC_SAP/TLI_SAP/CPP-ATM-client.cpp
new file mode 100644
index 00000000000..a46aefbe639
--- /dev/null
+++ b/examples/IPC_SAP/TLI_SAP/CPP-ATM-client.cpp
@@ -0,0 +1,126 @@
+// $Id$
+
+#include "ace/TLI_Connector.h"
+#include "ace/ATM_Addr.h"
+
+ACE_RCSID(TLI_SAP, CPP_ATM_client, "$Id$")
+
+#if defined (ACE_HAS_FORE_ATM_XTI)
+
+/* ACE_XTI/ATM Client */
+
+int main (int argc, char *argv[])
+{
+ if (argc < 2)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Usage: %s hostname [QoS in KB/sec] [timeout]\n",
+ argv[0]),
+ 1);
+ const char *host = argv[1];
+ int qos = argc > 2 ? ACE_OS::atoi (argv[2]) : 0;
+ int timeout = argc > 3 ? ACE_OS::atoi (argv[3]) : ACE_DEFAULT_TIMEOUT;
+
+ char buf[BUFSIZ];
+
+ ACE_TLI_Stream cli_stream;
+
+ ACE_ATM_Addr remote_addr (host);
+ char hostname[MAXNAMELEN];
+ ACE_OS::hostname(hostname, MAXNAMELEN);
+ ACE_ATM_Addr local_addr (hostname);
+
+ // In order to construct connections options the file handle is
+ // needed. Therefore, we need to open the TLI_Stream before we
+ // construct the options.
+ if (cli_stream.open (ACE_TLI_TCP_DEVICE, O_RDWR, 0) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "open failed"),
+ 1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "starting non-blocking connect\n"));
+
+ // Initiate timed, non-blocking connection with server.
+ ACE_TLI_Connector con;
+
+ // Construct QoS options - currently FORE only supports bandwidth
+ long optlen = 0;
+ char *options = ACE_ATM_Addr::construct_options (cli_stream.get_handle (),
+ qos,
+ ACE_ATM_Addr::OPT_FLAGS_CPID,
+ &optlen);
+ struct netbuf optbuf;
+ optbuf.len = optlen;
+ optbuf.buf = options;
+
+ // Not sure why but reuse_addr set to true/1 causes problems for
+ // FORE/XTI/ATM - this is now handled in
+ // ACE_TLI_Connector::connect()
+ if (con.connect (cli_stream, remote_addr,
+ (ACE_Time_Value *) &ACE_Time_Value::zero,
+ local_addr,
+ 1,
+ O_RDWR,
+ 0,
+ ACE_TLI_TCP_DEVICE,
+ 0,
+ 1,
+ 0,
+ &optbuf) == -1)
+ {
+ if (errno != EWOULDBLOCK)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "connection failed"),
+ 1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "starting timed connect\n"));
+
+ // Check if non-blocking connection is in progress, and wait up
+ // to timeout seconds for it to complete.
+ ACE_Time_Value tv (timeout);
+
+ if (con.complete (cli_stream,
+ &remote_addr,
+ &tv) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "connection failed"),
+ 1);
+ else
+ ACE_DEBUG ((LM_DEBUG,
+ "connected to %s\n",
+ remote_addr.addr_to_string ()));
+ }
+
+ // Send data to server (correctly handles "incomplete writes").
+
+ for (int r_bytes;
+ (r_bytes = ACE_OS::read (ACE_STDIN, buf, sizeof buf)) > 0;
+ )
+ if (cli_stream.send_n (buf,
+ r_bytes,
+ 0) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "send_n"),
+ 1);
+
+ // Explicitly close the connection.
+ if (cli_stream.close () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "close"),
+ -1);
+ return 0;
+}
+#else
+int main (int, char *[])
+{
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "your platform isn't configured to support XTI/ATM\n"),
+ 1);
+}
+#endif /* ACE_HAS_TLI */
diff --git a/examples/IPC_SAP/TLI_SAP/CPP-ATM-server.cpp b/examples/IPC_SAP/TLI_SAP/CPP-ATM-server.cpp
new file mode 100644
index 00000000000..8e3e13286b8
--- /dev/null
+++ b/examples/IPC_SAP/TLI_SAP/CPP-ATM-server.cpp
@@ -0,0 +1,87 @@
+// $Id$
+
+#include "ace/TLI_Acceptor.h"
+#include "ace/ATM_Addr.h"
+
+ACE_RCSID(TLI_SAP, CPP_ATM_server, "$Id$")
+
+#if defined (ACE_HAS_FORE_ATM_XTI)
+// ACE_TLI Server
+
+int
+main (int argc, char *argv[])
+{
+ ACE_Time_Value timeout (argc > 1 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_TIMEOUT);
+
+ // Create a server address.
+ ACE_ATM_Addr addr;
+
+ // Create a server, reuse the addr.
+ ACE_TLI_Acceptor peer_acceptor;
+
+ // Not sure why but reuse_addr set to true/1 causes problems for
+ // FORE/XTI/ATM - this is now handled in ACE_TLI_Acceptor::open()
+ if (peer_acceptor.open (addr, 1) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "open"),
+ -1);
+
+ ACE_TLI_Stream new_stream;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "starting server at address %s\n",
+ addr.addr_to_string ()));
+
+
+ // Performs the iterative server activities
+
+ for (;;)
+ {
+ char buf[BUFSIZ];
+
+ // Create a new ACE_TLI_Stream endpoint (note automatic restart
+ // if errno == EINTR).
+ if (peer_acceptor.accept (new_stream,
+ &addr,
+ &timeout) == -1)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "accept"));
+ continue;
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "client %s connected\n",
+ addr.addr_to_string ()));
+
+ // Read data from client (terminate on error).
+
+ for (int r_bytes;
+ (r_bytes = new_stream.recv (buf, sizeof buf)) > 0; )
+ if (ACE_OS::write (ACE_STDOUT,
+ buf,
+ r_bytes) != r_bytes)
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "ACE::send_n"));
+
+ // Close new endpoint (listening endpoint stays open).
+ if (new_stream.close () == -1)
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "close"));
+
+ }
+ /* NOTREACHED */
+ return 0;
+}
+#else
+int main (int, char *[])
+{
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "your platform isn't configured to support XTI/ATM\n"),
+ 1);
+}
+#endif /* ACE_HAS_TLI */
diff --git a/examples/IPC_SAP/TLI_SAP/Makefile b/examples/IPC_SAP/TLI_SAP/Makefile
index cd571947128..5f325491a08 100644
--- a/examples/IPC_SAP/TLI_SAP/Makefile
+++ b/examples/IPC_SAP/TLI_SAP/Makefile
@@ -13,7 +13,9 @@ BIN = ftp-client \
db-client \
db-server \
CPP-client \
- CPP-server
+ CPP-server \
+ CPP-ATM-client \
+ CPP-ATM-server
LSRC = $(addsuffix .cpp,$(BIN))