diff options
author | Steve Huston <shuston@riverace.com> | 2018-02-28 18:54:05 -0500 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2018-02-28 18:54:05 -0500 |
commit | 296d82b7a2fcff3d9cc704039a25fb0189669c17 (patch) | |
tree | 93218f40ee176b6b6ccfa3dd1a4de9e30096b888 | |
parent | 222b5db197187810b1fd1b54aad9fc8dc0ffd774 (diff) | |
download | ATCD-296d82b7a2fcff3d9cc704039a25fb0189669c17.tar.gz |
Add UDP changes and test program
-rw-r--r-- | ACE/ace/SOCK_Dgram.cpp | 41 | ||||
-rw-r--r-- | ACE/ace/SOCK_Dgram.h | 16 | ||||
-rw-r--r-- | ACE/tests/SOCK_Acceptor_Test.cpp | 101 | ||||
-rw-r--r-- | ACE/tests/run_test.lst | 1 | ||||
-rw-r--r-- | ACE/tests/tests.mpc | 7 |
5 files changed, 152 insertions, 14 deletions
diff --git a/ACE/ace/SOCK_Dgram.cpp b/ACE/ace/SOCK_Dgram.cpp index 2d3c5e0dd0f..3726fb24398 100644 --- a/ACE/ace/SOCK_Dgram.cpp +++ b/ACE/ace/SOCK_Dgram.cpp @@ -116,13 +116,28 @@ ACE_SOCK_Dgram::recv (iovec *io_vec, int ACE_SOCK_Dgram::shared_open (const ACE_Addr &local, - int protocol_family) + int protocol_family, + int ipv6_only) { ACE_TRACE ("ACE_SOCK_Dgram::shared_open"); bool error = false; +#if !defined (ACE_HAS_IPV6) || (!defined (IPPROTO_IPV6) || !defined (IPV6_V6ONLY)) + ACE_UNUSED_ARG (ipv6_only); +#endif /* !defined (ACE_HAS_IPV6) || (!defined (IPPROTO_IPV6) || !defined (IPV6_V6ONLY)) */ if (local == ACE_Addr::sap_any) { +#if defined (ACE_HAS_IPV6) && defined (IPPROTO_IPV6) && defined (IPV6_V6ONLY) + int setting = !!ipv6_only; + if (-1 == ACE_OS::setsockopt (this->get_handle (), + IPPROTO_IPV6, + IPV6_V6ONLY, + (char *)&setting, + sizeof (setting))) + error = true; + else +#endif /* ACE_HAS_IPV6 && IPPROTO_IPV6 && IPV6_V6ONLY */ + if (protocol_family == PF_INET #if defined (ACE_HAS_IPV6) || protocol_family == PF_INET6 @@ -153,7 +168,8 @@ ACE_SOCK_Dgram::open (const ACE_Addr &local, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, - int reuse_addr) + int reuse_addr, + int ipv6_only) { if (ACE_SOCK::open (SOCK_DGRAM, protocol_family, @@ -164,7 +180,8 @@ ACE_SOCK_Dgram::open (const ACE_Addr &local, reuse_addr) == -1) return -1; else if (this->shared_open (local, - protocol_family) == -1) + protocol_family, + ipv6_only) == -1) return -1; else return 0; @@ -176,7 +193,8 @@ int ACE_SOCK_Dgram::open (const ACE_Addr &local, int protocol_family, int protocol, - int reuse_addr) + int reuse_addr, + int ipv6_only) { ACE_TRACE ("ACE_SOCK_Dgram::open"); @@ -198,7 +216,8 @@ ACE_SOCK_Dgram::open (const ACE_Addr &local, return -1; else return this->shared_open (local, - protocol_family); + protocol_family, + ipv6_only); } // Here's the general-purpose constructor used by a connectionless @@ -207,14 +226,16 @@ ACE_SOCK_Dgram::open (const ACE_Addr &local, ACE_SOCK_Dgram::ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family, int protocol, - int reuse_addr) + int reuse_addr, + int ipv6_only) { ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram"); if (this->open (local, protocol_family, protocol, - reuse_addr) == -1) + reuse_addr, + ipv6_only) == -1) ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_SOCK_Dgram"))); @@ -226,7 +247,8 @@ ACE_SOCK_Dgram::ACE_SOCK_Dgram (const ACE_Addr &local, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, - int reuse_addr) + int reuse_addr, + int ipv6_only) { ACE_TRACE ("ACE_SOCK_Dgram::ACE_SOCK_Dgram"); if (this->open (local, @@ -235,7 +257,8 @@ ACE_SOCK_Dgram::ACE_SOCK_Dgram (const ACE_Addr &local, protocolinfo, g, flags, - reuse_addr) == -1) + reuse_addr, + ipv6_only) == -1) ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_SOCK_Dgram"))); diff --git a/ACE/ace/SOCK_Dgram.h b/ACE/ace/SOCK_Dgram.h index 1b8f9f8be42..457962f8acf 100644 --- a/ACE/ace/SOCK_Dgram.h +++ b/ACE/ace/SOCK_Dgram.h @@ -43,7 +43,8 @@ public: ACE_SOCK_Dgram (const ACE_Addr &local, int protocol_family = ACE_PROTOCOL_FAMILY_INET, int protocol = 0, - int reuse_addr = 0); + int reuse_addr = 0, + int ipv6_only = 0); /** * This is a QoS-enabed method for initiating a socket dgram that @@ -56,14 +57,16 @@ public: ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g = 0, u_long flags = 0, - int reuse_addr = 0); + int reuse_addr = 0, + int ipv6_only = 0); /// This is a BSD-style method (i.e., no QoS) for initiating a socket /// dgram that will accept datagrams at the <local> address. int open (const ACE_Addr &local, int protocol_family = ACE_PROTOCOL_FAMILY_INET, int protocol = 0, - int reuse_addr = 0); + int reuse_addr = 0, + int ipv6_only = 0); /** * This is a QoS-enabed method for initiating a socket dgram that @@ -76,7 +79,8 @@ public: ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g = 0, u_long flags = 0, - int reuse_addr = 0); + int reuse_addr = 0, + int ipv6_only = 0); /// Default dtor. ~ACE_SOCK_Dgram (void); @@ -204,7 +208,9 @@ public: protected: /// Open is shared by this and by <LSOCK_Dgram>. - int shared_open (const ACE_Addr &local, int protocol_family); + int shared_open (const ACE_Addr &local, + int protocol_family, + int ipv6_only = 0); /// Create a multicast addr/if pair, in format useful for system calls. /// If mreq param is NULL, just verify the passed addr/interface specs. diff --git a/ACE/tests/SOCK_Acceptor_Test.cpp b/ACE/tests/SOCK_Acceptor_Test.cpp new file mode 100644 index 00000000000..84835a4eec5 --- /dev/null +++ b/ACE/tests/SOCK_Acceptor_Test.cpp @@ -0,0 +1,101 @@ + +//============================================================================= +/** + * @file SOCK_Acceptor_Test.cpp + * + * $Id$ + * + * This is a test of the <ACE_SOCK_Acceptor> class. + * + * @author Steve Huston <shuston@riverace.com> + */ +//============================================================================= + + +#include "test_config.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_sys_wait.h" +#include "ace/Time_Value.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Acceptor.h" + + +static int +test_accept (ACE_Addr listen_addr, int v6_only) +{ + int status = 0; + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) starting listen, ipv6-only %d\n"), + v6_only)); + // Bind listener to any port and then find out what the port was. + ACE_SOCK_Acceptor acceptor; + ACE_INET_Addr listening_at; + if (acceptor.open (listen_addr, + 0, + PF_UNSPEC, + ACE_DEFAULT_BACKLOG, + 0, + v6_only) == -1 + || acceptor.get_local_addr (listening_at) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("open")), + -1); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) listening at port %d\n"), + listening_at.get_port_number ())); + + // Try IPv4 and, if v6 is available, v6. If v6-capable and v6-only + // is selected, v4 should NOT work and v6 should. If not v6-capable + // just try v4 and it should work regardless of v6-only. + ACE_SOCK_Connector connector; + + ACE_INET_Addr v4_addr (listening_at.get_port_number(), + ACE_LOCALHOST, + PF_INET); + ACE_SOCK_Stream v4_stream; + bool v4_ok = (connector.connect (v4_stream, v4_addr) == 0); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("v4 connect %s\n"), + v4_ok ? ACE_TEXT ("OK") : ACE_TEXT ("FAIL"))); + v4_stream.close(); + +#if defined (ACE_HAS_IPV6) + ACE_INET_Addr v6_addr (listening_at.get_port_number(), + ACE_IPV6_LOCALHOST, + PF_INET6); + ACE_SOCK_Stream v6_stream; + bool v6_ok = (connector.connect (v6_stream, v6_addr) == 0); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("v6 connect %s\n"), + v6_ok ? ACE_TEXT ("OK") : ACE_TEXT ("FAIL"))); + v6_stream.close(); + + if (v6_only && v4_ok) + status = 1; + if (!v6_only && !v4_ok) + status = 1; + if (!v6_ok) + status = 1; +#else + status = v4_ok ? 0 : 1; +#endif /* ACE_HAS_IPV6 */ + acceptor.close (); + return status; +} + +int +run_main (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("SOCK_Acceptor_Test")); + + int status = 0; + + if (test_accept (ACE_Addr::sap_any, 1) != 0) + status = 1; + if (test_accept (ACE_Addr::sap_any, 0) != 0) + status = 1; + + ACE_END_TEST; + return status; +} diff --git a/ACE/tests/run_test.lst b/ACE/tests/run_test.lst index 47fbaa95c58..9bcddbf6827 100644 --- a/ACE/tests/run_test.lst +++ b/ACE/tests/run_test.lst @@ -217,6 +217,7 @@ Reverse_Lock_Test RW_Process_Mutex_Test: !VxWorks !ACE_FOR_TAO !PHARLAP !Cygwin Sendfile_Test: !QNX !NO_NETWORK !VxWorks !LabVIEW_RT Signal_Test: !VxWorks !Cygwin +SOCK_Acceptor_Test: !NO_NETWORK SOCK_Connector_Test: !NO_NETWORK SOCK_Netlink_Test: !ACE_FOR_TAO SOCK_Send_Recv_Test: !NO_NETWORK diff --git a/ACE/tests/tests.mpc b/ACE/tests/tests.mpc index 6a567598f25..01a12f3c1f7 100644 --- a/ACE/tests/tests.mpc +++ b/ACE/tests/tests.mpc @@ -1626,6 +1626,13 @@ project(Singleton Restart Test) : aceexe { } } +project(SOCK Acceptor_Test) : acetest { + exename = SOCK_Acceptor_Test + Source_Files { + SOCK_Acceptor_Test.cpp + } +} + project(SOCK Test) : acetest { exename = SOCK_Test Source_Files { |