Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / SPIPE_SAP / NPServer.cpp
blob3afde969abe650291f9f2694f070423977453b61
1 #include "ace/SPIPE_Addr.h"
2 #include "ace/SPIPE_Acceptor.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_unistd.h"
8 #if defined (ACE_WIN32)
9 #define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\") ACE_TEXT (X)
10 #else
11 #define MAKE_PIPE_NAME(X) ACE_TEXT (X)
12 #endif
14 int
15 ACE_TMAIN (int /* argc */, ACE_TCHAR * /* argv */ [])
17 ACE_SPIPE_Acceptor acceptor;
18 ACE_SPIPE_Stream new_stream;
19 char buf[BUFSIZ];
20 int n;
21 const ACE_TCHAR *rendezvous = MAKE_PIPE_NAME ("acepipe");
23 // Initialize named pipe listener.
25 if (acceptor.open (ACE_SPIPE_Addr (rendezvous)) == -1)
26 ACE_ERROR_RETURN ((LM_ERROR,
27 ACE_TEXT ("%p\n"),
28 ACE_TEXT ("open")), 1);
30 for (;;)
32 ACE_DEBUG ((LM_DEBUG,
33 ACE_TEXT ("waiting for connection\n")));
35 // Accept a client connection.
36 if (acceptor.accept (new_stream, 0) == -1)
37 ACE_ERROR_RETURN ((LM_ERROR,
38 ACE_TEXT ("%p\n"),
39 ACE_TEXT ("accept")),
40 1);
42 ACE_DEBUG ((LM_DEBUG,
43 ACE_TEXT ("Accepted connection\n")));
45 while ((n = new_stream.recv (buf, sizeof buf)) > 0)
47 ACE_OS::fprintf (stderr,
48 "%s\n",
49 buf);
50 ACE_OS::write (ACE_STDOUT,
51 buf,
52 n);
55 if (n == -1)
57 ACE_DEBUG ((LM_DEBUG,
58 ACE_TEXT ("End of connection. Closing handle\n")));
59 new_stream.close ();
63 ACE_NOTREACHED(return 0);