This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 2ab367a Simplify AprEndpoint socket bind for all platforms 2ab367a is described below commit 2ab367ad34c4381f1daac8e997883a5dbe472e99 Author: Michael Osipov <micha...@apache.org> AuthorDate: Sat May 22 13:36:57 2021 +0200 Simplify AprEndpoint socket bind for all platforms * Unconditionally use APR_UNSPEC on all platforms and especially on *BSD which runs fine on IPv4 and IPv6 hosts. * Apply IPV6_V6ONLY only if libapr has been compiled with IPv6 support and the socket address is of family APR_INET6. This mimics the behavior of HTTPd's listen.c for apr_sockaddr_info_get() along with open_listeners() and make_sock() with IPV6_V6ONLY flag. --- java/org/apache/tomcat/util/net/AprEndpoint.java | 16 ++++------------ test/org/apache/tomcat/util/net/TestXxxEndpoint.java | 6 +----- webapps/docs/changelog.xml | 3 +++ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index 99f8b7c..9de8c0c 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -336,16 +336,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB if (getAddress() != null) { hostname = getAddress().getHostAddress(); } - family = Socket.APR_INET; - if (Library.APR_HAVE_IPV6) { - if (hostname == null) { - if (!OS.IS_BSD) { - family = Socket.APR_UNSPEC; - } - } else if (hostname.indexOf(':') >= 0) { - family = Socket.APR_UNSPEC; - } - } + family = Socket.APR_UNSPEC; } long sockAddress = Address.info(hostname, family, getPortWithOffset(), 0, rootPool); @@ -355,13 +346,14 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB serverSock = Socket.create(family, Socket.SOCK_STREAM, 0, rootPool); } else { - serverSock = Socket.create(Address.getInfo(sockAddress).family, + int saFamily = Address.getInfo(sockAddress).family; + serverSock = Socket.create(saFamily, Socket.SOCK_STREAM, Socket.APR_PROTO_TCP, rootPool); if (OS.IS_UNIX) { Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1); } - if (Library.APR_HAVE_IPV6) { + if (Library.APR_HAVE_IPV6 && saFamily == Socket.APR_INET6) { if (getIpv6v6only()) { Socket.optSet(serverSock, Socket.APR_IPV6_V6ONLY, 1); } else { diff --git a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java index f54723b..6ee9a09 100644 --- a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java +++ b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java @@ -65,11 +65,7 @@ public class TestXxxEndpoint extends TomcatBaseTest { String address = InetAddress.getByName("localhost").getHostAddress(); // Create the APR address that will be bound - int family = Socket.APR_INET; - if (Library.APR_HAVE_IPV6) { - if (!OS.IS_BSD && !OS.IS_WIN32 && !OS.IS_WIN64) - family = Socket.APR_UNSPEC; - } + int family = Socket.APR_UNSPEC; long inetAddress = 0; try { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index c86d65a..1855d4a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -167,6 +167,9 @@ <code>NioBlockingSelector</code> that could cause a delay to select operations. (markt) </fix> + <update> + Simplify AprEndpoint socket bind for all platforms. (michaelo) + </update> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org