Reorder PlatformDependent.isRoot() check
Motivation: isRoot() is an expensive operation. We should avoid calling it if possible. Modifications: Move the isRoot() checks to the end of the 'if' block, so that isRoot() is evaluated only when really necessary. Result: isRoot() is evaluated only when SO_BROADCAST is set and the bind address is anylocal address.
This commit is contained in:
parent
3ca6e4bd54
commit
10a5635acb
@ -459,7 +459,7 @@ public final class PlatformDependent {
|
||||
return false;
|
||||
}
|
||||
|
||||
String[] ID_COMMANDS = { "/usr/bin/id", "/bin/id", "id", "/usr/xpg4/bin/id"};
|
||||
String[] ID_COMMANDS = { "/usr/bin/id", "/bin/id", "/usr/xpg4/bin/id", "id"};
|
||||
Pattern UID_PATTERN = Pattern.compile("^(?:0|[1-9][0-9]*)$");
|
||||
for (String idCmd: ID_COMMANDS) {
|
||||
Process p = null;
|
||||
|
@ -467,10 +467,10 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
}
|
||||
|
||||
// See: https://github.com/netty/netty/issues/576
|
||||
if (!PlatformDependent.isWindows() && !PlatformDependent.isRoot() &&
|
||||
Boolean.TRUE.equals(config().getOption(ChannelOption.SO_BROADCAST)) &&
|
||||
if (Boolean.TRUE.equals(config().getOption(ChannelOption.SO_BROADCAST)) &&
|
||||
localAddress instanceof InetSocketAddress &&
|
||||
!((InetSocketAddress) localAddress).getAddress().isAnyLocalAddress()) {
|
||||
!((InetSocketAddress) localAddress).getAddress().isAnyLocalAddress() &&
|
||||
!PlatformDependent.isWindows() && !PlatformDependent.isRoot()) {
|
||||
// Warn a user about the fact that a non-root user can't receive a
|
||||
// broadcast packet on *nix if the socket is bound on non-wildcard address.
|
||||
logger.warn(
|
||||
|
@ -157,8 +157,8 @@ public class DefaultDatagramChannelConfig extends DefaultChannelConfig implement
|
||||
try {
|
||||
// See: https://github.com/netty/netty/issues/576
|
||||
if (broadcast &&
|
||||
!PlatformDependent.isWindows() && !PlatformDependent.isRoot() &&
|
||||
!javaSocket.getLocalAddress().isAnyLocalAddress()) {
|
||||
!javaSocket.getLocalAddress().isAnyLocalAddress() &&
|
||||
!PlatformDependent.isWindows() && !PlatformDependent.isRoot()) {
|
||||
// Warn a user about the fact that a non-root user can't receive a
|
||||
// broadcast packet on *nix if the socket is bound on non-wildcard address.
|
||||
logger.warn(
|
||||
|
Loading…
Reference in New Issue
Block a user