1 #include "ace/TLI_Connector.h"
2 #include "ace/INET_Addr.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/OS_NS_unistd.h"
6 #include "ace/Time_Value.h"
9 #if defined (ACE_HAS_TLI)
13 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
15 const ACE_TCHAR
*host
= argc
> 1 ? argv
[1] : ACE_DEFAULT_SERVER_HOST
;
16 u_short r_port
= argc
> 2 ? ACE_OS::atoi (argv
[2]) : ACE_DEFAULT_SERVER_PORT
;
17 int timeout
= argc
> 3 ? ACE_OS::atoi (argv
[3]) : ACE_DEFAULT_TIMEOUT
;
18 u_short l_port
= argc
> 4 ? ACE_OS::atoi (argv
[4]) : ACE_DEFAULT_LOCAL_PORT
;
22 ACE_TLI_Stream cli_stream
;
24 ACE_INET_Addr
remote_addr (r_port
, host
);
25 ACE_INET_Addr
local_addr (l_port
);
27 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("starting non-blocking connect\n")));
29 // Initiate timed, non-blocking connection with server.
30 ACE_TLI_Connector con
;
32 if (con
.connect (cli_stream
,
34 (ACE_Time_Value
*) &ACE_Time_Value::zero
,
38 if (errno
!= EWOULDBLOCK
)
39 ACE_ERROR_RETURN ((LM_ERROR
,
41 ACE_TEXT ("connection failed")),
44 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("starting timed connect\n")));
46 // Check if non-blocking connection is in progress, and wait up
47 // to timeout seconds for it to complete.
48 ACE_Time_Value
tv (timeout
);
50 if (con
.complete (cli_stream
,
53 ACE_ERROR_RETURN ((LM_ERROR
,
55 ACE_TEXT ("connection failed")),
59 ACE_TEXT ("connected to %s\n"),
60 remote_addr
.get_host_name ()));
63 // Send data to server (correctly handles "incomplete writes").
66 (r_bytes
= ACE_OS::read (ACE_STDIN
, buf
, sizeof buf
)) > 0;
68 if (cli_stream
.send_n (buf
,
71 ACE_ERROR_RETURN ((LM_ERROR
,
76 // Explicitly close the connection.
77 if (cli_stream
.close () == -1)
78 ACE_ERROR_RETURN ((LM_ERROR
,
85 int ACE_TMAIN (int, ACE_TCHAR
*[])
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 ACE_TEXT ("your platform isn't configured to support TLI\n")),
91 #endif /* ACE_HAS_TLI */