2 //=============================================================================
4 * @file SOCK_Acceptor_Test.cpp
6 * This is a test of the <ACE_SOCK_Acceptor> class.
8 * @author Steve Huston <shuston@riverace.com>
10 //=============================================================================
12 #include "test_config.h"
13 #include "ace/OS_NS_unistd.h"
14 #include "ace/OS_NS_sys_wait.h"
15 #include "ace/Time_Value.h"
16 #include "ace/SOCK_Connector.h"
17 #include "ace/SOCK_Acceptor.h"
20 test_accept (ACE_Addr listen_addr
, int v6_only
)
25 ACE_TEXT ("(%P|%t) starting listen, ipv6-only %d\n"),
27 // Bind listener to any port and then find out what the port was.
28 ACE_SOCK_Acceptor acceptor
;
29 ACE_INET_Addr listening_at
;
30 if (acceptor
.open (listen_addr
,
36 || acceptor
.get_local_addr (listening_at
) == -1)
37 ACE_ERROR_RETURN ((LM_ERROR
,
38 ACE_TEXT ("(%P|%t) %p\n"),
41 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) listening at port %d\n"),
42 listening_at
.get_port_number ()));
44 // Try IPv4 and, if v6 is available, v6. If v6-capable and v6-only
45 // is selected, v4 should NOT work and v6 should. If not v6-capable
46 // just try v4 and it should work regardless of v6-only.
47 ACE_SOCK_Connector connector
;
49 ACE_INET_Addr
v4_addr (listening_at
.get_port_number(),
52 ACE_SOCK_Stream v4_stream
;
53 bool v4_ok
= (connector
.connect (v4_stream
, v4_addr
) == 0);
55 ACE_TEXT ("v4 connect %s\n"),
56 v4_ok
? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
59 #if defined (ACE_HAS_IPV6)
60 ACE_INET_Addr
v6_addr (listening_at
.get_port_number(),
63 ACE_SOCK_Stream v6_stream
;
64 bool v6_ok
= (connector
.connect (v6_stream
, v6_addr
) == 0);
66 ACE_TEXT ("v6 connect %s\n"),
67 v6_ok
? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
72 if (!v6_only
&& !v4_ok
)
77 status
= v4_ok
? 0 : 1;
78 #endif /* ACE_HAS_IPV6 */
84 run_main (int, ACE_TCHAR
*[])
86 ACE_START_TEST (ACE_TEXT ("SOCK_Acceptor_Test"));
90 if (test_accept (ACE_Addr::sap_any
, 1) != 0)
92 if (test_accept (ACE_Addr::sap_any
, 0) != 0)