8233245: More adaptive sockets

Reviewed-by: chegar, igerasim, alanb, skoivu, rhalade
This commit is contained in:
Daniel Fuchs 2019-12-09 20:33:15 +00:00
parent 2ea157fee1
commit ad09813035
2 changed files with 159 additions and 5 deletions

View file

@ -166,13 +166,23 @@ public class DatagramSocketAdaptor
@Override
public SocketAddress getLocalSocketAddress() {
try {
return dc.getLocalAddress();
} catch (ClosedChannelException e) {
InetSocketAddress local = dc.localAddress();
if (local == null || isClosed())
return null;
} catch (Exception x) {
throw new Error(x);
InetAddress addr = local.getAddress();
if (addr.isAnyLocalAddress())
return local;
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkConnect(addr.getHostAddress(), -1);
} catch (SecurityException x) {
return new InetSocketAddress(local.getPort());
}
}
return local;
}
@Override