From 1118793bfbc126d5e7420631a03f8cffd8747f59 Mon Sep 17 00:00:00 2001 From: Steve Rao Date: Wed, 13 Nov 2019 00:48:58 +0800 Subject: [PATCH] netty: improve code readability (#6375) --- netty/src/main/java/io/grpc/netty/KeepAliveEnforcer.java | 2 +- netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java | 3 ++- netty/src/main/java/io/grpc/netty/NettyServerBuilder.java | 3 ++- .../main/java/io/grpc/netty/NettyWritableBufferAllocator.java | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/netty/src/main/java/io/grpc/netty/KeepAliveEnforcer.java b/netty/src/main/java/io/grpc/netty/KeepAliveEnforcer.java index 076be80dd3..6470e44032 100644 --- a/netty/src/main/java/io/grpc/netty/KeepAliveEnforcer.java +++ b/netty/src/main/java/io/grpc/netty/KeepAliveEnforcer.java @@ -64,7 +64,7 @@ class KeepAliveEnforcer { } if (!valid) { pingStrikes++; - return !(pingStrikes > MAX_PING_STRIKES); + return pingStrikes <= MAX_PING_STRIKES; } else { lastValidPingTime = now; return true; diff --git a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java index 84d47b8fee..17b5cba878 100644 --- a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java @@ -65,7 +65,8 @@ import javax.net.ssl.SSLException; public final class NettyChannelBuilder extends AbstractManagedChannelImplBuilder { - public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1048576; // 1MiB + // 1MiB. + public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1024 * 1024; private static final long AS_LARGE_AS_INFINITE = TimeUnit.DAYS.toNanos(1000L); diff --git a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java index 30457305a9..d9547c0e6c 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerBuilder.java @@ -63,7 +63,8 @@ import javax.net.ssl.SSLException; @CanIgnoreReturnValue public final class NettyServerBuilder extends AbstractServerImplBuilder { - public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1048576; // 1MiB + // 1MiB + public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1024 * 1024; static final long MAX_CONNECTION_IDLE_NANOS_DISABLED = Long.MAX_VALUE; static final long MAX_CONNECTION_AGE_NANOS_DISABLED = Long.MAX_VALUE; diff --git a/netty/src/main/java/io/grpc/netty/NettyWritableBufferAllocator.java b/netty/src/main/java/io/grpc/netty/NettyWritableBufferAllocator.java index d0db923636..9e93ee1155 100644 --- a/netty/src/main/java/io/grpc/netty/NettyWritableBufferAllocator.java +++ b/netty/src/main/java/io/grpc/netty/NettyWritableBufferAllocator.java @@ -34,9 +34,9 @@ import io.netty.buffer.ByteBufAllocator; class NettyWritableBufferAllocator implements WritableBufferAllocator { // Use 4k as our minimum buffer size. - private static final int MIN_BUFFER = 4096; + private static final int MIN_BUFFER = 4 * 1024; - // Set the maximum buffer size to 1MB + // Set the maximum buffer size to 1MB. private static final int MAX_BUFFER = 1024 * 1024; private final ByteBufAllocator allocator;