diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
commit | 99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch) | |
tree | bda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/examples/Service_Configurator/IPC-tests/server | |
parent | c4078c377d74290ebe4e66da0b4975da91732376 (diff) | |
download | ATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz |
undoing accidental deletion
Diffstat (limited to 'ACE/examples/Service_Configurator/IPC-tests/server')
36 files changed, 2501 insertions, 0 deletions
diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.cpp new file mode 100644 index 00000000000..d81213805cd --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.cpp @@ -0,0 +1,38 @@ +// $Id$ + +#include "Handle_Broadcast.h" + +ACE_RCSID(server, Handle_Broadcast, "$Id$") + +#if defined (SunOS4) +extern "C" +{ + int init (void); + int fini (void); + void __sti__Handle_Broadcast_C_init_(); + void __std__Handle_Broadcast_C_init_(); +} + +int +init (void) +{ + __sti__Handle_Broadcast_C_init_(); + return 0; +} + +int +fini (void) +{ + __std__Handle_Broadcast_C_init_(); + return 0; +} +#endif /* SunOS4 */ + +unsigned short Handle_Broadcast::DEFAULT_PORT = ACE_DEFAULT_BROADCAST_PORT; + +#if !defined (__ACE_INLINE__) +#include "Handle_Broadcast.inl" +#endif /* __ACE_INLINE__ */ + +Handle_Broadcast remote_broadcast; +ACE_Service_Object_Type rb (&remote_broadcast, ACE_TEXT("Remote_Brdcast")); diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.h new file mode 100644 index 00000000000..39c115b8c46 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +// +// $Id$ + +/* Handles INET broadcast datagram messages from remote hosts on the local subnet. */ + +#ifndef _HANDLE_BROADCAST_H +#define _HANDLE_BROADCAST_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/INET_Addr.h" +#include "ace/SOCK_Dgram.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +class ACE_Svc_Export Handle_Broadcast : public ACE_Service_Object, public ACE_SOCK_Dgram +{ +public: + Handle_Broadcast (void); + ~Handle_Broadcast (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_INET_Addr &r, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + static unsigned short DEFAULT_PORT; +}; + +extern ACE_Service_Object_Type rb; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_Broadcast.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_BROADCAST_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.inl new file mode 100644 index 00000000000..ce7f42617e7 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Broadcast.inl @@ -0,0 +1,116 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_Broadcast::~Handle_Broadcast (void) +{ +} + +ACE_INLINE +Handle_Broadcast::Handle_Broadcast (void) +{ +} + +ACE_INLINE int +Handle_Broadcast::open (const ACE_INET_Addr &r, int async) +{ + if (this->ACE_SOCK_Dgram::open (r) == -1) + return -1; + else if (async && ACE_SOCK_Dgram::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_Broadcast::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_INET_Addr sa; + + if (this->get_local_addr (sa) == -1) + return -1; + + ACE_OS::sprintf (buf, ACE_TEXT("%d/"), sa.get_port_number ()); + ACE_OS::strcat (buf, ACE_TEXT("udp # tests broadcasting\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_Broadcast::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_INET_Addr sba (Handle_Broadcast::DEFAULT_PORT); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'p': + sba.set (ACE_OS::atoi (get_opt.opt_arg ())); + break; + default: + break; + } + + if (this->open (sba) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), -1); + return 0; +} + +ACE_INLINE int +Handle_Broadcast::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_Broadcast::get_handle (void) const +{ + return this->ACE_SOCK_Dgram::get_handle (); +} + +ACE_INLINE int +Handle_Broadcast::handle_input (ACE_HANDLE) +{ + ACE_INET_Addr sa; + char buf[8 * 1024]; /* 8 k buffer */ + ssize_t n = this->recv (buf, sizeof buf, sa); + + if (n== -1) + return -1; + else + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("received broadcast datagram from host %C\n"), + sa.get_host_name ())); + + ACE_OS::puts (ACE_TEXT ("----------------------------------------")); + ACE_OS::write (ACE_STDOUT, buf, n); + + if (buf[n - 1] != '\n') + putchar ('\n'); + + ACE_OS::puts (ACE_TEXT ("----------------------------------------")); + + return 0; +} + +ACE_INLINE int +Handle_Broadcast::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + return this->ACE_SOCK_Dgram::close (); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.cpp new file mode 100644 index 00000000000..1654eff8573 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.cpp @@ -0,0 +1,19 @@ +// $Id$ + +#include "Handle_L_CODgram.h" + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +ACE_RCSID(server, Handle_L_CODgram, "$Id$") + +const ACE_TCHAR *Handle_L_CODgram::DEFAULT_RENDEZVOUS = + ACE_TEXT ("/tmp/foo_codgram"); + +#if !defined (__ACE_INLINE__) +#include "Handle_L_CODgram.inl" +#endif /* __ACE_INLINE__ */ + +Handle_L_CODgram local_codgram; +ACE_Service_Object_Type lc (&local_codgram, ACE_TEXT ("Local_CODgram")); + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.h new file mode 100644 index 00000000000..c0b158dea08 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.h @@ -0,0 +1,51 @@ +/* -*- C++ -*- */ +// $Id$ + +// Handles UNIX datagram messages from local host. + +#ifndef _HANDLE_L_CODGRAM_H +#define _HANDLE_L_CODGRAM_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/LSOCK_CODgram.h" +#include "ace/UNIX_Addr.h" +#include "ace/svc_export.h" + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +class ACE_Svc_Export Handle_L_CODgram : public ACE_Service_Object, public ACE_LSOCK_CODgram +{ +public: + Handle_L_CODgram (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +public: + int open (const ACE_UNIX_Addr &suad, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE); + virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask); + + ACE_TCHAR rendezvous[MAXPATHLEN + 1]; + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; +}; + +extern ACE_Service_Object_Type lc; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_CODgram.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ +#endif /* _HANDLE_L_CODGRAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.inl new file mode 100644 index 00000000000..a77d75e1fa8 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_CODgram.inl @@ -0,0 +1,123 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_L_CODgram::Handle_L_CODgram (void) +{ +} + +ACE_INLINE int +Handle_L_CODgram::open (const ACE_UNIX_Addr &suad, int async) +{ + if (this->ACE_LSOCK_CODgram::open (ACE_Addr::sap_any, suad) == -1) + return -1; + else if (async && this->ACE_LSOCK_CODgram::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_CODgram::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_UNIX_Addr sa; + + if (ACE_LSOCK_CODgram::get_local_addr (sa) == -1) + return -1; + + ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ())); + ACE_OS::strcat (buf, ACE_TEXT (" # tests local connected datagram\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_CODgram::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_UNIX_Addr sucd; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0); + const ACE_TCHAR *r = Handle_L_CODgram::DEFAULT_RENDEZVOUS; + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + r = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN); + ACE_OS::unlink (this->rendezvous); + sucd.set (this->rendezvous); + if (this->open (sucd) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), + -1); + return 0; +} + +ACE_INLINE int +Handle_L_CODgram::fini(void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_L_CODgram::get_handle (void) const +{ + return ACE_LSOCK_CODgram::get_handle (); +} + +ACE_INLINE int +Handle_L_CODgram::handle_input (ACE_HANDLE) +{ + ACE_HANDLE handle = ACE_INVALID_HANDLE; + char buf[BUFSIZ]; + + if (this->recv_handle (handle) == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, ACE_TEXT ("received handle (%d)\n"), handle)); + + ACE_OS::puts ("----------------------------------------"); + + for (;;) + { + ssize_t n = ACE_OS::read (handle, buf, sizeof buf); + + if (n <= 0) + break; + + ACE_OS::write (ACE_STDOUT, buf, n); + } + + ACE_OS::puts ("----------------------------------------"); + + if (ACE_OS::close (handle) == -1) + return -1; + + return 0; +} + +ACE_INLINE int +Handle_L_CODgram::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + this->ACE_LSOCK_CODgram::close (); + return ACE_OS::unlink (this->rendezvous); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.cpp new file mode 100644 index 00000000000..606f6f014fc --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.cpp @@ -0,0 +1,18 @@ +// $Id$ + +#include "Handle_L_Dgram.h" + +ACE_RCSID(server, Handle_L_Dgram, "$Id$") + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +const ACE_TCHAR *Handle_L_Dgram::DEFAULT_RENDEZVOUS = + ACE_TEXT ("/tmp/foo_dgram"); + +#if !defined (__ACE_INLINE__) +#include "Handle_L_Dgram.inl" +#endif /* __ACE_INLINE__ */ + +Handle_L_Dgram local_dgram; +ACE_Service_Object_Type ld (&local_dgram, ACE_TEXT ("Local_Dgram")); +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.h new file mode 100644 index 00000000000..b9fdc6324c0 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +// $Id$ + +// Handles UNIX datagram messages from local host. + +#ifndef _HANDLE_L_DGRAM_H +#define _HANDLE_L_DGRAM_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/LSOCK_Dgram.h" +#include "ace/UNIX_Addr.h" +#include "ace/svc_export.h" + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +class ACE_Svc_Export Handle_L_Dgram : public ACE_Service_Object, public ACE_LSOCK_Dgram +{ +public: + Handle_L_Dgram (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_UNIX_Addr &suad, int async = 0); + virtual int get_handle (void) const; + virtual int handle_input (int fd); + virtual int handle_close (int fd, ACE_Reactor_Mask); + + ACE_TCHAR rendezvous[MAXPATHLEN + 1]; + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; +}; + +extern ACE_Service_Object_Type ld; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_Dgram.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ +#endif /* _HANDLE_L_DGRAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.inl new file mode 100644 index 00000000000..3b2ab29331f --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Dgram.inl @@ -0,0 +1,116 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_L_Dgram::Handle_L_Dgram (void) +{ +} + +ACE_INLINE int +Handle_L_Dgram::open (const ACE_UNIX_Addr &suad, int async) +{ + if (this->ACE_LSOCK_Dgram::open (suad) == -1) + return -1; + else if (async && this->ACE_LSOCK_Dgram::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_Dgram::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_UNIX_Addr sa; + + if (this->ACE_LSOCK_Dgram::get_local_addr (sa) == -1) + return -1; + + ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ())); + ACE_OS::strcat (buf, ACE_TEXT (" # tests local datagram\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_Dgram::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_UNIX_Addr sudg; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0); + const ACE_TCHAR *r = Handle_L_Dgram::DEFAULT_RENDEZVOUS; + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + r = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN); + ACE_OS::unlink (this->rendezvous); + sudg.set (this->rendezvous); + if (this->open (sudg) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler (this, + ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), + -1); + return 0; +} + +ACE_INLINE int +Handle_L_Dgram::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE int +Handle_L_Dgram::get_handle (void) const +{ + return this->ACE_LSOCK_Dgram::get_handle (); +} + +ACE_INLINE int +Handle_L_Dgram::handle_input (int) +{ + ACE_UNIX_Addr sa; + char buf[8 * 1024]; /* 8 k buffer */ + int n; + + if ((n = this->recv (buf, sizeof buf, sa)) == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, ACE_TEXT ("received datagram from %s\n"), + sa.get_path_name ())); + + ACE_OS::puts ("----------------------------------------"); + ACE_OS::write (ACE_STDOUT, buf, n); + + if (buf[n - 1] != '\n') + putchar ('\n'); + + ACE_OS::puts ("----------------------------------------"); + + return 0; +} + +ACE_INLINE int +Handle_L_Dgram::handle_close (int, ACE_Reactor_Mask) +{ + this->ACE_LSOCK_Dgram::close (); + return ACE_OS::unlink (this->rendezvous); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.cpp new file mode 100644 index 00000000000..3be991cc36e --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.cpp @@ -0,0 +1,38 @@ +// $Id$ + +#include "Handle_L_FIFO.h" + +ACE_RCSID(server, Handle_L_FIFO, "$Id$") + +#if defined (SunOS4) +extern "C" +{ + int init (void); + int fini (void); + void __sti__Handle_L_FIFO_C_init_(); + void __std__Handle_L_FIFO_C_init_(); +} + +int +init (void) +{ + __sti__Handle_L_FIFO_C_init_(); + return 0; +} + +int +fini (void) +{ + __std__Handle_L_FIFO_C_init_(); + return 0; +} +#endif /* SunOS4 */ + +const ACE_TCHAR *Handle_L_FIFO::DEFAULT_RENDEZVOUS = ACE_TEXT("/tmp/foo_fifo"); + +#if !defined (__ACE_INLINE__) +#include "Handle_L_FIFO.inl" +#endif /* __ACE_INLINE__ */ + +Handle_L_FIFO local_fifo; +ACE_Service_Object_Type lf (&local_fifo, ACE_TEXT("Local_FIFO")); diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.h new file mode 100644 index 00000000000..fcd51a43a1a --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +// +// $Id$ + +/* Handle connections from local UNIX ACE_FIFO */ +/* Read from a well known ACE_FIFO and write to stdout. */ + +#ifndef _HANDLE_L_FIFO_H +#define _HANDLE_L_FIFO_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/FIFO_Recv_Msg.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +class ACE_Svc_Export Handle_L_FIFO : public ACE_Service_Object, public ACE_FIFO_Recv_Msg +{ +public: + Handle_L_FIFO (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_TCHAR *rendezvous_fifo); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; +}; + +extern ACE_Service_Object_Type lf; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_FIFO.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_L_FIFO_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.inl new file mode 100644 index 00000000000..f6cd0cda734 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_FIFO.inl @@ -0,0 +1,101 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_stropts.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_L_FIFO::Handle_L_FIFO (void) +{ +} + +ACE_INLINE int +Handle_L_FIFO::open (const ACE_TCHAR *rendezvous_fifo) +{ + if (this->ACE_FIFO_Recv_Msg::open (rendezvous_fifo) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_FIFO::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + const ACE_TCHAR *rendezvous_fifo; + + this->get_local_addr (rendezvous_fifo); + + ACE_OS::strcpy (buf, rendezvous_fifo); + ACE_OS::strcat (buf, ACE_TEXT(" # tests local ACE_FIFO\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_FIFO::init (int argc, ACE_TCHAR *argv[]) +{ + const ACE_TCHAR *rendezvous_fifo = Handle_L_FIFO::DEFAULT_RENDEZVOUS; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("r:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + rendezvous_fifo = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::unlink (rendezvous_fifo); + if (this->open (rendezvous_fifo) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), + -1); + return 0; +} + +ACE_INLINE int +Handle_L_FIFO::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_L_FIFO::get_handle (void) const +{ + return this->ACE_FIFO::get_handle (); +} + +ACE_INLINE int +Handle_L_FIFO::handle_input (ACE_HANDLE) +{ + char buf[PIPE_BUF]; + ACE_Str_Buf msg (buf, 0, sizeof buf); + + /* Accept communication requests */ + if (this->recv (msg) == -1) + return -1; + else + + ACE_OS::write (ACE_STDOUT, (const char *) msg.buf, (int) msg.len); + return 0; +} + +ACE_INLINE int +Handle_L_FIFO::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + return this->ACE_FIFO::remove (); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.cpp new file mode 100644 index 00000000000..ebd5d618f41 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.cpp @@ -0,0 +1,66 @@ +// $Id$ + +#include "Handle_L_Pipe.h" +#include "ace/OS_NS_ctype.h" +#include "ace/OS_NS_unistd.h" + +ACE_RCSID(server, Handle_L_Pipe, "$Id$") + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +// Uppercase N bytes of S. + +char * +Handle_L_Pipe::upper_case (char s[], int n) +{ + while (--n >= 0) + if (ACE_OS::ace_islower (s[n])) + s[n] = ACE_OS::ace_toupper (s[n]); + + return s; +} + +int +Handle_L_Pipe::handle_input (ACE_HANDLE) +{ + ACE_LSOCK_Stream new_local_stream; + int n; + ACE_HANDLE fd1 = ACE_INVALID_HANDLE; + ACE_HANDLE fd2 = ACE_INVALID_HANDLE; + char buf[BUFSIZ]; + + if (this->accept (new_local_stream) == -1) + return -1; + + if (new_local_stream.recv_handle (fd1) == -1 + || new_local_stream.recv_handle (fd2) == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("received file descriptors %d and %d\n"), + fd1, + fd2)); + + if ((n = ACE_OS::read (fd1, buf, sizeof buf)) == -1) + return -1; + else if (ACE_OS::write (fd2, this->upper_case (buf, n), n) == -1) + return -1; + if (ACE_OS::close (fd1) == -1 + || ACE_OS::close (fd2) == -1) + return -1; + if (new_local_stream.close () == -1) + return -1; + + return 0; +} + +const ACE_TCHAR *Handle_L_Pipe::DEFAULT_RENDEZVOUS = ACE_TEXT ("/tmp/foo_pipe"); + +#if !defined (__ACE_INLINE__) +#include "Handle_L_Pipe.inl" +#endif /* __ACE_INLINE__ */ + +Handle_L_Pipe local_pipe; +ACE_Service_Object_Type lp (&local_pipe, ACE_TEXT ("Local_Pipe")); + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.h new file mode 100644 index 00000000000..5f6fac87ecf --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.h @@ -0,0 +1,55 @@ +// -*- C++ -*- +// $Id$ + +// Handle connections from local UNIX domain sockets that are sending +// end-points from a pipe! + +#ifndef _HANDLE_L_PIPE_H +#define _HANDLE_L_PIPE_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/UNIX_Addr.h" +#include "ace/LSOCK_Acceptor.h" +#include "ace/svc_export.h" + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +class ACE_Svc_Export Handle_L_Pipe : public ACE_Service_Object, public ACE_LSOCK_Acceptor +{ +public: + Handle_L_Pipe (void); + ~Handle_L_Pipe (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_UNIX_Addr &suap, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + char *upper_case (char s[], int n); + + ACE_TCHAR rendezvous[MAXPATHLEN + 1]; + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; +}; + +extern ACE_Service_Object_Type lp; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_Pipe.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ +#endif /* _HANDLE_L_PIPE_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.inl new file mode 100644 index 00000000000..ce978aa85ea --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Pipe.inl @@ -0,0 +1,96 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_L_Pipe::~Handle_L_Pipe (void) +{ +} + +ACE_INLINE +Handle_L_Pipe::Handle_L_Pipe (void) +{ +} + +ACE_INLINE int +Handle_L_Pipe::open (const ACE_UNIX_Addr &suap, int async) +{ + if (this->ACE_LSOCK_Acceptor::open (suap) == -1) + return -1; + else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_Pipe::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_UNIX_Addr sa; + + if (ACE_LSOCK_Acceptor::get_local_addr (sa) == -1) + return -1; + + ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ())); + ACE_OS::strcat (buf, ACE_TEXT (" # tests local pipe\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_Pipe::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_UNIX_Addr sup; + const ACE_TCHAR *r = Handle_L_Pipe::DEFAULT_RENDEZVOUS; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + r = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN); + ACE_OS::unlink (this->rendezvous); + sup.set (this->rendezvous); + if (this->open (sup) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), -1); + return 0; +} + +ACE_INLINE int +Handle_L_Pipe::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE int +Handle_L_Pipe::get_handle (void) const +{ + return ACE_LSOCK_Acceptor::get_handle (); +} + +ACE_INLINE int +Handle_L_Pipe::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + this->ACE_LSOCK_Acceptor::close (); + return ACE_OS::unlink (this->rendezvous); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.cpp new file mode 100644 index 00000000000..fcdc2b7f0bf --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.cpp @@ -0,0 +1,18 @@ +// $Id$ + +#include "Handle_L_SPIPE.h" + +ACE_RCSID(server, Handle_L_SPIPE, "$Id$") + +#if !defined (__ACE_INLINE__) +#include "Handle_L_SPIPE.inl" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_HAS_STREAM_PIPES) + +const ACE_TCHAR *Handle_L_SPIPE::DEFAULT_RENDEZVOUS = ACE_TEXT ("/tmp/foo_spipe"); + +Handle_L_SPIPE local_spipe; +ACE_Service_Object_Type lsp (&local_spipe, ACE_TEXT ("Local_SPIPE")); + +#endif /* ACE_HAS_STREAM_PIPES */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.h new file mode 100644 index 00000000000..baa8d89ea8f --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.h @@ -0,0 +1,52 @@ +/* -*- C++ -*- */ +// $Id$ + +/* Handle connections from local UNIX ACE_SPIPE */ +/* Read from a well known ACE_SPIPE and write to stdout. */ + +#ifndef _HANDLE_L_SPIPE_H +#define _HANDLE_L_SPIPE_H + +#include "ace/Service_Config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/SPIPE_Acceptor.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +#if defined (ACE_HAS_STREAM_PIPES) + +class ACE_Svc_Export Handle_L_SPIPE : public ACE_Service_Object, public ACE_SPIPE_Acceptor +{ +public: + Handle_L_SPIPE (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_SPIPE_Addr &rendezvous_spipe); + virtual int get_handle (void) const; + virtual int handle_input (int fd); + virtual int handle_close (int fd, ACE_Reactor_Mask); + + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; +}; + +extern ACE_Service_Object_Type lsp; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_SPIPE.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_L_SPIPE_H */ + + +#endif /* ACE_HAS_STREAM_PIPES */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.inl new file mode 100644 index 00000000000..910938d8648 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_SPIPE.inl @@ -0,0 +1,131 @@ +// -*- C++ -*- +// +// $Id$ + + +#include "ace/SPIPE_Stream.h" + +#if defined (ACE_HAS_STREAM_PIPES) + +#include "ace/Reactor.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_string.h" + + +ACE_INLINE +Handle_L_SPIPE::Handle_L_SPIPE (void) +{ +} + +ACE_INLINE int +Handle_L_SPIPE::open (const ACE_SPIPE_Addr &rendezvous_spipe) +{ + if (this->ACE_SPIPE_Acceptor::open (rendezvous_spipe) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_SPIPE::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_SPIPE_Addr sa; + + if (ACE_SPIPE_Acceptor::get_local_addr (sa) == -1) + return -1; + + ACE_OS::strcpy (buf, sa.get_path_name ()); + ACE_OS::strcat (buf, ACE_TEXT (" # tests local STREAM pipe\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_SPIPE::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_SPIPE_Addr susp; + const ACE_TCHAR *rendezvous = Handle_L_SPIPE::DEFAULT_RENDEZVOUS; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + rendezvous = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::unlink (rendezvous); + susp.set (rendezvous); + if (this->open (susp) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), + -1); + return 0; +} + +ACE_INLINE int +Handle_L_SPIPE::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE int +Handle_L_SPIPE::get_handle (void) const +{ + return ACE_SPIPE::get_handle(); +} + +ACE_INLINE int +Handle_L_SPIPE::handle_input (int) +{ + ACE_SPIPE_Stream new_spipe; + char buf[PIPE_BUF]; + ACE_Str_Buf msg (buf, 0, sizeof buf); + int flags = 0; + + /* Accept communication requests */ + if (this->ACE_SPIPE_Acceptor::accept (new_spipe) == -1) + return -1; + else + { + ACE_SPIPE_Addr sa; + + new_spipe.get_remote_addr (sa); + + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("accepted request from %s (gid = %d, uid = %d)\n"), + sa.get_path_name (), sa.group_id (), sa.user_id ())); + } + + while (new_spipe.recv ((ACE_Str_Buf *) 0, &msg, &flags) >= 0) + if (msg.len != 0) + ACE_OS::write (ACE_STDOUT, (const char *) msg.buf, (int) msg.len); + else + break; + + if (new_spipe.close () == -1) + return -1; + return 0; +} + +ACE_INLINE int +Handle_L_SPIPE::handle_close (int, ACE_Reactor_Mask) +{ + return this->ACE_SPIPE_Acceptor::remove (); +} +#endif /* ACE_HAS_STREAM_PIPES */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.cpp new file mode 100644 index 00000000000..8a0a6a46033 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.cpp @@ -0,0 +1,22 @@ +// $Id$ + +#include "Handle_L_Stream.h" + +ACE_RCSID(server, Handle_L_Stream, "$Id$") + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +// Static variables. + +const ACE_TCHAR *Handle_L_Stream::DEFAULT_RENDEZVOUS = ACE_TEXT ("/tmp/foo_stream"); +char *Handle_L_Stream::login_name = 0; +char Handle_L_Stream::login[ACE_MAX_USERID]; + +#if !defined (__ACE_INLINE__) +#include "Handle_L_Stream.inl" +#endif /* __ACE_INLINE__ */ + +Handle_L_Stream local_stream; +ACE_Service_Object_Type ls (&local_stream, ACE_TEXT ("Local_Stream")); + +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.h new file mode 100644 index 00000000000..aa3840bfede --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +// $Id$ + +// Handle connections from local UNIX domain sockets. + +#ifndef _HANDLE_L_STREAM_H +#define _HANDLE_L_STREAM_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/UNIX_Addr.h" +#include "ace/LSOCK_Acceptor.h" +#include "ace/svc_export.h" + +#if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS) + +class ACE_Svc_Export Handle_L_Stream : public ACE_Service_Object, public ACE_LSOCK_Acceptor +{ +public: + Handle_L_Stream (void); + ~Handle_L_Stream (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_UNIX_Addr &suas, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + ACE_TCHAR rendezvous[MAXPATHLEN + 1]; + static const ACE_TCHAR *DEFAULT_RENDEZVOUS; + static char *login_name; + static char login[ACE_MAX_USERID]; +}; + +extern ACE_Service_Object_Type ls; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_L_Stream.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ +#endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */ +#endif /* _HANDLE_L_STREAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.inl new file mode 100644 index 00000000000..80b21852293 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_L_Stream.inl @@ -0,0 +1,149 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_time.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_L_Stream::~Handle_L_Stream (void) +{ +} + +ACE_INLINE +Handle_L_Stream::Handle_L_Stream (void) +{ + if (Handle_L_Stream::login_name == 0) + Handle_L_Stream::login_name = ACE_OS::cuserid (Handle_L_Stream::login); +} + +ACE_INLINE int +Handle_L_Stream::open (const ACE_UNIX_Addr &suas, + int async) +{ + if (this->ACE_LSOCK_Acceptor::open (suas) == -1) + return -1; + else if (async && this->ACE_LSOCK_Acceptor::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_Stream::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_UNIX_Addr sa; + + if (this->get_local_addr (sa) == -1) + return -1; + + ACE_OS::strcpy (buf, ACE_TEXT_CHAR_TO_TCHAR (sa.get_path_name ())); + ACE_OS::strcat (buf, ACE_TEXT (" # tests local ACE_Stream\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_L_Stream::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_UNIX_Addr sus; + const ACE_TCHAR *r = Handle_L_Stream::DEFAULT_RENDEZVOUS; + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("r:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'r': + r = get_opt.opt_arg (); + break; + default: + break; + } + + ACE_OS::strncpy (this->rendezvous, r, MAXPATHLEN); + ACE_OS::unlink (this->rendezvous); + sus.set (this->rendezvous); + + if (this->open (sus) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), -1); + return 0; +} + +ACE_INLINE int +Handle_L_Stream::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_L_Stream::get_handle (void) const +{ + return ACE_LSOCK_Acceptor::get_handle (); +} + +ACE_INLINE int +Handle_L_Stream::handle_input (ACE_HANDLE) +{ + ACE_LSOCK_Stream new_local_stream; + ACE_UNIX_Addr sa; + ACE_HANDLE handle = ACE_INVALID_HANDLE; + char buf[BUFSIZ]; + + if (this->accept (new_local_stream, &sa) == -1) + return -1; + else if (new_local_stream.recv_handle (handle) == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("received file descriptor %d on ACE_Stream %s\n"), + handle, sa.get_path_name ())); + + ACE_OS::puts ("----------------------------------------"); + + for (;;) + { + ssize_t n = ACE_OS::read (handle, buf, sizeof buf); + + if (n <= 0) + break; + + ACE_OS::write (ACE_STDOUT, buf, n); + } + + ACE_OS::puts ("----------------------------------------"); + + time_t t = ACE_OS::time (0L); + ACE_TCHAR *cs = ACE_OS::ctime (&t); + + if (new_local_stream.send (4, + Handle_L_Stream::login_name, + ACE_OS::strlen (Handle_L_Stream::login_name), + ACE_TEXT_ALWAYS_CHAR (cs), + ACE_OS::strlen (cs)) == -1) + return -1; + else if (ACE_OS::close (handle) == -1) + return -1; + else if (new_local_stream.close () == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_L_Stream::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + this->ACE_LSOCK_Acceptor::close (); + return ACE_OS::unlink (this->rendezvous); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.cpp new file mode 100644 index 00000000000..6b684f40e6b --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.cpp @@ -0,0 +1,38 @@ +// $Id$ + +#include "Handle_R_Dgram.h" + +ACE_RCSID(server, Handle_R_Dgram, "Handle_R_Dgram.cpp,v 4.2 1998/07/31 22:55:19 gonzo Exp") + +#if defined (SunOS4) +extern "C" +{ + int init (void); + int fini (void); + void __sti__Handle_R_Dgram_C_init_(); + void __std__Handle_R_Dgram_C_init_(); +} + +int +init (void) +{ + __sti__Handle_R_Dgram_C_init_(); + return 0; +} + +int +fini (void) +{ + __std__Handle_R_Dgram_C_init_(); + return 0; +} +#endif /* SunOS4 */ + +unsigned short Handle_R_Dgram::DEFAULT_PORT = ACE_DEFAULT_SERVER_PORT; + +#if !defined (__ACE_INLINE__) +#include "Handle_R_Dgram.inl" +#endif /* __ACE_INLINE__ */ + +Handle_R_Dgram remote_dgram; +ACE_Service_Object_Type rd (&remote_dgram, ACE_TEXT ("Remote_Dgram")); diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.h new file mode 100644 index 00000000000..e3ef8c0e802 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +// $Id$ + +/* Handles INET datagram messages from remote hosts. */ + +#ifndef _HANDLE_R_DGRAM_H +#define _HANDLE_R_DGRAM_H + +#include "ace/Service_Config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/INET_Addr.h" +#include "ace/SOCK_Dgram.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +class ACE_Svc_Export Handle_R_Dgram : public ACE_Service_Object, public ACE_SOCK_Dgram +{ +public: + Handle_R_Dgram (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_INET_Addr &r, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + static u_short DEFAULT_PORT; +}; + +extern ACE_Service_Object_Type rd; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_R_Dgram.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_R_DGRAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.inl new file mode 100644 index 00000000000..88212a988f0 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Dgram.inl @@ -0,0 +1,111 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_R_Dgram::Handle_R_Dgram (void) +{ +} + +ACE_INLINE int +Handle_R_Dgram::open (const ACE_INET_Addr &r, int async) +{ + if (this->ACE_SOCK_Dgram::open (r) == -1) + return -1; + else if (async && this->ACE_SOCK_Dgram::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_R_Dgram::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_INET_Addr sa; + + if (this->get_local_addr (sa) == -1) + return -1; + + ACE_OS::sprintf (buf, ACE_TEXT ("%d/"), sa.get_port_number ()); + ACE_OS::strcat (buf, ACE_TEXT ("udp # tests remote dgram\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_R_Dgram::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_INET_Addr sidg (Handle_R_Dgram::DEFAULT_PORT); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'p': + sidg.set (ACE_OS::atoi (get_opt.opt_arg ())); + break; + default: + break; + } + + if (this->open (sidg) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("registering service with ACE_Reactor")), -1); + return 0; +} + +ACE_INLINE int +Handle_R_Dgram::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_R_Dgram::get_handle (void) const +{ + return ACE_SOCK_Dgram::get_handle (); +} + +ACE_INLINE int +Handle_R_Dgram::handle_input (ACE_HANDLE) +{ + ACE_INET_Addr sa; + char buf[8 * 1024]; /* 8 k buffer */ + ssize_t n = this->recv (buf, sizeof buf, sa); + + if (n == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("received datagram from host %C on port %d\n"), + sa.get_host_name (), sa.get_port_number ())); + + ACE_OS::puts ("----------------------------------------"); + ACE_OS::write (ACE_STDOUT, buf, n); + + if (buf[n - 1] != '\n') + putchar ('\n'); + + ACE_OS::puts ("----------------------------------------"); + + return 0; +} + +ACE_INLINE int +Handle_R_Dgram::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + return this->ACE_SOCK_Dgram::close (); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.cpp new file mode 100644 index 00000000000..ee49a28a2ef --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.cpp @@ -0,0 +1,42 @@ +// $Id$ + +#include "Handle_R_Stream.h" + +ACE_RCSID(server, Handle_R_Stream, "$Id$") + +#if defined (SunOS4) +extern "C" +{ + int init (void); + int fini (void); + void __sti__Handle_R_Stream_C_recv_n_(); + void __std__Handle_R_Stream_C_recv_n_(); +} + +int +init (void) +{ + __sti__Handle_R_Stream_C_recv_n_(); + return 0; +} + +int +fini (void) +{ + __std__Handle_R_Stream_C_recv_n_(); + return 0; +} +#endif /* SunOS4 */ + +// Static variables. + +u_short Handle_R_Stream::DEFAULT_PORT = ACE_DEFAULT_SERVER_PORT; +char *Handle_R_Stream::login_name = 0; +char Handle_R_Stream::login[ACE_MAX_USERID]; + +#if !defined (__ACE_INLINE__) +#include "Handle_R_Stream.inl" +#endif /* __ACE_INLINE__ */ + +Handle_R_Stream remote_stream; +ACE_Service_Object_Type rs (&remote_stream, ACE_TEXT("Remote_Stream")); diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.h new file mode 100644 index 00000000000..fb06f525073 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +// +// $Id$ + +/* Handle connections from remote INET connections. */ + +#ifndef _HANDLE_R_STREAM_H +#define _HANDLE_R_STREAM_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/SOCK_Stream.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/INET_Addr.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +class ACE_Svc_Export Handle_R_Stream : public ACE_Service_Object, public ACE_SOCK_Acceptor +{ +public: + Handle_R_Stream (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + int open (const ACE_INET_Addr &sia, int async = 0); + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE fd); + virtual int handle_close (ACE_HANDLE fd, ACE_Reactor_Mask); + + ACE_SOCK_Stream new_remote_stream; + static u_short DEFAULT_PORT; + static char *login_name; + static char login[ACE_MAX_USERID]; +}; + +extern ACE_Service_Object_Type rs; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_R_Stream.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_R_STREAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.inl new file mode 100644 index 00000000000..f126cd13aee --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_R_Stream.inl @@ -0,0 +1,153 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Get_Opt.h" +#include "ace/WFMO_Reactor.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_time.h" +#include "ace/OS_NS_unistd.h" + +ACE_INLINE +Handle_R_Stream::Handle_R_Stream (void) +{ + if (Handle_R_Stream::login_name == 0) + Handle_R_Stream::login_name = ACE_OS::cuserid (Handle_R_Stream::login); +} + +ACE_INLINE int +Handle_R_Stream::open (const ACE_INET_Addr &sia, int async) +{ + if (this->ACE_SOCK_Acceptor::open (sia) == -1) + return -1; + else if (async && this->ACE_SOCK_Acceptor::enable (ACE_SIGIO) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_R_Stream::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_INET_Addr sa; + + if (this->get_local_addr (sa) == -1) + return -1; + + ACE_OS::sprintf (buf, + ACE_TEXT("%d/%s %s"), + sa.get_port_number (), + ACE_TEXT("tcp"), + ACE_TEXT("# tests remote stream\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_R_Stream::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_INET_Addr sis (Handle_R_Stream::DEFAULT_PORT); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'p': + sis.set (ACE_OS::atoi (get_opt.opt_arg ())); + break; + default: + break; + } + + if (this->open (sis) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); + + else if (ACE_Reactor::instance ()->register_handler + (this, ACE_Event_Handler::ACCEPT_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "registering service with ACE_Reactor\n"), + -1); + return 0; +} + +ACE_INLINE int +Handle_R_Stream::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +ACE_INLINE ACE_HANDLE +Handle_R_Stream::get_handle (void) const +{ + return ACE_SOCK_Acceptor::get_handle (); +} + +ACE_INLINE int +Handle_R_Stream::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + int bytes; + + // Try to find out if the implementation of the reactor that we are + // using requires us to reset the event association for the newly + // created handle. This is because the newly created handle will + // inherit the properties of the listen handle, including its event + // associations. + int reset_new_handle = + ACE_Reactor::instance ()->uses_event_associations (); + + if (this->accept (this->new_remote_stream, // stream + 0, // remote address + 0, // timeout + 1, // restart + reset_new_handle // reset new handler + ) == -1) + return -1; + else + ACE_DEBUG ((LM_INFO, "new_remote_stream fd = %d\n", + this->new_remote_stream.get_handle ())); + + ACE_INET_Addr sa; + + if (this->new_remote_stream.get_remote_addr (sa) == -1) + return -1; + + ACE_DEBUG ((LM_INFO, + "accepted from host %s at port %d\n", + sa.get_host_name (), + sa.get_port_number ())); + + ACE_OS::puts (ACE_TEXT ("----------------------------------------")); + + while ((bytes = this->new_remote_stream.recv (buf, sizeof buf)) > 0) + ACE_OS::write (ACE_STDOUT, buf, bytes); + + ACE_OS::puts (ACE_TEXT ("----------------------------------------")); + + time_t t = ACE_OS::time (0L); + ACE_TCHAR *cs = ACE_OS::ctime (&t); + + if (this->new_remote_stream.send (4, + Handle_R_Stream::login_name, + ACE_OS::strlen (Handle_R_Stream::login_name), + cs, + ACE_OS::strlen (cs)) == -1) + return -1; + + if (this->new_remote_stream.close () == -1) + return -1; + + return 0; +} + +ACE_INLINE int +Handle_R_Stream::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +{ + return this->ACE_SOCK_Acceptor::close (); +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.cpp new file mode 100644 index 00000000000..fb53c0f8d70 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.cpp @@ -0,0 +1,195 @@ +// $Id$ + +#if !defined (ACE_HANDLE_THR_STREAM_C) +#define ACE_HANDLE_THR_STREAM_C + +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_unistd.h" +#include "ace/Get_Opt.h" +#include "ace/INET_Addr.h" +#include "ace/TLI_Acceptor.h" +#include "Handle_Thr_Stream.h" + +ACE_RCSID(server, Handle_Thr_Stream, "$Id$") + +#if defined (ACE_HAS_THREADS) + +#include "ace/OS_NS_time.h" + +// Shorthand names. +#define SVH SVC_HANDLER +#define PR_AC_1 ACE_PEER_ACCEPTOR_1 +#define PR_AC_2 ACE_PEER_ACCEPTOR_2 +#define PR_ST_1 ACE_PEER_STREAM_1 +#define PR_ST_2 ACE_PEER_STREAM_2 + +template <class SVH, PR_AC_1> +Handle_Thr_Acceptor<SVH, PR_AC_2>::~Handle_Thr_Acceptor (void) +{ +} + +template <class SVH, PR_AC_1> +Handle_Thr_Acceptor<SVH, PR_AC_2>::Handle_Thr_Acceptor (void) + : thr_flags_ (THR_DETACHED | THR_NEW_LWP) +{ +} + +template <class SVH, PR_AC_1> int +Handle_Thr_Acceptor<SVH, PR_AC_2>::info (ACE_TCHAR **strp, + size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + ACE_INET_Addr sa; + + if (this->acceptor ().get_local_addr (sa) == -1) + return -1; + + ACE_OS::sprintf (buf, ACE_TEXT("%d/"), sa.get_port_number ()); + ACE_OS::strcat (buf, ACE_TEXT("tcp # tests threaded remote stream\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +template <class SVH, PR_AC_1> int +Handle_Thr_Acceptor<SVH, PR_AC_2>::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_INET_Addr local_addr (ACE_DEFAULT_THR_PORT); + int n_threads = ACE_DEFAULT_THREADS; + + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("p:t:"), 0); + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'p': + local_addr.set (ACE_OS::atoi (get_opt.opt_arg ())); + break; + case 't': + n_threads = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + break; + } + + // Initialize the threading strategy. + if (this->thr_strategy_.open (&this->thr_mgr_, + this->thr_flags_, + n_threads) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + + // Initialize the Acceptor base class, passing in the desired + // concurrency strategy. + else if (this->open (local_addr, + ACE_Reactor::instance (), + 0, + 0, + &this->thr_strategy_) == -1) + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), -1); + else + return 0; +} + +template <class SVH, PR_AC_1> int +Handle_Thr_Acceptor<SVH, PR_AC_2>::fini (void) +{ + return ACE_Reactor::instance ()->remove_handler + (this, ACE_Event_Handler::ACCEPT_MASK); +} + +template <PR_ST_1> +CLI_Stream<PR_ST_2>::CLI_Stream (ACE_Thread_Manager *thr_mgr) + : inherited (thr_mgr) +{ +} + +template <PR_ST_1> int +CLI_Stream<PR_ST_2>::close (u_long) +{ + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%t) client stream object closing down\n"))); + this->peer ().close (); + + // Must be allocated dynamically! + delete this; + return 0; +} + +template <PR_ST_1> int +CLI_Stream<PR_ST_2>::open (void *) +{ + ACE_INET_Addr sa; + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) client handle = %d\n"), + this->peer ().get_handle ())); + + if (this->peer ().get_remote_addr (sa) == -1) + return -1; + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) accepted at port %d\n"), + sa.get_port_number ())); + return 0; +} + +template <PR_ST_1> int +CLI_Stream<PR_ST_2>::svc (void) +{ + char buf[BUFSIZ]; + char login_name[ACE_MAX_USERID]; + int bytes; + + ACE_OS::puts ("----------------------------------------"); + + while ((bytes = this->peer ().recv (buf, sizeof buf)) > 0) + ACE_OS::write (ACE_STDOUT, buf, bytes); + + ACE_OS::puts ("----------------------------------------"); + ACE_OS::fflush (stdout); + + time_t t = ACE_OS::time (0L); + ACE_OS::cuserid (login_name); + ACE_OS::sprintf (buf, "user %s %s", + login_name, + ACE_TEXT_ALWAYS_CHAR (ACE_OS::ctime ((const time_t *) &t))); + + if (this->peer ().send_n (buf, ACE_OS::strlen (buf) + 1) == -1) + return -1; + + ACE_DEBUG ((LM_DEBUG, "(%t) sent reply %s", buf)); + return 0; +} + +#undef SVH +#undef PR_AC_1 +#undef PR_AC_2 +#undef PR_ST_1 +#undef PR_ST_2 + +//---------------------------------------- + +#if defined (ACE_HAS_TLI) +#include "ace/TLI_Stream.h" +#include "ace/TLI_Acceptor.h" +#define THR_STREAM ACE_TLI_STREAM +#define THR_ACCEPTOR ACE_TLI_ACCEPTOR +#else +#include "ace/SOCK_Stream.h" +#include "ace/SOCK_Acceptor.h" +#define THR_STREAM ACE_SOCK_STREAM +#define THR_ACCEPTOR ACE_SOCK_ACCEPTOR +#endif /* ACE_HAS_TLI */ +#include "ace/INET_Addr.h" + +typedef CLI_Stream <THR_STREAM> CLI_STREAM; +typedef Handle_Thr_Acceptor<CLI_STREAM, THR_ACCEPTOR> HANDLE_THR_ACCEPTOR; + +// Service object. +HANDLE_THR_ACCEPTOR remote_thr_stream; +ACE_Service_Object_Type rts (&remote_thr_stream, ACE_TEXT("Remote_Thr_Stream")); + +#endif /* ACE_HAS_THREADS */ +#endif /* ACE_HANDLE_THR_STREAM_C */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.h new file mode 100644 index 00000000000..994a70009c0 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Thr_Stream.h @@ -0,0 +1,73 @@ +/* -*- C++ -*- */ +// $Id$ + +#ifndef _HANDLE_THR_STREAM_H +#define _HANDLE_THR_STREAM_H + +#include "ace/Acceptor.h" +#include "ace/Svc_Handler.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" + +#if defined (ACE_HAS_THREADS) + +template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> +class Handle_Thr_Acceptor : public ACE_Strategy_Acceptor<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> + // = TITLE + // This factory creates new <SVC_HANDLERS> and runs them with the + // configured <ACE_Thread_Strategy>. +{ +public: + // = Initialization and termination. + Handle_Thr_Acceptor (void); + ~Handle_Thr_Acceptor (void); + + // = Dynamic linking hooks. + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + ACE_Thread_Manager thr_mgr_; + // Thread manager. + + ACE_Thread_Strategy<SVC_HANDLER> thr_strategy_; + // Threading strategy. + + int thr_flags_; + // Threading flags. +}; + +template <ACE_PEER_STREAM_1> +class CLI_Stream : public ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_MT_SYNCH> + // = TITLE + // This class interacts with the client, running in a separate + // thread and handles connections from remote TCP/IP connections. +{ +public: + CLI_Stream (ACE_Thread_Manager * = 0); + + virtual int open (void *); + // Open the service. + + virtual int close (u_long); + // Close down the service. + + virtual int svc (void); + // Execute the service. + +protected: + typedef ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_MT_SYNCH> inherited; +}; + +extern ACE_Service_Object_Type rts; + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "Handle_Thr_Stream.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ +#endif /* ACE_HAS_THREADS */ +#endif /* _HANDLE_THR_STREAM_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.cpp new file mode 100644 index 00000000000..18e9c154e91 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.cpp @@ -0,0 +1,36 @@ +// $Id$ + +#include "Handle_Timeout.h" + +ACE_RCSID(server, Handle_Timeout, "$Id$") + +#if defined (SunOS4) +extern "C" +{ + int init (void); + int fini (void); + void __sti__Handle_Timeout_C_init_(); + void __std__Handle_Timeout_C_init_(); +} + +int +init (void) +{ + __sti__Handle_Timeout_C_init_(); + return 0; +} + +int +fini (void) +{ + __std__Handle_Timeout_C_init_(); + return 0; +} +#endif /* SunOS4 */ + +#if !defined (__ACE_INLINE__) +#include "Handle_Timeout.inl" +#endif /* __ACE_INLINE__ */ + +Handle_Timeout timer_1; +ACE_Service_Object_Type t1 (&timer_1, ACE_TEXT("Timer_1")); diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.h b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.h new file mode 100644 index 00000000000..e07cc247ca9 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +// +// $Id$ + +/* Handles timeouts. */ + +#ifndef _HANDLE_TIMEOUT_H +#define _HANDLE_TIMEOUT_H + +#include "ace/Service_Config.h" +#include "ace/Reactor.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Types.h" +#include "ace/Log_Msg.h" +#include "ace/svc_export.h" + +class ACE_Svc_Export Handle_Timeout : public ACE_Service_Object +{ +public: + Handle_Timeout (void); + virtual int init (int argc, ACE_TCHAR *argv[]); + virtual int info (ACE_TCHAR **, size_t) const; + virtual int fini (void); + +private: + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); + + int count; +}; + +extern ACE_Service_Object_Type t1; + +#if defined (__ACE_INLINE__) +#define ACE_INLINE inline +#include "Handle_Timeout.inl" +#else +#define ACE_INLINE +#endif /* __ACE_INLINE__ */ + +#endif /* _HANDLE_TIMEOUT_H */ diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.inl b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.inl new file mode 100644 index 00000000000..a5f1421b8b9 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Handle_Timeout.inl @@ -0,0 +1,86 @@ +/* -*- C++ -*- */ +// $Id$ + +#include "ace/Service_Config.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" + +ACE_INLINE +Handle_Timeout::Handle_Timeout (void): count (0) +{ +} + +ACE_INLINE int +Handle_Timeout::info (ACE_TCHAR **strp, size_t length) const +{ + ACE_TCHAR buf[BUFSIZ]; + + ACE_OS::strcpy (buf, ACE_TEXT("# tests timeout facility\n")); + + if (*strp == 0 && (*strp = ACE_OS::strdup (buf)) == 0) + return -1; + else + ACE_OS::strncpy (*strp, buf, length); + return ACE_OS::strlen (buf); +} + +ACE_INLINE int +Handle_Timeout::init (int argc, ACE_TCHAR *argv[]) +{ + ACE_Time_Value delta (10); + ACE_Time_Value interval (1); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("a:d:i:"), 0); + intptr_t arg = 0; + + for (int c; (c = get_opt ()) != -1; ) + switch (c) + { + case 'd': + delta.sec (ACE_OS::atoi (get_opt.opt_arg ())); + break; + case 'i': + interval.sec (ACE_OS::atoi (get_opt.opt_arg ())); + break; + case 'a': + arg = ACE_OS::atoi (get_opt.opt_arg ()); + break; + default: + break; + } + + if (ACE_Reactor::instance ()->schedule_timer (this, + reinterpret_cast<void *> (arg), + delta, + interval) == -1) + return -1; + else + return 0; +} + +ACE_INLINE int +Handle_Timeout::fini (void) +{ + return 0; +} + +ACE_INLINE ACE_HANDLE +Handle_Timeout::get_handle (void) const +{ + return ACE_INVALID_HANDLE; +} + +ACE_INLINE int +Handle_Timeout::handle_timeout (const ACE_Time_Value &tv, + const void *arg) +{ + if (this->count++ >= 10) + return -1; // Automatically cancel periodic timer... + + // Cast arg to a long, first, because a pointer is the same + // size as a long on all current ACE platforms. + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("time for this(%u) expired at (%d, %d) with arg = %d\n"), + this, tv.sec (), tv.usec (), (int) (long) arg)); + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/Makefile.am b/ACE/examples/Service_Configurator/IPC-tests/server/Makefile.am new file mode 100644 index 00000000000..fbc788f8cd3 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Makefile.am @@ -0,0 +1,107 @@ +## 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) + + +## Makefile.Svc_Cfg_IPC_Server_Lib.am + +if !BUILD_ACE_FOR_TAO + +noinst_LTLIBRARIES = libIPC_Tests_Server.la + +libIPC_Tests_Server_la_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_BUILD_SVC_DLL + +libIPC_Tests_Server_la_SOURCES = \ + Handle_Broadcast.cpp \ + Handle_L_CODgram.cpp \ + Handle_L_Dgram.cpp \ + Handle_L_FIFO.cpp \ + Handle_L_Pipe.cpp \ + Handle_L_SPIPE.cpp \ + Handle_L_Stream.cpp \ + Handle_R_Stream.cpp \ + Handle_Thr_Stream.cpp \ + Handle_Timeout.cpp + +noinst_HEADERS = \ + Handle_Broadcast.h \ + Handle_Broadcast.inl \ + Handle_L_CODgram.h \ + Handle_L_CODgram.inl \ + Handle_L_Dgram.h \ + Handle_L_Dgram.inl \ + Handle_L_FIFO.h \ + Handle_L_FIFO.inl \ + Handle_L_Pipe.h \ + Handle_L_Pipe.inl \ + Handle_L_SPIPE.h \ + Handle_L_SPIPE.inl \ + Handle_L_Stream.h \ + Handle_L_Stream.inl \ + Handle_R_Stream.h \ + Handle_R_Stream.inl \ + Handle_Thr_Stream.h \ + Handle_Timeout.h \ + Handle_Timeout.inl + +endif !BUILD_ACE_FOR_TAO + +## Makefile.Svc_Cfg_IPC_Server_Test.am + +if !BUILD_ACE_FOR_TAO + +noinst_PROGRAMS = server_test + +server_test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +server_test_SOURCES = \ + server_test.cpp \ + Handle_Broadcast.h \ + Handle_Broadcast.inl \ + Handle_L_CODgram.h \ + Handle_L_CODgram.inl \ + Handle_L_Dgram.h \ + Handle_L_Dgram.inl \ + Handle_L_FIFO.h \ + Handle_L_FIFO.inl \ + Handle_L_Pipe.h \ + Handle_L_Pipe.inl \ + Handle_L_SPIPE.h \ + Handle_L_SPIPE.inl \ + Handle_L_Stream.h \ + Handle_L_Stream.inl \ + Handle_R_Dgram.h \ + Handle_R_Dgram.inl \ + Handle_R_Stream.h \ + Handle_R_Stream.inl \ + Handle_Thr_Stream.h \ + Handle_Timeout.h \ + Handle_Timeout.inl + +server_test_LDADD = \ + libIPC_Tests_Server.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/examples/Service_Configurator/IPC-tests/server/Svc_Cfg_IPC_Server.mpc b/ACE/examples/Service_Configurator/IPC-tests/server/Svc_Cfg_IPC_Server.mpc new file mode 100644 index 00000000000..c44b40c6e32 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/Svc_Cfg_IPC_Server.mpc @@ -0,0 +1,30 @@ +// -*- MPC -*- +// $Id$ + +project(*Lib) : acelib { + avoids += ace_for_tao + sharedname = IPC_Tests_Server + dynamicflags += ACE_BUILD_SVC_DLL + Source_Files { + Handle_Broadcast.cpp + Handle_L_CODgram.cpp + Handle_L_Dgram.cpp + Handle_L_FIFO.cpp + Handle_L_Pipe.cpp + Handle_L_SPIPE.cpp + Handle_L_Stream.cpp + Handle_R_Stream.cpp + Handle_Thr_Stream.cpp + Handle_Timeout.cpp + } +} + +project(*test) : aceexe { + avoids += ace_for_tao + exename = server_test + after += Svc_Cfg_IPC_Server_Lib + libs += IPC_Tests_Server + Source_Files { + server_test.cpp + } +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/server_test.cpp b/ACE/examples/Service_Configurator/IPC-tests/server/server_test.cpp new file mode 100644 index 00000000000..fe88a3eab8e --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/server_test.cpp @@ -0,0 +1,54 @@ +// $Id$ + +// The main test driver for the dynamically configured server. + +#include "ace/OS_NS_unistd.h" +#include "ace/Service_Config.h" +#include "ace/Reactor.h" +#include "ace/Log_Msg.h" +#include "ace/Signal.h" +#include "ace/Sig_Adapter.h" + +ACE_RCSID(server, server_test, "$Id$") + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + if (ACE_Service_Config::open (argc, + argv, + ACE_DEFAULT_LOGGER_KEY, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("ACE_Service_Config::open")), + -1); + + // 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 signals so we can shut down + // gracefully. + if (ACE_Reactor::instance ()->register_handler (sig_set, + &sa) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), ACE_TEXT ("register_handler")), + -1); + + // This makes the README demo even easier (for sighup). + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("pid = %d\n"), + ACE_OS::getpid ())); + + // Run forever, performing the configured services until we are shut + // down by a SIGINT/SIGQUIT signal. + + // We use this version of the event loop so that reconfigurations + // are triggered properly. + ACE_Reactor::run_event_loop (); + + return 0; +} diff --git a/ACE/examples/Service_Configurator/IPC-tests/server/svc.conf b/ACE/examples/Service_Configurator/IPC-tests/server/svc.conf new file mode 100644 index 00000000000..6f4e70a3ca5 --- /dev/null +++ b/ACE/examples/Service_Configurator/IPC-tests/server/svc.conf @@ -0,0 +1,19 @@ +# To configure different services, simply uncomment the appropriate lines in this file! +static ACE_Service_Manager "-d -p 3911" +dynamic Remote_Brdcast Service_Object * ./IPC_Tests_Server:remote_broadcast "-p 10001" +dynamic Remote_Stream Service_Object * ./IPC_Tests_Server:remote_stream "-p 20002" +dynamic Remote_Dgram Service_Object * ./IPC_Tests_Server:remote_dgram "-p 15001" +dynamic Timer_1 Service_Object * ./IPC_Tests_Server:timer_1 "-d 5 -i 1 -a 100" +dynamic Local_Stream Service_Object * ./IPC_Tests_Server:local_stream "-r /tmp/foo_stream" +dynamic Local_Pipe Service_Object * ./IPC_Tests_Server:local_pipe "-r /tmp/foo_pipe" +dynamic Local_Fifo Service_Object * ./IPC_Tests_Server:local_fifo "-r /tmp/foo_fifo" +dynamic Local_Dgram Service_Object * ./IPC_Tests_Server:local_dgram "-r /tmp/foo_dgram" +dynamic Local_CODgram Service_Object * ./IPC_Tests_Server:local_codgram "-r /tmp/foo_codgram" +dynamic Local_Spipe Service_Object * ./IPC_Tests_Server:local_spipe "-r /tmp/foo_spipe" +dynamic Remote_Thr_Stream Service_Object * ./IPC_Tests_Server:remote_thr_stream "-p 10001" +#suspend Remote_Stream +#resume Local_SPIPE +#resume Remote_Stream +#remove Remote_Stream +#remove Local_Stream + |