mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
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
8 changed files with 25 additions and 23 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue