Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / TLI_SAP / CPP-server.cpp
blob7aa26e1ee48fd36af7133f52f23aa72505802418
1 #include "ace/TLI_Acceptor.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/OS_NS_stdlib.h"
4 #include "ace/OS_NS_unistd.h"
7 #if defined (ACE_HAS_TLI)
8 // ACE_TLI Server
10 int
11 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
13 u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
14 ACE_Time_Value timeout (argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_TIMEOUT);
16 // Create a server address.
17 ACE_INET_Addr addr (port);
19 // Create a server, reuse the addr.
20 ACE_TLI_Acceptor peer_acceptor;
22 // Not sure why but reuse_addr set to true/1 causes problems for
23 // FORE/XTI/ATM - this is now handled in ACE_TLI_Acceptor::open()
24 if (peer_acceptor.open (addr, 1) == -1)
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "%p\n",
27 "open"),
28 -1);
30 ACE_TLI_Stream new_stream;
32 ACE_DEBUG ((LM_DEBUG,
33 "starting server at host %s\n",
34 addr.get_host_name ()));
36 // Performs the iterative server activities
38 for (;;)
40 char buf[BUFSIZ];
42 // Create a new ACE_TLI_Stream endpoint (note automatic restart
43 // if errno == EINTR).
44 if (peer_acceptor.accept (new_stream,
45 &addr,
46 &timeout) == -1)
48 ACE_ERROR ((LM_ERROR,
49 "%p\n",
50 "accept"));
51 continue;
54 ACE_DEBUG ((LM_DEBUG,
55 "client %s connected\n",
56 addr.get_host_name ()));
58 // Read data from client (terminate on error).
60 for (int r_bytes; (r_bytes = new_stream.recv (buf, sizeof buf)) > 0; )
61 if (ACE_OS::write (ACE_STDOUT,
62 buf,
63 r_bytes) != r_bytes)
64 ACE_ERROR ((LM_ERROR,
65 "%p\n",
66 "ACE::send_n"));
68 // Close new endpoint (listening endpoint stays open).
69 if (new_stream.close () == -1)
70 ACE_ERROR ((LM_ERROR,
71 "%p\n",
72 "close"));
74 /* NOTREACHED */
75 return 0;
77 #else
78 int ACE_TMAIN (int, ACE_TCHAR *[])
80 ACE_ERROR_RETURN ((LM_ERROR,
81 "your platform isn't configured to support TLI\n"),
82 1);
84 #endif /* ACE_HAS_TLI */