Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / SOCK_SAP / CPP-unclient.cpp
blobafd85f1bcf0434ca973cd05bcfcca075cb039df4
1 // ACE_LSOCK Client.
3 #include "ace/LSOCK_Connector.h"
4 #include "ace/UNIX_Addr.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_main.h"
7 #include "ace/OS_NS_unistd.h"
10 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
11 int
12 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
14 const ACE_TCHAR *rendezvous = argc > 1 ? argv[1] : ACE_DEFAULT_RENDEZVOUS;
15 char buf[BUFSIZ];
17 ACE_LSOCK_Stream cli_stream;
18 ACE_LSOCK_Connector con;
19 ACE_UNIX_Addr remote_addr (rendezvous);
21 // Establish the connection with server.
22 if (con.connect (cli_stream, remote_addr) == -1)
23 ACE_ERROR_RETURN ((LM_ERROR,
24 ACE_TEXT ("%p\n"),
25 ACE_TEXT ("connect")),
26 1);
28 // Send data to server (correctly handles "incomplete writes").
30 for (int r_bytes;
31 (r_bytes = ACE_OS::read (ACE_STDIN, buf, sizeof buf)) > 0;
33 if (cli_stream.send_n (buf, r_bytes) == -1)
34 ACE_ERROR_RETURN ((LM_ERROR,
35 ACE_TEXT ("%p\n"),
36 ACE_TEXT ("send_n")),
37 1);
39 // Explicitly close the writer-side of the connection.
40 if (cli_stream.close_writer () == -1)
41 ACE_ERROR_RETURN ((LM_ERROR,
42 ACE_TEXT ("%p\n"),
43 ACE_TEXT ("close_writer")),
44 1);
46 // Wait for handshake with server.
47 if (cli_stream.recv_n (buf, 1) != 1)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 ACE_TEXT ("%p\n"),
50 ACE_TEXT ("recv_n")),
51 1);
53 // Close the connection completely.
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;
61 #else
62 int
63 ACE_TMAIN (int, ACE_TCHAR *[])
65 ACE_ERROR_RETURN ((LM_ERROR,
66 "this platform does not support UNIX-domain sockets\n"), -1);
68 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */