8234103: DatagramSocketImpl::socket is not needed
DatagramSocketImpl has a socket field that links back to the DatagramSocket. This is only used to figure out whether multicasting is supported or not. This fix replaces it with a boolean isMulticast. Reviewed-by: alanb, chegar, dfuchs
This commit is contained in:
parent
a0b8244416
commit
e636c69e61
@ -54,6 +54,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
private int trafficClass = 0;
|
||||
protected InetAddress connectedAddress = null;
|
||||
private int connectedPort = -1;
|
||||
private final boolean isMulticast;
|
||||
|
||||
private static final String os =
|
||||
GetPropertyAction.privilegedGetProperty("os.name");
|
||||
@ -84,6 +85,10 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
return isReusePortAvailable;
|
||||
}
|
||||
|
||||
AbstractPlainDatagramSocketImpl(boolean isMulticast) {
|
||||
this.isMulticast = isMulticast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a datagram socket
|
||||
*/
|
||||
@ -406,6 +411,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
options.add(StandardSocketOptions.SO_SNDBUF);
|
||||
options.add(StandardSocketOptions.SO_RCVBUF);
|
||||
options.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
options.add(StandardSocketOptions.SO_BROADCAST);
|
||||
options.add(StandardSocketOptions.IP_TOS);
|
||||
if (isReusePortAvailable())
|
||||
options.add(StandardSocketOptions.SO_REUSEPORT);
|
||||
@ -418,6 +424,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
options.add(StandardSocketOptions.SO_SNDBUF);
|
||||
options.add(StandardSocketOptions.SO_RCVBUF);
|
||||
options.add(StandardSocketOptions.SO_REUSEADDR);
|
||||
options.add(StandardSocketOptions.SO_BROADCAST);
|
||||
options.add(StandardSocketOptions.IP_TOS);
|
||||
options.add(StandardSocketOptions.IP_MULTICAST_IF);
|
||||
options.add(StandardSocketOptions.IP_MULTICAST_TTL);
|
||||
@ -430,7 +437,7 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
|
||||
@Override
|
||||
protected Set<SocketOption<?>> supportedOptions() {
|
||||
if (getDatagramSocket() instanceof MulticastSocket)
|
||||
if (isMulticast)
|
||||
return multicastSocketOptions;
|
||||
else
|
||||
return datagramSocketOptions;
|
||||
@ -460,6 +467,8 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
setOption(SocketOptions.SO_REUSEADDR, value);
|
||||
} else if (name == StandardSocketOptions.SO_REUSEPORT) {
|
||||
setOption(SocketOptions.SO_REUSEPORT, value);
|
||||
} else if (name == StandardSocketOptions.SO_BROADCAST) {
|
||||
setOption(SocketOptions.SO_BROADCAST, value);
|
||||
} else if (name == StandardSocketOptions.IP_TOS) {
|
||||
int i = ((Integer)value).intValue();
|
||||
if (i < 0 || i > 255)
|
||||
@ -499,6 +508,8 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
|
||||
return (T) getOption(SocketOptions.SO_REUSEADDR);
|
||||
} else if (name == StandardSocketOptions.SO_REUSEPORT) {
|
||||
return (T) getOption(SocketOptions.SO_REUSEPORT);
|
||||
} else if (name == StandardSocketOptions.SO_BROADCAST) {
|
||||
return (T) getOption(SocketOptions.SO_BROADCAST);
|
||||
} else if (name == StandardSocketOptions.IP_TOS) {
|
||||
return (T) getOption(SocketOptions.IP_TOS);
|
||||
} else if (name == StandardSocketOptions.IP_MULTICAST_IF) {
|
||||
|
@ -338,7 +338,6 @@ class DatagramSocket implements java.io.Closeable {
|
||||
}
|
||||
// creates a udp socket
|
||||
impl.create();
|
||||
impl.setDatagramSocket(this);
|
||||
created = true;
|
||||
}
|
||||
|
||||
|
@ -48,20 +48,6 @@ public abstract class DatagramSocketImpl implements SocketOptions {
|
||||
*/
|
||||
protected FileDescriptor fd;
|
||||
|
||||
/**
|
||||
* The DatagramSocket or MulticastSocket
|
||||
* that owns this impl
|
||||
*/
|
||||
DatagramSocket socket;
|
||||
|
||||
void setDatagramSocket(DatagramSocket socket) {
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
DatagramSocket getDatagramSocket() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
int dataAvailable() {
|
||||
// default impl returns zero, which disables the calling
|
||||
// functionality
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -69,7 +69,7 @@ class DefaultDatagramSocketImplFactory {
|
||||
throw new SocketException("can't instantiate DatagramSocketImpl");
|
||||
}
|
||||
} else {
|
||||
return new java.net.PlainDatagramSocketImpl();
|
||||
return new java.net.PlainDatagramSocketImpl(isMulticast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ import sun.net.ext.ExtendedSocketOptions;
|
||||
|
||||
class PlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
|
||||
{
|
||||
PlainDatagramSocketImpl(boolean isMulticast) {
|
||||
super(isMulticast);
|
||||
}
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -100,7 +100,7 @@ class DefaultDatagramSocketImplFactory
|
||||
if (!preferIPv4Stack && !isMulticast)
|
||||
return new DualStackPlainDatagramSocketImpl(exclusiveBind);
|
||||
else
|
||||
return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast);
|
||||
return new TwoStacksPlainDatagramSocketImpl(exclusiveBind && !isMulticast, isMulticast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -62,6 +62,7 @@ class DualStackPlainDatagramSocketImpl extends AbstractPlainDatagramSocketImpl
|
||||
private boolean isReuseAddress;
|
||||
|
||||
DualStackPlainDatagramSocketImpl(boolean exclBind) {
|
||||
super(false);
|
||||
exclusiveBind = exclBind;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -78,7 +78,8 @@ final class TwoStacksPlainDatagramSocketImpl extends AbstractPlainDatagramSocket
|
||||
// emulates SO_REUSEADDR when exclusiveBind is true and socket is bound
|
||||
private boolean isReuseAddress;
|
||||
|
||||
TwoStacksPlainDatagramSocketImpl(boolean exclBind) {
|
||||
TwoStacksPlainDatagramSocketImpl(boolean exclBind, boolean isMulticast) {
|
||||
super(isMulticast);
|
||||
exclusiveBind = exclBind;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user