Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / SPIPE_SAP / consumer_read.cpp
blob392513f92b2bd621a573e6e1f1488ae5a635c910
1 #include "ace/OS_main.h"
2 #include "ace/SPIPE_Addr.h"
3 #include "ace/SPIPE_Acceptor.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/Time_Value.h"
10 #if defined (ACE_HAS_STREAM_PIPES)
12 #include "shared.h"
14 int
15 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
17 ACE_SPIPE_Acceptor peer_acceptor;
18 ACE_SPIPE_Stream new_stream;
19 char buf[BUFSIZ];
20 int n;
22 // Wait up to ACE_DEFAULT_TIMEOUT seconds to accept connection.
23 ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
25 if (argc > 1)
26 rendezvous = argv[1];
28 ACE_OS::unlink (rendezvous);
29 ACE_OS::fdetach (ACE_TEXT_ALWAYS_CHAR (rendezvous));
31 if (peer_acceptor.open (ACE_SPIPE_Addr (rendezvous)) == -1)
32 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), 1);
34 ACE_DEBUG ((LM_DEBUG, "waiting for connection\n"));
36 if (peer_acceptor.accept (new_stream, 0, &timeout) == -1)
37 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "accept"), 1);
39 ACE_DEBUG ((LM_DEBUG, "accepted\n"));
41 while ((n = new_stream.recv (buf, sizeof buf)) > 0)
42 ACE_OS::write (ACE_STDOUT, buf, n);
44 return 0;
46 #else
47 #include <stdio.h>
48 int ACE_TMAIN (int, ACE_TCHAR *[])
50 ACE_OS::fprintf (stderr, "This feature is not supported\n");
51 return 0;
53 #endif /* ACE_HAS_STREAM_PIPES */