Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / SPIPE_SAP / producer_msg.cpp
blobfbb9a7e06c5cac2fe5e9d3c91d40b5ea785c67f2
1 #include "ace/OS_main.h"
2 #include "ace/OS_Memory.h"
3 #include "ace/SPIPE_Addr.h"
4 #include "ace/SPIPE_Connector.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_stdio.h"
7 #include "ace/OS_NS_stdlib.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/Time_Value.h"
12 #if defined (ACE_HAS_STREAM_PIPES)
14 #include "shared.h"
16 const int DEFAULT_SIZE = 4 * 1024;
17 const int DEFAULT_COUNT = 100;
19 int
20 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
22 int size = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_SIZE;
23 int iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_COUNT;
24 char *buf;
26 ACE_NEW_RETURN (buf, char[size], -1);
28 if (argc > 3)
29 rendezvous = argv[3];
31 ACE_SPIPE_Stream cli_stream;
32 ACE_SPIPE_Connector con;
33 int i;
35 if (con.connect (cli_stream, ACE_SPIPE_Addr (rendezvous)) == -1)
36 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", rendezvous), 1);
38 for (i = 0; i < size; i++)
39 buf[i] = 'a';
41 ACE_Str_Buf buffer (buf, size);
43 for (i = 0; i < iterations; i++)
44 if (cli_stream.send ((ACE_Str_Buf *) 0,
45 &buffer,
47 MSG_BAND) == -1)
48 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), 1);
50 if (cli_stream.close () == -1)
51 ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), 1);
53 delete buf;
54 return 0;
56 #else
57 #include <stdio.h>
58 int ACE_TMAIN (int, ACE_TCHAR *[])
60 ACE_OS::fprintf (stderr, "This feature is not supported\n");
61 return 0;
63 #endif /* ACE_HAS_STREAM_PIPES */