diff options
Diffstat (limited to 'ACE/examples/Service_Configurator/IPC-tests/client')
19 files changed, 1500 insertions, 0 deletions
diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/.cvsignore b/ACE/examples/Service_Configurator/IPC-tests/client/.cvsignore new file mode 100644 index 00000000000..121d4de020f --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/.cvsignore @@ -0,0 +1,10 @@ +local_dgram_test +local_fifo_test +local_pipe_test +local_spipe_test +local_stream_test +remote_broadcast_test +remote_dgram_test +remote_service_directory_test +remote_stream_test +remote_thr_stream_test diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/Makefile.am b/ACE/examples/Service_Configurator/IPC-tests/client/Makefile.am new file mode 100644 index 00000000000..b6dd5a3d7b8 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/Makefile.am @@ -0,0 +1,180 @@ +## 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) + +noinst_PROGRAMS = + +## Makefile.Svc_Cfg_IPC_Client_Bcast.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += remote_broadcast_test + +remote_broadcast_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +remote_broadcast_test_SOURCES = \ + broadcast_client_test.cpp + +remote_broadcast_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Loc_Dgram.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += local_dgram_test + +local_dgram_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +local_dgram_test_SOURCES = \ + local_dgram_client_test.cpp + +local_dgram_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Loc_Fifo.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += local_fifo_test + +local_fifo_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +local_fifo_test_SOURCES = \ + local_fifo_client_test.cpp + +local_fifo_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Loc_Pipe.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += local_pipe_test + +local_pipe_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +local_pipe_test_SOURCES = \ + local_pipe_client_test.cpp + +local_pipe_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Loc_Spipe.am +noinst_PROGRAMS += local_spipe_test + +local_spipe_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +local_spipe_test_SOURCES = \ + local_spipe_client_test.cpp + +local_spipe_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +## Makefile.Svc_Cfg_IPC_Client_Loc_Stream.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += local_stream_test + +local_stream_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +local_stream_test_SOURCES = \ + local_stream_client_test.cpp + +local_stream_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Rem_Dgram.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += remote_dgram_test + +remote_dgram_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +remote_dgram_test_SOURCES = \ + remote_dgram_client_test.cpp + +remote_dgram_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Rem_Stream.am + +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += remote_stream_test + +remote_stream_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +remote_stream_test_SOURCES = \ + remote_stream_client_test.cpp + +remote_stream_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Client_Rem_Svc_Dir.am +noinst_PROGRAMS += remote_service_directory_test + +remote_service_directory_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +remote_service_directory_test_SOURCES = \ + remote_service_directory_test.cpp + +remote_service_directory_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +## Makefile.Svc_Cfg_IPC_Client_Rem_Thr_Stream.am +noinst_PROGRAMS += remote_thr_stream_test + +remote_thr_stream_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +remote_thr_stream_test_SOURCES = \ + remote_thr_stream_client_test.cpp + +remote_thr_stream_test_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +## 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/Service_Configurator/IPC-tests/client/Svc_Cfg_IPC_Client.mpc b/ACE/examples/Service_Configurator/IPC-tests/client/Svc_Cfg_IPC_Client.mpc new file mode 100644 index 00000000000..6876c4aac4d --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/Svc_Cfg_IPC_Client.mpc @@ -0,0 +1,70 @@ +// -*- MPC -*- +// $Id$ + +project(*loc dgram) : aceexe { + avoids += ace_for_tao + exename = local_dgram_test + Source_Files { + local_dgram_client_test.cpp + } +} +project(*loc fifo) : aceexe { + avoids += ace_for_tao + exename = local_fifo_test + Source_Files { + local_fifo_client_test.cpp + } +} +project(*loc pipe) : aceexe { + avoids += ace_for_tao + exename = local_pipe_test + Source_Files { + local_pipe_client_test.cpp + } +} +project(*loc spipe) : aceexe { + exename = local_spipe_test + Source_Files { + local_spipe_client_test.cpp + } +} +project(*loc stream) : aceexe { + avoids += ace_for_tao + exename = local_stream_test + Source_Files { + local_stream_client_test.cpp + } +} +project(*rem dgram) : aceexe { + avoids += ace_for_tao + exename = remote_dgram_test + Source_Files { + remote_dgram_client_test.cpp + } +} +project(*rem svc dir) : aceexe { + exename = remote_service_directory_test + Source_Files { + remote_service_directory_test.cpp + } +} +project(*rem stream) : aceexe { + avoids += ace_for_tao + exename = remote_stream_test + Source_Files { + remote_stream_client_test.cpp + } +} +project(*rem thr_stream) : aceexe { + exename = remote_thr_stream_test + Source_Files { + remote_thr_stream_client_test.cpp + } +} +project(*bcast) : aceexe { + avoids += ace_for_tao + exename = remote_broadcast_test + Source_Files { + broadcast_client_test.cpp + } +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/broadcast_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/broadcast_client_test.cpp new file mode 100644 index 00000000000..4cbb964cd74 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/broadcast_client_test.cpp @@ -0,0 +1,62 @@ +// $Id$ + +// Tests out the broadcast service of the +// Internet domain IPC-SAP dgram abstraction. + +#include "ace/OS_main.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/INET_Addr.h" +#include "ace/SOCK_Dgram_Bcast.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, broadcast_client_test, "$Id$") + +/* Name of the program. */ +static ACE_TCHAR *program_name; + +/* Port number to use. */ +static unsigned short broadcast_port_number = ACE_DEFAULT_BROADCAST_PORT; + +static void +print_usage_and_die (void) +{ + ACE_OS::fprintf (stderr, "usage: %s [-p broadcast portnum]\n", + program_name); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'p': + broadcast_port_number = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + parse_args (argc, argv); + + ACE_SOCK_Dgram_Bcast sd (ACE_Addr::sap_any); + + static char buf[] = "testing socket broadcast service"; + + if (sd.send (buf, ACE_OS::strlen (buf), broadcast_port_number) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "can't send broadcast"), -1); + + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_data b/ACE/examples/Service_Configurator/IPC-tests/client/local_data new file mode 100644 index 00000000000..1faba1b8091 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_data @@ -0,0 +1,22 @@ +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal +locallocallocallocallocallocallocallocal diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_dgram_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/local_dgram_client_test.cpp new file mode 100644 index 00000000000..3f8ed3db866 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_dgram_client_test.cpp @@ -0,0 +1,117 @@ +// $Id$ + +// Tests out the UNIX domain IPC-SAP abstraction. + +#include "ace/OS_main.h" +#include "ace/LSOCK_CODgram.h" +#include "ace/LSOCK_Dgram.h" +#include "ace/UNIX_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_fcntl.h" + +ACE_RCSID(client, local_dgram_client_test, "$Id$") + +#if defined (ACE_HAS_MSG) && !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) +// Name of the program. +static ACE_TCHAR *program_name; + +// Name of rendezvous point. +static const ACE_TCHAR *rendezvous_codgram = ACE_TEXT ("/tmp/foo_codgram"); +static const ACE_TCHAR *rendezvous_dgram = ACE_TEXT ("/tmp/foo_dgram"); + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT ("local_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("usage: %s [-r rendezvous_dgram] ") + ACE_TEXT ("[-c rendezvous_codgram] [-f file]\n"), + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("c:f:r:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'r': + rendezvous_dgram = get_opt.opt_arg (); + break; + case 'c': + rendezvous_codgram = get_opt.opt_arg (); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + + parse_args (argc, argv); + + char *sock_client = ACE_OS::tempnam (); + + ACE_LSOCK_Dgram sd ((ACE_UNIX_Addr) (sock_client)); + if (ACE_OS::unlink (sock_client)) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("unlink")), + -1); + ACE_OS::free ((void *) sock_client); + + ACE_LSOCK_CODgram sc; + + if (sc.open (ACE_UNIX_Addr (rendezvous_codgram), + ACE_Addr::sap_any) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), + -1); + + ACE_HANDLE handle = ACE_OS::open (file_name, O_RDONLY); + + if (handle == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), + -1); + + // Send the open file descriptor to the server! + + if (sc.send_handle (handle) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send")), + -1); + + char name[ACE_MAX_USERID]; + ACE_OS::cuserid (name); + + if (sd.send (name, + ACE_OS::strlen (name) + 1, + ACE_UNIX_Addr (rendezvous_dgram)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send")), + -1); + + if (ACE_OS::close (handle) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("close")), + -1); + return 0; +} +#else +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("your platform must support sendmsg/recvmsg to run this test\n")), + -1); +} +#endif /* ACE_HAS_MSG */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_fifo_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/local_fifo_client_test.cpp new file mode 100644 index 00000000000..9fb26b4088e --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_fifo_client_test.cpp @@ -0,0 +1,101 @@ +// $Id$ + +// Send a file through ACE_FIFO communication channel by +// breaking it (the file) into pieces. + +#include "ace/OS_main.h" +#include "ace/Mem_Map.h" +#include "ace/FIFO_Send_Msg.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_stropts.h" + +ACE_RCSID(client, local_fifo_client_test, "$Id$") + +// Name of the program. +static ACE_TCHAR *program_name; + +// debug state on or off +static int debug = 0; + +static const ACE_TCHAR *rendezvous_fifo = ACE_TEXT("/tmp/foo_fifo"); + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT("./local_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + "usage: %s [-d] [-f rendezvous_fifo]\n", + program_name)); + ACE_OS::exit (1); +} + +static void +parse_arguments (int argc, ACE_TCHAR *argv[]) +{ + int tracing = 1; + program_name = argv[0]; + + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("df:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'd': + debug = 1; + break; + case 'f': + rendezvous_fifo = get_opt.opt_arg (); + break; + default: + print_usage_and_die (); + break; + } + + if (debug) + ACE_DEBUG ((LM_DEBUG, + "rendezvous_fifo = %s\n" + "trace = %s\n", + rendezvous_fifo, + tracing ? "on" : "off")); +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + parse_arguments (argc, argv); + + ACE_FIFO_Send_Msg fifo; + + if (fifo.open (rendezvous_fifo, + O_WRONLY, + 0666) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open %s for requesting a new communication channel" + "in local_fifo_client_test\n", + rendezvous_fifo), + -1); + void *cp = 0; + ACE_Mem_Map mmap (file_name); + + if (mmap (cp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "mmap"), + -1); + + // Next, send the file's contents. + + ACE_Str_Buf msg (cp, + int (mmap.size ())); + + if (fifo.send (msg) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send"), + -1); + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_pipe_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/local_pipe_client_test.cpp new file mode 100644 index 00000000000..7193440b440 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_pipe_client_test.cpp @@ -0,0 +1,150 @@ +// $Id$ + +// Another test of UNIX domain IPC-SAP abstraction. This one opens 2 +// pipes and then ships certain ends over to the server to act as a +// filter! + +#include "ace/OS_main.h" +#include "ace/LSOCK_Connector.h" +#include "ace/UNIX_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_fcntl.h" + +ACE_RCSID(client, local_pipe_client_test, "$Id$") + +#if defined (ACE_HAS_MSG) && !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) +// Name of the program. +static ACE_TCHAR *program_name; + +// Name of rendezvous point. +static const ACE_TCHAR *rendezvous = ACE_TEXT ("/tmp/foo_pipe"); + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT ("local_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("usage: %s [-r rendezvous] [-f file]\n"), + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("f:r:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'r': + rendezvous = get_opt.opt_arg (); + break; + default: + print_usage_and_die (); + break; + } +} + +static int +do_client_processing (ACE_LSOCK_Stream &sc) +{ + ACE_HANDLE fd_read[2]; + ACE_HANDLE fd_write[2]; + char buf[BUFSIZ]; + int n; + + if (ACE_OS::pipe (fd_read) == -1 || ACE_OS::pipe (fd_write) == -1) + return -1; + + if (sc.send_handle (fd_write[0]) == -1 || sc.send_handle (fd_read[1]) == -1) + return -1; + + // Close off the ends we aren't interested in. + + if (ACE_OS::close (fd_read[1]) || ACE_OS::close (fd_write[0]) == -1) + return -1; + + // Do a silly dup just for fun... + + ACE_HANDLE fd1 = ACE_OS::open (file_name, O_RDONLY); + + if (fd1 == ACE_INVALID_HANDLE) + return -1; + + while ((n = ACE_OS::read (fd1, buf, sizeof buf)) > 0) + { + if (ACE_OS::write (fd_write[1], + buf, + n) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("write")), + -1); + if ((n = ACE_OS::read (fd_read[0], + buf, + sizeof buf)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("read")), + -1); + if (ACE_OS::write (ACE_STDOUT, + buf, + n) == -1) + return -1; + } + + if (ACE_OS::close (fd_read[0]) == -1 + || ACE_OS::close (fd_write[1]) == -1 + || ACE_OS::close (fd1) == -1) + ACE_OS::exit (1); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + parse_args (argc, argv); + + ACE_LSOCK_Stream sc; + ACE_LSOCK_Connector con; + + if (con.connect (sc, + ACE_UNIX_Addr (rendezvous)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("connect")), + -1); + + if (do_client_processing (sc) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("do_client_processing")), + -1); + + if (sc.close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("close")), + -1); + + return 0; +} +#else +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("your platform must support sendmsg/recvmsg to run this test\n")), + -1); +} +#endif /* ACE_HAS_MSG */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_spipe_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/local_spipe_client_test.cpp new file mode 100644 index 00000000000..91d81338ea1 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_spipe_client_test.cpp @@ -0,0 +1,106 @@ +// $Id$ + +// Send a file through ACE_SPIPE communication channel by +// breaking it (the file) into pieces. + +#include "ace/OS_main.h" +#include "ace/Mem_Map.h" +#include "ace/SPIPE_Connector.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, local_spipe_client_test, "$Id$") + +#if defined (ACE_HAS_STREAM_PIPES) + +static ACE_TCHAR *program_name; + +// debug state on or off +static int debug = 0; + +static const ACE_TCHAR *rendezvous_spipe = ACE_TEXT ("/tmp/foo_spipe"); + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT ("./local_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("usage: %s [-d] [-r rendezvous_spipe]\n"), + program_name)); + ACE_OS::exit (1); +} + +static void +parse_arguments (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dr:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'd': + debug = 1; + break; + case 'r': + rendezvous_spipe = get_opt.opt_arg (); + break; + default: + print_usage_and_die (); + break; + } + if (debug) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("rendezvous_spipe = %s\n"), + rendezvous_spipe)); +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + parse_arguments (argc, argv); + + ACE_SPIPE_Stream spipe; + ACE_SPIPE_Connector con; + + if (con.connect (spipe, + ACE_SPIPE_Addr (rendezvous_spipe)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Cannot open %s for requesting a new ") + ACE_TEXT ("communication channel in %p\n"), + rendezvous_spipe, + ACE_TEXT ("local_spipe_client_test")), + -1); + + ACE_Mem_Map mmap (file_name); + void *cp; + + if (mmap (cp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("mmap")), + -1); + + // Next, send the file's contents. + + ACE_Str_Buf msg (cp, int (mmap.size ())); + + if (spipe.send ((ACE_Str_Buf *) 0, &msg) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("send")), + -1); + return 0; +} +#else +#include <stdio.h> +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("This feature is not supported\n")), + -1); +} +#endif /* ACE_HAS_STREAM_PIPES */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/local_stream_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/local_stream_client_test.cpp new file mode 100644 index 00000000000..390b14e19b8 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/local_stream_client_test.cpp @@ -0,0 +1,113 @@ +// $Id$ + +// Tests out the UNIX domain IPC-SAP abstraction. + +#include "ace/OS_main.h" +#include "ace/LSOCK_Connector.h" +#include "ace/UNIX_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_fcntl.h" + +ACE_RCSID(client, local_stream_client_test, "$Id$") + +#if defined (ACE_HAS_MSG) && !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) +// Name of the program. +static ACE_TCHAR *program_name; + +// Name of rendezvous point. +static const ACE_TCHAR *rendezvous = ACE_TEXT ("/tmp/foo_stream"); + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT ("local_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("usage: %s [-r rendezvous] [-f file]\n"), + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("f:r:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'r': + rendezvous = get_opt.opt_arg (); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + parse_args (argc, argv); + + int fd; + char buf[BUFSIZ]; + int n; + + ACE_LSOCK_Stream sc; + ACE_LSOCK_Connector con; + + if (con.connect (sc, + ACE_UNIX_Addr (rendezvous)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("connect")), + -1); + + if ((fd = ACE_OS::open (file_name, + O_RDONLY)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("open")), + -1); + + // Send the open file descriptor to the server! + + if (sc.send_handle (fd) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("send_handle")), + -1); + + if ((n = sc.recv_n (buf, + sizeof buf)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("recv")), + -1); + else + ACE_OS::write (ACE_STDOUT, buf, n); + + if (ACE_OS::close (fd) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("close")), + -1); + + return 0; +} +#else +int ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("your platform must support sendmsg/recvmsg to run this test\n")), + -1); +} +#endif /* ACE_HAS_MSG */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_data b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data new file mode 100644 index 00000000000..ae7e1fbb88e --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data @@ -0,0 +1,22 @@ +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote +remoteremoteremoteremoteremoteremoteremoteremote diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_data1 b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data1 new file mode 100644 index 00000000000..6faaee46729 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data1 @@ -0,0 +1,22 @@ +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 +remote1remote1remote1remote1remote1remote1remote1remote1 diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_data2 b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data2 new file mode 100644 index 00000000000..ae6bf12d49f --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data2 @@ -0,0 +1,22 @@ +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 +remote2remote2remote2remote2remote2remote2remote2remote2 diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_data3 b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data3 new file mode 100644 index 00000000000..7f2ec1aa81b --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data3 @@ -0,0 +1,22 @@ +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 +remote3remote3remote3remote3remote3remote3remote3remote3 diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_data4 b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data4 new file mode 100644 index 00000000000..6c5a9633d56 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_data4 @@ -0,0 +1,22 @@ +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 +remote4remote4remote4remote4remote4remote4remote4remote4 diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_dgram_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/remote_dgram_client_test.cpp new file mode 100644 index 00000000000..e5bec64d8c6 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_dgram_client_test.cpp @@ -0,0 +1,92 @@ +// $Id$ + +// Tests out the Internet domain IPC-SAP dgram abstraction. + +#include "ace/OS_main.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/Mem_Map.h" +#include "ace/SOCK_Dgram.h" +#include "ace/INET_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, remote_dgram_client_test, "$Id$") + +// Name of the program. +static const ACE_TCHAR *program_name; + +// Port number to use. +static u_short port_number = ACE_DEFAULT_SERVER_PORT; + +// Name of remote host. +static const ACE_TCHAR *host_name = ACE_DEFAULT_SERVER_HOST; + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT("./remote_data"); + +static void print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + "usage: %s [-p portnum] [-h host_name] [-f file]\n", + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("f:h:p:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'h': + host_name = get_opt.opt_arg (); + break; + case 'p': + port_number = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + parse_args (argc, argv); + + ACE_SOCK_Dgram sd (ACE_Addr::sap_any); + void *cp = 0; + ACE_INET_Addr sa (port_number, host_name); + + ACE_Mem_Map mmap (file_name); + + if (mmap (cp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "mmap"), + -1); + + // Next, send the file's contents. + + ssize_t cc = sd.send (cp, mmap.size (), sa); + + if (cc == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send"), + -1); + else if (cc != (ssize_t) mmap.size ()) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "Not all the contents of mmap file are sent."), + -1); + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_service_directory_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/remote_service_directory_test.cpp new file mode 100644 index 00000000000..cee8ca1469f --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_service_directory_test.cpp @@ -0,0 +1,111 @@ +// $Id$ + +// Test program for the INET IPC-SAPs... + +#include "ace/OS_main.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_string.h" +#include "ace/SOCK_Connector.h" +#include "ace/INET_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, remote_service_directory_test, "$Id$") + +// Port number to use. +static unsigned short port_number = ACE_DEFAULT_SERVICE_PORT; + +// Name of remote host. +static const ACE_TCHAR *host_name = ACE_DEFAULT_SERVER_HOST; + +// Trigger a remote reconfiguration. +static int remote_reconfigure = 0; + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + "usage: %n [-p portnum] [-h host_name] [-r]\n")); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:h:r")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'h': + host_name = get_opt.opt_arg (); + break; + case 'p': + port_number = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'r': + remote_reconfigure = 1; + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + ACE_LOG_MSG->open (argv[0]); + + parse_args (argc, argv); + // Default is to ask the server for ``help.'' + static char buf[BUFSIZ] = "help\n"; + int n; + ACE_SOCK_Stream sc; + ACE_SOCK_Connector con; + + if (con.connect (sc, + ACE_INET_Addr (port_number, + host_name)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n%a", + "connect", + 1), + -1); + + if (remote_reconfigure) + // Remotely instruct the server to reconfigure itself. + ACE_OS::strcpy (buf, "reconfigure\n"); + + // Send the command. + + if (sc.send_n (buf, + ACE_OS::strlen (buf) + 1) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n%a", + "send", + 1), -1); + + // Next, read the response. + + while ((n = sc.recv (buf, + sizeof buf)) > 0) + if (ACE_OS::write (ACE_STDOUT, + buf, + n) != n) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n%a", + "write", + 1), + -1); + + if (sc.close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n%a", + "close", + 1), + -1); + + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_stream_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/remote_stream_client_test.cpp new file mode 100644 index 00000000000..d7d4ef7346c --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_stream_client_test.cpp @@ -0,0 +1,134 @@ +// $Id$ + +// Test program for the INET IPC-SAPs... + +#include "ace/OS_main.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" +#include "ace/Mem_Map.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_CODgram.h" +#include "ace/INET_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, remote_stream_client_test, "$Id$") + +// Name of the program. +static const ACE_TCHAR *program_name; + +// Port number to use. +static u_short port_number = ACE_DEFAULT_SERVER_PORT; + +// Name of remote host. +static const ACE_TCHAR *host_name = ACE_DEFAULT_SERVER_HOST; + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT("./remote_data"); + +static void +print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + "usage: %s [-p portnum] [-h host_name] [-f file]\n", + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("f:h:p:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'h': + host_name = get_opt.opt_arg (); + break; + case 'p': + port_number = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + parse_args (argc, argv); + ACE_INET_Addr sa (port_number, host_name); + void *cp = 0; + char buf[BUFSIZ]; + int n; + ACE_SOCK_CODgram dc; + + if (dc.open (sa, ACE_Addr::sap_any) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "open"), + -1); + + // First send the name of the file as a datagram. + + iovec iov[2]; + + iov[0].iov_base = (char *) "filename: "; + iov[0].iov_len = 11; + iov[1].iov_base = (char *) file_name; + iov[1].iov_len = ACE_OS::strlen (file_name); + + if (dc.send (iov, 2) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send"), + -1); + + ACE_SOCK_Stream sc; + ACE_SOCK_Connector con; + + if (con.connect (sc, sa) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "connect"), + -1); + + ACE_Mem_Map mmap (file_name); + + if (mmap (cp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "mmap"), + -1); + + // Next, send the file's contents. + + if (sc.send_n (cp, mmap.size ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "send_urg"), + -1); + + if (sc.close_writer () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "close_writer"), + -1); + + if ((n = sc.recv_n (buf, sizeof buf)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "recv"), + -1); + else + ACE_OS::write (ACE_STDOUT, buf, n); + + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/client/remote_thr_stream_client_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/client/remote_thr_stream_client_test.cpp new file mode 100644 index 00000000000..113c809069d --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/client/remote_thr_stream_client_test.cpp @@ -0,0 +1,122 @@ +// $Id$ + +// Test program for the INET ACE_TLI-SAPs... + +#include "ace/OS_main.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/Mem_Map.h" +#include "ace/TLI_Connector.h" +#include "ace/INET_Addr.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" + +ACE_RCSID(client, remote_thr_stream_client_test, "$Id$") + +#if defined (ACE_HAS_TLI) + +// Name of the program. +static const ACE_TCHAR *program_name; + +// Port number to use. +static u_short port_number = ACE_DEFAULT_THR_PORT; + +// Name of remote host. +static const ACE_TCHAR *host_name = ACE_DEFAULT_SERVER_HOST; + +// Name of file to send. +static const ACE_TCHAR *file_name = ACE_TEXT ("./remote_data"); + +static void print_usage_and_die (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("usage: %s [-p portnum] [-h host_name] [-f file]\n"), + program_name)); + ACE_OS::exit (1); +} + +void +parse_args (int argc, ACE_TCHAR *argv[]) +{ + program_name = argv[0]; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("f:h:p:")); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'f': + file_name = get_opt.opt_arg (); + break; + case 'h': + host_name = get_opt.opt_arg (); + break; + case 'p': + port_number = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + print_usage_and_die (); + break; + } +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + parse_args (argc, argv); + void *cp; + char buf[BUFSIZ]; + ACE_TLI_Stream sc; + ACE_TLI_Connector con; + + if (con.connect (sc, + ACE_INET_Addr (port_number, + host_name)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("open")), + -1); + + ACE_Mem_Map mmap (file_name, PROT_READ); + + if (mmap (cp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("mmap")), -1); + + // Next, send the file's contents. + + if (sc.send_n (cp, mmap.size ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("send_n")), + -1); + + if (sc.sndrel () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("close_writer")), + -1); + + for (int n; (n = sc.recv (buf, sizeof buf)) > 0; ) + if (ACE_OS::write (ACE_STDOUT, buf, n) != n) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("write")), + -1); + + if (sc.close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("close")), + -1); + return 0; +} +#else +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("you must have TLI to run this test\n")), + 1); +} +#endif /* ACE_HAS_TLI */ |