diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:30 +0000 |
commit | c44379cc7d9c7aa113989237ab0f56db12aa5219 (patch) | |
tree | 66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp | |
parent | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff) | |
download | ATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz |
Repo restructuring
Diffstat (limited to 'ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp')
-rw-r--r-- | ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp b/ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp new file mode 100644 index 00000000000..4055a2cc02d --- /dev/null +++ b/ACE/examples/IPC_SAP/SPIPE_SAP/NPServer.cpp @@ -0,0 +1,67 @@ +// $Id$ + +#include "ace/SPIPE_Addr.h" +#include "ace/SPIPE_Acceptor.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_unistd.h" + +ACE_RCSID(SPIPE_SAP, NPServer, "$Id$") + +#if defined (ACE_WIN32) +#define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\") ACE_TEXT (X) +#else +#define MAKE_PIPE_NAME(X) ACE_TEXT (X) +#endif + +int +ACE_TMAIN (int /* argc */, ACE_TCHAR * /* argv */ []) +{ + ACE_SPIPE_Acceptor acceptor; + ACE_SPIPE_Stream new_stream; + char buf[BUFSIZ]; + int n; + const ACE_TCHAR *rendezvous = MAKE_PIPE_NAME ("acepipe"); + + // Initialize named pipe listener. + + if (acceptor.open (ACE_SPIPE_Addr (rendezvous)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("open")), 1); + + for (;;) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("waiting for connection\n"))); + + // Accept a client connection. + if (acceptor.accept (new_stream, 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("accept")), + 1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Accepted connection\n"))); + + while ((n = new_stream.recv (buf, sizeof buf)) > 0) + { + ACE_OS::fprintf (stderr, + "%s\n", + buf); + ACE_OS::write (ACE_STDOUT, + buf, + n); + } + + if (n == -1) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("End of connection. Closing handle\n"))); + new_stream.close (); + } + } + + ACE_NOTREACHED(return 0); +} |