Merge pull request #2317 from jwillemsen/jwi-deleteop
[ACE_TAO.git] / ACE / examples / IPC_SAP / SPIPE_SAP / NPClient.cpp
blob6341ccc8d9889febda3830de5c761a3e4a360fea
1 #include "ace/OS_main.h"
2 #include "ace/SPIPE_Addr.h"
3 #include "ace/SPIPE_Connector.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/Truncate.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_stdlib.h"
8 #include "ace/OS_Memory.h"
11 #if defined (ACE_WIN32)
12 #define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\") ACE_TEXT (X)
13 #else
14 #define MAKE_PIPE_NAME(X) ACE_TEXT (X)
15 #endif
17 const int DEFAULT_SIZE = 8;
18 const int DEFAULT_COUNT = 10000;
20 int
21 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
23 int size = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_SIZE;
24 int iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : DEFAULT_COUNT;
25 char *buf;
27 ACE_NEW_RETURN (buf,
28 char[size],
29 1);
31 const ACE_TCHAR *rendezvous = MAKE_PIPE_NAME ("acepipe");
33 ACE_SPIPE_Stream cli_stream;
34 ACE_SPIPE_Connector con;
35 int i;
37 if (con.connect (cli_stream,
38 ACE_SPIPE_Addr (rendezvous)) == -1)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 ACE_TEXT ("%p\n"),
41 rendezvous),
42 -1);
44 ACE_OS::strcpy (buf, "hello");
45 size = ACE_Utils::truncate_cast<int> (ACE_OS::strlen (buf) + 1);
47 for (i = 0; i < iterations; i++)
48 if (cli_stream.send (buf, size) != size)
49 ACE_ERROR_RETURN ((LM_ERROR,
50 ACE_TEXT ("%p\n"),
51 ACE_TEXT ("putmsg")),
52 -1);
54 if (cli_stream.close () == -1)
55 ACE_ERROR_RETURN ((LM_ERROR,
56 ACE_TEXT ("%p\n"),
57 ACE_TEXT ("close")),
58 -1);
59 return 0;