summaryrefslogtreecommitdiff
path: root/ACE/protocols/tests/HTBP/ping
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/protocols/tests/HTBP/ping')
-rw-r--r--ACE/protocols/tests/HTBP/ping/Makefile.am62
-rw-r--r--ACE/protocols/tests/HTBP/ping/client.cpp203
-rwxr-xr-xACE/protocols/tests/HTBP/ping/ping.mpc19
-rwxr-xr-xACE/protocols/tests/HTBP/ping/run_test.pl59
-rw-r--r--ACE/protocols/tests/HTBP/ping/server.cpp191
5 files changed, 534 insertions, 0 deletions
diff --git a/ACE/protocols/tests/HTBP/ping/Makefile.am b/ACE/protocols/tests/HTBP/ping/Makefile.am
new file mode 100644
index 00000000000..b59b297e535
--- /dev/null
+++ b/ACE/protocols/tests/HTBP/ping/Makefile.am
@@ -0,0 +1,62 @@
+## 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:
+## ./bin/mwc.pl -type automake -noreldefs ACE.mwc
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+noinst_PROGRAMS =
+
+## Makefile.Ping_Client.am
+
+if !BUILD_ACE_FOR_TAO
+
+noinst_PROGRAMS += client
+
+client_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -I$(ACE_ROOT)/protocols
+
+client_SOURCES = \
+ client.cpp
+
+client_LDADD = \
+ $(ACE_BUILDDIR)/protocols/ace/HTBP/libACE_HTBP.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+
+## Makefile.Ping_Server.am
+
+if !BUILD_ACE_FOR_TAO
+
+noinst_PROGRAMS += server
+
+server_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -I$(ACE_ROOT)/protocols
+
+server_SOURCES = \
+ server.cpp
+
+server_LDADD = \
+ $(ACE_BUILDDIR)/protocols/ace/HTBP/libACE_HTBP.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+
+## 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/protocols/tests/HTBP/ping/client.cpp b/ACE/protocols/tests/HTBP/ping/client.cpp
new file mode 100644
index 00000000000..481be629208
--- /dev/null
+++ b/ACE/protocols/tests/HTBP/ping/client.cpp
@@ -0,0 +1,203 @@
+/**
+ * $Id$
+ *
+ * client for a basic connection establishment test using HTBP
+ */
+
+#include "ace/ACE.h"
+#include "ace/Log_Msg.h"
+#include "ace/Get_Opt.h"
+
+#include "ace/HTBP/HTBP_Session.h"
+#include "ace/HTBP/HTBP_Stream.h"
+#include "ace/HTBP/HTBP_Addr.h"
+#include "ace/HTBP/HTBP_ID_Requestor.h"
+#include "ace/HTBP/HTBP_Environment.h"
+
+const ACE_TCHAR * remote_host = 0;
+const ACE_TCHAR * config_file = 0;
+unsigned int remote_port = 8088;
+
+int
+parse_args (int argc, ACE_TCHAR *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("p:h:c:d"));
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'p':
+ remote_port = static_cast<unsigned>(ACE_OS::atoi (get_opts.opt_arg()));
+ break;
+ case 'h':
+ remote_host = get_opts.opt_arg ();
+ break;
+ case 'c':
+ config_file = get_opts.opt_arg ();
+ break;
+ case 'd':
+ ACE::debug (true);
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("usage: %s ")
+ ACE_TEXT ("-h remote_host ")
+ ACE_TEXT ("-p remote_port ")
+ ACE_TEXT ("-c config_file ")
+ ACE_TEXT ("-d (turn on extra logging)")
+ ACE_TEXT ("\n"),
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ ACE_OS::socket_init (ACE_WSOCK_VERSION);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+ if (remote_host == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("Client: No remote host specified\n")),
+ 1);
+
+ ACE::HTBP::Environment env;
+ if (config_file != 0)
+ env.import_config (config_file);
+
+ ACE::HTBP::ID_Requestor req (&env);
+ ACE::HTBP::Addr local (ACE_TEXT_ALWAYS_CHAR (req.get_HTID ()));
+
+ unsigned int proxy_port = 0;
+ ACE_TString proxy_host;
+
+ if (env.get_proxy_port (proxy_port) != 0 ||
+ env.get_proxy_host (proxy_host) != 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT("no proxy address in ")
+ ACE_TEXT("config, using direct connect\n")));
+ proxy_port = remote_port;
+ proxy_host = remote_host;
+ }
+
+ ACE_INET_Addr proxy (proxy_port, proxy_host.c_str ());
+ ACE::HTBP::Addr remote (remote_port, ACE_TEXT_ALWAYS_CHAR (remote_host));
+ ACE_TCHAR proxy_s[MAXHOSTNAMELEN+1];
+ proxy.addr_to_string (proxy_s, MAXHOSTNAMELEN);
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: connecting to %s\n"),
+ proxy_s));
+ ACE::HTBP::Session session (remote,
+ local,
+ ACE::HTBP::Session::next_session_id (),
+ &proxy);
+ ACE::HTBP::Stream stream (&session);
+
+ char buffer[1000];
+ ssize_t n = 0;
+ int retrycount = 10;
+ for (int i = 0; i < 3; i++)
+ {
+ ACE_OS::sprintf (buffer, "Do you hear me? %d", i);
+ ACE::HTBP::Channel *ob = session.outbound ();
+ n = stream.send (buffer, ACE_OS::strlen (buffer)+1);
+ if (n == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("%p\n"),
+ ACE_TEXT("stream send")),
+ -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("send returned %b\n"),
+ n));
+
+ retrycount = 10;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("after send, outbound = %@, ob = %@\n"),
+ session.outbound (), ob));
+ while ((n = ob->recv_ack ()) == -1
+ && (errno == EWOULDBLOCK || errno == ETIME)
+ && retrycount > 0)
+ {
+ retrycount--;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("waiting for ack, %d tries left\n"),
+ retrycount));
+ ACE_OS::sleep (1);
+ }
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("After wait for ack, n = %b, retry = %d\n"),
+ n, retrycount));
+
+ retrycount = 10;
+ while ((n = stream.recv (buffer, 1000)) == -1
+ && (errno == EWOULDBLOCK || errno == ETIME)
+ && retrycount > 0)
+ {
+ retrycount--;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("waiting for inbound data, %d tries left\n"),
+ retrycount));
+ ACE_OS::sleep (1);
+ }
+ if (retrycount == 0 || n < 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("bailing after wait, %p\n"),
+ ACE_TEXT ("recv")));
+ break;
+ }
+
+ buffer[n] = 0;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: Got: \"%C\"\n"),
+ buffer));
+ }
+
+ ACE::HTBP::Channel *ob = session.outbound ();
+ n = stream.send ("goodbye", 7);
+ if (n == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) Client: %p\n"),
+ ACE_TEXT ("stream send")),
+ -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("send returned %b\n"),
+ n));
+
+ retrycount = 10;
+ while ((n = ob->recv_ack ()) == -1
+ && (errno == EWOULDBLOCK || errno == ETIME)
+ && retrycount > 0)
+ {
+ retrycount--;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("waiting for ack, %d tries left\n"),
+ retrycount));
+ ACE_OS::sleep (1);
+ }
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Client: ")
+ ACE_TEXT ("After wait for ack, n = %b, retry = %d\n"),
+ n, retrycount));
+ stream.close ();
+ return 0;
+}
diff --git a/ACE/protocols/tests/HTBP/ping/ping.mpc b/ACE/protocols/tests/HTBP/ping/ping.mpc
new file mode 100755
index 00000000000..61e59146a93
--- /dev/null
+++ b/ACE/protocols/tests/HTBP/ping/ping.mpc
@@ -0,0 +1,19 @@
+// -*- MPC -*-
+//
+// $Id$
+
+project(*Server): aceexe, htbp {
+ exename = server
+
+ Source_Files {
+ server.cpp
+ }
+}
+
+project(*Client): aceexe, htbp {
+ exename = client
+
+ Source_Files {
+ client.cpp
+ }
+}
diff --git a/ACE/protocols/tests/HTBP/ping/run_test.pl b/ACE/protocols/tests/HTBP/ping/run_test.pl
new file mode 100755
index 00000000000..b769c37757e
--- /dev/null
+++ b/ACE/protocols/tests/HTBP/ping/run_test.pl
@@ -0,0 +1,59 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib "$ENV{ACE_ROOT}/bin";
+use PerlACE::Run_Test;
+use Sys::Hostname;
+
+$status = 0;
+$host = hostname();
+$port = PerlACE::random_port();
+$synchbase = "ready";
+$synchfile = PerlACE::LocalFile ("$synchbase");
+
+print "port = $port\n";
+if (PerlACE::is_vxworks_test()) {
+ $host = $ENV{'ACE_RUN_VX_TGTHOST'};
+ $SV = new PerlACE::ProcessVX ("server", "-p $port -o $synchbase");
+}
+else {
+ $SV = new PerlACE::Process ("server", "-p $port -o $synchfile");
+}
+
+# The client code should later be modified to get the hostname
+# using ACE_OS::hostname so the same script can be run on all
+# hosts without havng to reset the host where it has to be run.
+$CL = new PerlACE::Process ("client", " -h $host -p $port");
+
+unlink $synchfile;
+
+$SV->Spawn ();
+
+if (PerlACE::waitforfile_timed ($synchfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$synchfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+unlink $synchfile;
+
+$client = $CL->SpawnWaitKill (300);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$server = $SV->WaitKill (10);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+
+exit $status;
diff --git a/ACE/protocols/tests/HTBP/ping/server.cpp b/ACE/protocols/tests/HTBP/ping/server.cpp
new file mode 100644
index 00000000000..7bde988c3cf
--- /dev/null
+++ b/ACE/protocols/tests/HTBP/ping/server.cpp
@@ -0,0 +1,191 @@
+/**
+ * server for a basic connection establishment test using HTBP
+ *
+ * $Id$
+ */
+
+#include "ace/Log_Msg.h"
+
+#include "ace/HTBP/HTBP_Session.h"
+#include "ace/HTBP/HTBP_Stream.h"
+#include "ace/HTBP/HTBP_Addr.h"
+
+#include "ace/SOCK_Acceptor.h"
+#include "ace/SOCK_Stream.h"
+#include "ace/Get_Opt.h"
+#include "ace/OS_NS_stdio.h"
+
+unsigned port = 8088;
+const ACE_TCHAR *notifier_file = 0;
+int
+parse_args (int argc, ACE_TCHAR *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:o:"));
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'o':
+ notifier_file = get_opts.opt_arg();
+ break;
+ case 'p':
+ port = static_cast<unsigned>(ACE_OS::atoi (get_opts.opt_arg()));
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-p port "
+ "\n",
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+int
+ACE_TMAIN (int argc , ACE_TCHAR *argv[])
+{
+ char buffer[1000];
+ ssize_t n = 0;
+ ACE_OS::socket_init (ACE_WSOCK_VERSION);
+
+ if (parse_args(argc, argv) != 0)
+ return 1;
+
+ ACE_TCHAR host[MAXHOSTNAMELEN+1];
+ if (ACE_OS::hostname (host, MAXHOSTNAMELEN) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("(%P|%t) Server failure: %p\n"),
+ ACE_TEXT ("hostname")),
+ 1);
+
+ ACE_INET_Addr local (port, host);
+ ACE_SOCK_Stream sock[2];
+ ACE_SOCK_Acceptor acc(local, 1);
+ local.addr_to_string (host, MAXHOSTNAMELEN);
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server is ready on %s\n"),
+ host));
+ if (notifier_file != 0)
+ {
+ FILE *f = ACE_OS::fopen (notifier_file,ACE_TEXT("w+"));
+ const char *msg = "server ready";
+ ACE_OS::fwrite (msg,ACE_OS::strlen(msg),1,f);
+ ACE_OS::fclose (f);
+ }
+ acc.accept (sock[0]);
+ ACE::HTBP::Channel channel1(sock[0]);
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("Got sock[0], handle = %d\n"),
+ sock[0].get_handle()));
+ acc.accept (sock[1]);
+ ACE::HTBP::Channel channel2 (sock[1]);
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("Got sock[1], handle = %d\n"),
+ sock[1].get_handle()));
+ int res = 0;
+ while ((res = channel1.pre_recv ()) != 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("res = %d. waiting 1 sec. %p\n"),
+ res,
+ ACE_TEXT ("stream.pre_recv()")));
+ ACE_OS::sleep (1);
+ }
+
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Read from channel2\n")));
+ while ((res = channel2.pre_recv()) != 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("res = %d, waiting 1 sec. %p\n"),
+ res,
+ ACE_TEXT ("stream2.pre_recv()")));
+ ACE_OS::sleep (1);
+ }
+
+ ACE::HTBP::Session *session = channel1.session();
+ ACE::HTBP::Stream stream (session);
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("using streams %d, %d. Got sesssion = %@\n"),
+ sock[0].get_handle(),
+ sock[1].get_handle(),
+ session));
+
+ for (int i = 0; i >= 0; i++)
+ {
+ int retrycount = 10;
+ while ((n = stream.recv(buffer,1000)) == -1
+ && (errno == EWOULDBLOCK || errno == ETIME)
+ && retrycount > 0)
+ {
+ retrycount--;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("waiting for inbound data, %d tries left\n"),
+ retrycount));
+ ACE_OS::sleep(1);
+ }
+ if (retrycount == 0 || n < 0)
+ break;
+
+ buffer[n] = 0;
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("Got: \"%C\"\n"), buffer));
+
+ if (ACE_OS::strstr (buffer,"goodbye") != 0)
+ break;
+
+ ACE_OS::sprintf (buffer,"I hear you %d",i);
+ n = stream.send (buffer,ACE_OS::strlen(buffer)+1);
+ if (n == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
+ ACE_TEXT ("stream.send")),
+ -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: Send returned %d\n"), n));
+
+ int got[2] = {-1,-1};
+ while (got[0] == -1 || got[1] == -1)
+ {
+ if (got[0] == -1)
+ {
+ if ((got[0] = (res =channel1.pre_recv())) == -1)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("res = %d, waiting 1 sec. %p\n"),
+ got[0],
+ ACE_TEXT ("channel1.pre_recv()")));
+ }
+ if (got[1] == -1)
+ {
+ if ((got[1] = (res =channel2.pre_recv())) == -1)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%P|%t) Server: ")
+ ACE_TEXT ("res = %d, waiting 1 sec. %p\n"),
+ got[1],
+ ACE_TEXT ("channel2.pre_recv()")));
+ }
+ if (got[0] == -1 || got[1] == -1)
+ ACE_OS::sleep (1);
+ }
+ }
+ ACE_OS::sleep(1); // prevent test failure on windows when the connection
+ // closes too fast.
+
+ stream.close();
+ acc.close();
+
+ return 0;
+}