aboutsummaryrefslogtreecommitdiff
path: root/netty
diff options
context:
space:
mode:
authorzpencer <spencerfang@google.com>2018-04-05 10:36:49 -0700
committerGitHub <noreply@github.com>2018-04-05 10:36:49 -0700
commit62cc2b1ae3008c034269a3128907acc9708a97be (patch)
tree8155895ae882f05be77686be0da8df57c092db14 /netty
parent2df76cc71015bce0ce2fdcd8a0aaa152763ca2fd (diff)
downloadgrpc-grpc-java-62cc2b1ae3008c034269a3128907acc9708a97be.tar.gz
core,netty: add NettySocketSupport to populate TcpInfo (#4306)
NettySocketSupport is responsible for making the low level calls to get and populate the TcpInfo structure.
Diffstat (limited to 'netty')
-rw-r--r--netty/src/main/java/io/grpc/netty/NettySocketSupport.java60
-rw-r--r--netty/src/main/java/io/grpc/netty/Utils.java9
2 files changed, 69 insertions, 0 deletions
diff --git a/netty/src/main/java/io/grpc/netty/NettySocketSupport.java b/netty/src/main/java/io/grpc/netty/NettySocketSupport.java
new file mode 100644
index 000000000..597927b6f
--- /dev/null
+++ b/netty/src/main/java/io/grpc/netty/NettySocketSupport.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2018, gRPC Authors All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.grpc.netty;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import io.grpc.internal.Channelz.TcpInfo;
+import io.netty.channel.Channel;
+import java.util.HashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+/**
+ * An class for getting low level socket info.
+ */
+final class NettySocketSupport {
+
+ /**
+ * Returns the info on the socket if possible. Returns null if the info can not be discovered.
+ */
+ @Nullable
+ public static NativeSocketOptions getNativeSocketOptions(Channel ch) {
+ // TODO(zpencer): if netty-epoll, use reflection to call EpollSocketChannel.tcpInfo()
+ // And/or if some other low level socket support library is available, call it now.
+ return null;
+ }
+
+ /**
+ * A TcpInfo and additional other info that will be turned into channelz socket options.
+ */
+ public static final class NativeSocketOptions {
+ @Nullable public final TcpInfo tcpInfo;
+ public final ImmutableMap<String, String> otherInfo;
+
+ /** Creates an instance. */
+ public NativeSocketOptions(
+ TcpInfo tcpInfo,
+ Map<String, String> otherInfo) {
+ Preconditions.checkNotNull(otherInfo);
+ this.tcpInfo = tcpInfo;
+ this.otherInfo = ImmutableMap.copyOf(new HashMap<String, String>(otherInfo));
+ }
+ }
+
+ private NettySocketSupport() {}
+}
diff --git a/netty/src/main/java/io/grpc/netty/Utils.java b/netty/src/main/java/io/grpc/netty/Utils.java
index 473a4c8ef..fc2203c9c 100644
--- a/netty/src/main/java/io/grpc/netty/Utils.java
+++ b/netty/src/main/java/io/grpc/netty/Utils.java
@@ -32,6 +32,7 @@ import io.grpc.internal.Channelz;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.SharedResourceHolder.Resource;
import io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2InboundHeaders;
+import io.grpc.netty.NettySocketSupport.NativeSocketOptions;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelOption;
@@ -235,6 +236,14 @@ class Utils {
// zpencer: Can a netty option be null?
b.addOption(key.name(), String.valueOf(value));
}
+
+ NativeSocketOptions nativeOptions = NettySocketSupport.getNativeSocketOptions(channel);
+ if (nativeOptions != null) {
+ b.setTcpInfo(nativeOptions.tcpInfo); // may be null
+ for (Entry<String, String> entry : nativeOptions.otherInfo.entrySet()) {
+ b.addOption(entry.getKey(), entry.getValue());
+ }
+ }
return b.build();
}