8233296: MulticastSocket getOption/setOption inverts the value of IP_MULTICAST_LOOP

MulticastSocket.getOption(StandardSocketOption.IP_MULTICAST_LOOP) now returns true if loopback mode is enabled, and MulticastSocket.setOption(StandardSocketOption.IP_MULTICAST_LOOP, true) enables loopback mode. No other behavioral changes.

Reviewed-by: alanb, chegar
This commit is contained in:
Daniel Fuchs 2019-11-22 11:52:48 +00:00
parent 0a1737ca97
commit 8333ea85fa
3 changed files with 321 additions and 4 deletions

View file

@ -482,7 +482,9 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
throw new IllegalArgumentException("Invalid TTL/hop value: " + value);
setTimeToLive((Integer)value);
} else if (name == StandardSocketOptions.IP_MULTICAST_LOOP) {
setOption(SocketOptions.IP_MULTICAST_LOOP, value);
boolean enable = (boolean) value;
// Legacy setOption expects true to mean 'disabled'
setOption(SocketOptions.IP_MULTICAST_LOOP, !enable);
} else if (extendedOptions.isOptionSupported(name)) {
extendedOptions.setOption(fd, name, value);
} else {
@ -517,7 +519,9 @@ abstract class AbstractPlainDatagramSocketImpl extends DatagramSocketImpl
} else if (name == StandardSocketOptions.IP_MULTICAST_TTL) {
return (T) ((Integer) getTimeToLive());
} else if (name == StandardSocketOptions.IP_MULTICAST_LOOP) {
return (T) getOption(SocketOptions.IP_MULTICAST_LOOP);
boolean disabled = (boolean) getOption(SocketOptions.IP_MULTICAST_LOOP);
// Legacy getOption returns true when disabled
return (T) Boolean.valueOf(!disabled);
} else if (extendedOptions.isOptionSupported(name)) {
return (T) extendedOptions.getOption(fd, name);
} else {