diff options
author | joeh <joeh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-02 23:34:23 +0000 |
---|---|---|
committer | joeh <joeh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-02 23:34:23 +0000 |
commit | 78380acd0bb8175d147832e6c39a4cafc07460b3 (patch) | |
tree | 0c11f44dfbff1db3b70789181d562022aa6babeb /examples | |
parent | beb5a05dd94e35adcf3a8bd301156bfda7d8aea1 (diff) | |
download | ATCD-78380acd0bb8175d147832e6c39a4cafc07460b3.tar.gz |
Adding new test directory for ATM wrapper classes
Diffstat (limited to 'examples')
-rw-r--r-- | examples/IPC_SAP/ATM_SAP/CPP-client.cpp | 146 | ||||
-rw-r--r-- | examples/IPC_SAP/ATM_SAP/CPP-server.cpp | 113 | ||||
-rw-r--r-- | examples/IPC_SAP/ATM_SAP/Makefile | 45 |
3 files changed, 304 insertions, 0 deletions
diff --git a/examples/IPC_SAP/ATM_SAP/CPP-client.cpp b/examples/IPC_SAP/ATM_SAP/CPP-client.cpp new file mode 100644 index 00000000000..71eca9f9790 --- /dev/null +++ b/examples/IPC_SAP/ATM_SAP/CPP-client.cpp @@ -0,0 +1,146 @@ +// $Id$ + +#include "ace/ATM_Connector.h" +#include "ace/ATM_Addr.h" + +ACE_RCSID(ATM_SAP, CPP_client, "$Id$") + +#if defined (ACE_HAS_ATM) + +/* ACE_ATM Client */ + +int main (int argc, char *argv[]) +{ + if (argc < 2) + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s [-s selector] hostname [QoS in KB/sec]\n", + argv[0]), + 1); + + unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR; + int selector_specified = 0; + extern int optind; + int opt; + while ((opt = ACE_OS::getopt (argc, argv, "s:?h")) != EOF) + { + switch(opt) + { + case 's': + selector = ACE_OS::atoi (optarg); + selector_specified = 1; + break; + case '?': + case 'h': + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s hostname [-s selector] [QoS in KB/s]\n", + argv[0]), + 1); + } // switch + } // while getopt + + const char *host = argv[optind]; + + int rate = (argc == 3) ? ACE_OS::atoi (argv[2]) : + (argc == 5) ? ACE_OS::atoi (argv[4]) : 0; + // The timeout really gets ignored since FORE's drivers don't work when + // ioctl or fcntl calls are made on the transport id/file descriptor + int timeout = ACE_DEFAULT_TIMEOUT; + + char buf[BUFSIZ]; + + ACE_ATM_Stream atm_stream; + + ACE_ATM_Addr remote_addr (host); + if (selector_specified) + remote_addr.set_selector(selector); + 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 ATM_Stream before we + // construct the options. + if (atm_stream.open () == -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_ATM_Connector con; + + // Construct QoS options - currently FORE only supports bandwidth + ACE_ATM_QoS qos; + qos.set_rate(atm_stream.get_handle (), + rate, + ACE_ATM_QoS::OPT_FLAGS_CPID); + + struct netbuf optbuf = qos.get_qos(); + + // Not sure why but reuse_addr set to true/1 causes problems for + // FORE/XTI/ATM - this is now handled in ACE_ATM_Connector::connect() + if (con.connect (atm_stream, + remote_addr, + ACE_ATM_Params(), + qos, + (ACE_Time_Value *) &ACE_Time_Value::zero, + local_addr) == -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 (atm_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 (atm_stream.send_n (buf, + r_bytes, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send_n"), + 1); + + // Explicitly close the connection. + if (atm_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 ATM\n"), + 1); +} +#endif /* ACE_HAS_ATM */ diff --git a/examples/IPC_SAP/ATM_SAP/CPP-server.cpp b/examples/IPC_SAP/ATM_SAP/CPP-server.cpp new file mode 100644 index 00000000000..5615ecf133f --- /dev/null +++ b/examples/IPC_SAP/ATM_SAP/CPP-server.cpp @@ -0,0 +1,113 @@ +// $Id$ + +#include "ace/ATM_Acceptor.h" +#include "ace/ATM_Addr.h" + +ACE_RCSID(ATM_SAP, CPP_ATM_server, "$Id$") + +#if defined (ACE_HAS_ATM) +// ACE_ATM Server + +int +main (int argc, char *argv[]) +{ + ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT); + + unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR; + int selector_specified = 0; + int opt; + while ((opt = ACE_OS::getopt (argc, argv, "s:?h")) != EOF) + { + switch(opt) + { + case 's': + selector = ACE_OS::atoi (optarg); + selector_specified = 1; + break; + case '?': + case 'h': + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s [-s selector]\n", argv[0]), + 1); + } // switch + } // while getopt + + // Create a server address. + ACE_ATM_Addr addr; + if (selector_specified) + addr.set_selector(selector); + + // Create a server, reuse the addr. + ACE_ATM_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_ATM_Acceptor::open() + if (peer_acceptor.open (addr, + 5) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "open"), + -1); + + ACE_ATM_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_ATM_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 ())); + + ACE_DEBUG ((LM_DEBUG, + "client %s connected to host\n", + new_stream.get_peer_name ())); + + // Read data from client (terminate on error). + + for (int r_bytes; + (r_bytes = new_stream.recv (buf, sizeof buf, 0)) > 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 ATM\n"), + 1); +} +#endif /* ACE_HAS_ATM */ diff --git a/examples/IPC_SAP/ATM_SAP/Makefile b/examples/IPC_SAP/ATM_SAP/Makefile new file mode 100644 index 00000000000..818496c114d --- /dev/null +++ b/examples/IPC_SAP/ATM_SAP/Makefile @@ -0,0 +1,45 @@ +#---------------------------------------------------------------------------- +# $Id$ +# +# Makefile for ATM_SAP test +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = CPP-client \ + CPP-server + +LSRC = $(addsuffix .cpp,$(BIN)) + +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +BUILD = $(VBIN) + +INSTALL = + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +LDFLAGS += -R$(FORE_ROOT)/lib -L$(FORE_ROOT)/lib +LIBS += -lans -lpmp +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU +include $(ACE_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. + |