Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / SOCK_SAP / FD-unserver.cpp
blob6fc1b3f4bf015160ac46f10f6471be23fc906acb
1 #include "ace/LSOCK_Acceptor.h"
2 #include "ace/LSOCK_Stream.h"
3 #include "ace/UNIX_Addr.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_main.h"
6 #include "ace/OS_NS_string.h"
7 #include "ace/OS_NS_stdio.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/OS_NS_stdlib.h"
12 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
14 // ACE_LSOCK Server
16 void
17 handle_client (ACE_LSOCK_Stream &stream)
19 char buf[BUFSIZ];
20 ACE_HANDLE handle;
22 // Retrieve the socket descriptor passed from the client.
24 if (stream.recv_handle (handle) == -1)
25 ACE_ERROR ((LM_ERROR, "%p", "recv_handle"));
27 ACE_DEBUG ((LM_DEBUG, "(%P|%t) ----------------------------------------\n"));
29 // Read data from client (correctly handles incomplete reads due to
30 // flow control).
32 for (ssize_t n;
33 (n = ACE_OS::read (handle, buf, sizeof buf)) > 0;
35 ACE_DEBUG ((LM_DEBUG, "%*s", n, buf));
37 ACE_OS::sprintf (buf, "%d", static_cast<int> (ACE_OS::getpid ()));
39 ACE_DEBUG ((LM_DEBUG, "(%s, %d) ----------------------------------------\n", buf, ACE_OS::strlen (buf)));
41 // Tell the client to shut down.
42 if (stream.send_n (buf, ACE_OS::strlen (buf)) == -1)
43 ACE_ERROR ((LM_ERROR, "%p", "send"));
45 // Close new endpoint (listening endpoint stays open).
46 if (stream.close () == -1)
47 ACE_ERROR ((LM_ERROR, "%p", "close"));
50 int
51 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
53 const ACE_TCHAR *rendezvous = argc > 1 ? argv[1] : ACE_DEFAULT_RENDEZVOUS;
54 // Create a server.
55 ACE_OS::unlink (rendezvous);
56 ACE_UNIX_Addr addr (rendezvous);
57 ACE_LSOCK_Acceptor peer_acceptor (addr);
58 ACE_LSOCK_Stream stream;
60 // Performs the concurrent server activities.
62 for (;;)
64 // Create a new ACE_SOCK_Stream endpoint.
65 if (peer_acceptor.accept (stream) == -1)
66 ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "accept"), -1);
68 ACE_DEBUG ((LM_DEBUG, "(%P|%t) accepted new connection\n"));
70 #if defined (VXWORKS)
71 handle_client (stream);
72 #else
73 switch (ACE_OS::fork (argv[0]))
75 case -1:
76 ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "fork"), -1);
77 /* NOTREACHED */
78 case 0:
79 ACE_LOG_MSG->sync (argv[0]);
80 handle_client (stream);
81 ACE_OS::exit (0);
82 default:
83 stream.close ();
85 #endif /* VXWORKS */
88 ACE_NOTREACHED (return 0;)
90 #else
91 int
92 ACE_TMAIN (int, ACE_TCHAR *[])
94 ACE_ERROR_RETURN ((LM_ERROR, "your platform doesn't not support UNIX domain sockets\n"), -1);
96 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */