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)
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
,
30 ACE_TLI_Stream new_stream
;
33 "starting server at host %s\n",
34 addr
.get_host_name ()));
36 // Performs the iterative server activities
42 // Create a new ACE_TLI_Stream endpoint (note automatic restart
43 // if errno == EINTR).
44 if (peer_acceptor
.accept (new_stream
,
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
,
68 // Close new endpoint (listening endpoint stays open).
69 if (new_stream
.close () == -1)
78 int ACE_TMAIN (int, ACE_TCHAR
*[])
80 ACE_ERROR_RETURN ((LM_ERROR
,
81 "your platform isn't configured to support TLI\n"),
84 #endif /* ACE_HAS_TLI */