This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new cf8b603 Simplify AprEndpoint socket bind for all platforms
cf8b603 is described below
commit cf8b6035ef7a3349a6fbf971dbbf73263a030036
Author: Michael Osipov <[email protected]>
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 b03c797..3e3b2c9 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -304,27 +304,19 @@ public class AprEndpoint extends AbstractEndpoint<Long>
implements SNICallBack {
if (getAddress() != null) {
addressStr = getAddress().getHostAddress();
}
- int family = Socket.APR_INET;
- if (Library.APR_HAVE_IPV6) {
- if (addressStr == null) {
- if (!OS.IS_BSD) {
- family = Socket.APR_UNSPEC;
- }
- } else if (addressStr.indexOf(':') >= 0) {
- family = Socket.APR_UNSPEC;
- }
- }
+ int family = Socket.APR_UNSPEC;
long inetAddress = Address.info(addressStr, family,
getPort(), 0, rootPool);
// Create the APR server socket
- serverSock = Socket.create(Address.getInfo(inetAddress).family,
+ int saFamily = Address.getInfo(inetAddress).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 ab08bf7..c27f588 100644
--- a/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
+++ b/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
@@ -60,11 +60,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 9958e20..2a6e035 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -162,6 +162,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: [email protected]
For additional commands, e-mail: [email protected]