Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / IPC_SAP / SOCK_SAP / FD-unclient.cpp
blob03e5131f917d99412a6ac278ce1d7e3cfd121fc4
1 #include "ace/OS_NS_fcntl.h"
2 #include "ace/LSOCK_Connector.h"
3 #include "ace/UNIX_Addr.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_main.h"
8 #if defined (ACE_HAS_MSG) && !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
9 // ACE_LSOCK Client.
11 int
12 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
14 const ACE_TCHAR *file_name = argc > 1 ? argv[1] : ACE_TEXT ("./local_data");
15 const ACE_TCHAR *rendezvous = argc > 2 ? argv[2] : ACE_DEFAULT_RENDEZVOUS;
17 ACE_LSOCK_Stream cli_stream;
18 ACE_UNIX_Addr addr (rendezvous);
20 // Establish the connection with server.
21 ACE_LSOCK_Connector connector;
23 if (connector.connect (cli_stream, addr) == -1)
24 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p"), ACE_TEXT ("connect")), -1);
26 ACE_HANDLE handle = ACE_OS::open (file_name, O_RDONLY);
28 if (handle == ACE_INVALID_HANDLE)
29 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p"), ACE_TEXT ("open")), -1);
31 // Send handle to server (correctly handles incomplete writes).
32 if (cli_stream.send_handle (handle) == -1)
33 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p"), ACE_TEXT ("send")), -1);
35 char buf[BUFSIZ];
36 ssize_t n = cli_stream.recv (buf, sizeof buf);
38 if (n == -1)
39 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p"), ACE_TEXT ("recv")), -1);
40 else if (n == 0)
41 //FUZZ: disable check_for_lack_ACE_OS
42 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server shutdown (bug in kernel?)\n")));
43 //FUZZ: enable check_for_lack_ACE_OS
44 else
45 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server %*C shutdown\n"), n, buf));
47 // Explicitly close the connection.
48 if (cli_stream.close () == -1)
49 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p"), ACE_TEXT ("close")), -1);
51 return 0;
53 #else
54 int ACE_TMAIN (int, ACE_TCHAR *[])
56 ACE_ERROR_RETURN ((LM_ERROR,
57 ACE_TEXT ("your platform must support sendmsg/recvmsg to run this test\n")), -1);
59 #endif /* ACE_HAS_MSG */