Author: markt Date: Tue Dec 13 16:48:40 2016 New Revision: 1774052 URL: http://svn.apache.org/viewvc?rev=1774052&view=rev Log: Fix unlock delay on OSX if airdrop is enabled.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java?rev=1774052&r1=1774051&r2=1774052&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Tue Dec 13 16:48:40 2016 @@ -21,6 +21,7 @@ import java.io.OutputStreamWriter; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.NetworkInterface; +import java.net.SocketException; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -785,24 +786,7 @@ public abstract class AbstractEndpoint<S } try { - if (localAddress.getAddress().isAnyLocalAddress()) { - // Need a local address of the same type (IPv4 or IPV6) as the - // configured bind address since the connector may be configured - // to not map between types. - Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); - while (unlockAddress == null && networkInterfaces.hasMoreElements()) { - NetworkInterface networkInterface = networkInterfaces.nextElement(); - Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); - while (unlockAddress == null && inetAddresses.hasMoreElements()) { - InetAddress inetAddress = inetAddresses.nextElement(); - if (localAddress.getAddress().getClass().isAssignableFrom(inetAddress.getClass())) { - unlockAddress = new InetSocketAddress(inetAddress, localAddress.getPort()); - } - } - } - } else { - unlockAddress = localAddress; - } + unlockAddress = getUnlockAddress(localAddress); try (java.net.Socket s = new java.net.Socket()) { int stmo = 2 * 1000; @@ -851,6 +835,52 @@ public abstract class AbstractEndpoint<S } } + + private static InetSocketAddress getUnlockAddress(InetSocketAddress localAddress) throws SocketException { + if (localAddress.getAddress().isAnyLocalAddress()) { + // Need a local address of the same type (IPv4 or IPV6) as the + // configured bind address since the connector may be configured + // to not map between types. + InetAddress loopbackUnlockAddress = null; + InetAddress linkLocalUnlockAddress = null; + + Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface networkInterface = networkInterfaces.nextElement(); + Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); + while (inetAddresses.hasMoreElements()) { + InetAddress inetAddress = inetAddresses.nextElement(); + if (localAddress.getAddress().getClass().isAssignableFrom(inetAddress.getClass())) { + if (inetAddress.isLoopbackAddress()) { + if (loopbackUnlockAddress == null) { + loopbackUnlockAddress = inetAddress; + } + } else if (inetAddress.isLinkLocalAddress()) { + if (linkLocalUnlockAddress == null) { + linkLocalUnlockAddress = inetAddress; + } + } else { + // Use a non-link local, non-loop back address by default + return new InetSocketAddress(inetAddress, localAddress.getPort()); + } + } + } + } + // Prefer loop back over link local since on some platforms (e.g. + // OSX) some link local addresses are not included when listening on + // all local addresses. + if (loopbackUnlockAddress != null) { + return new InetSocketAddress(loopbackUnlockAddress, localAddress.getPort()); + } + if (linkLocalUnlockAddress != null) { + return new InetSocketAddress(linkLocalUnlockAddress, localAddress.getPort()); + } + return null; + } else { + return localAddress; + } + } + // ---------------------------------------------- Request processing methods Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1774052&r1=1774051&r2=1774052&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Dec 13 16:48:40 2016 @@ -81,6 +81,12 @@ with a clear error message HTTP/2 header values that contain characters with unicode code points above 255. (markt) </fix> + <fix> + Improve the logic that selects an address to use to unlock the Acceptor + to take account of platforms what do not listen on all local addresses + when configured with an address of <code>0.0.0.0</code> or + <code>::</code>. (markt) + </fix> </changelog> </subsection> <subsection name="Web Applications"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org