From f65696c6eb9bfcc06dc95de095e5ada4c62b805e Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Thu, 14 Oct 2021 17:12:26 +0200 Subject: [PATCH] Make it possible to query Epoll if TCP FastOpen is available (#11762) Motivation: While TCP FastOpen is mostly a pure optimisation (albeit one that demands idempotency of TFO messages), it can still sometimes be useful to query whether it can be expected to be available. This information can for instance be useful for telemetry, where you want to include if TFO is available to the system, to see if it helps overall. For epoll, we have such fields already, but they are not public. The public field we do have, is deprecated and conflates clients and servers. Modification: Add static methods to Epoll that delegates to the existing IS_SUPPORTING_TCP_FASTOPEN_{CLIENT/SERVER} fields. Whether TFO is available is also predicated upon epoll itself being available. Result: People, who specifically rely on epoll, can now query their system in pure Java about whether TFO is available or not. --- .../java/io/netty/channel/epoll/Epoll.java | 21 +++++++++++++++++++ .../java/io/netty/channel/epoll/Native.java | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java index 44ba7f6779e..69620b12a43 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Epoll.java @@ -15,6 +15,7 @@ */ package io.netty.channel.epoll; +import io.netty.channel.ChannelOption; import io.netty.channel.unix.FileDescriptor; import io.netty.util.internal.SystemPropertyUtil; @@ -92,6 +93,26 @@ public static Throwable unavailabilityCause() { return UNAVAILABILITY_CAUSE; } + /** + * Returns {@code true} if the epoll native transport is both {@linkplain #isAvailable() available} and supports + * {@linkplain ChannelOption#TCP_FASTOPEN_CONNECT client-side TCP FastOpen}. + * + * @return {@code true} if it's possible to use client-side TCP FastOpen via epoll, otherwise {@code false}. + */ + public static boolean isTcpFastOpenClientSideAvailable() { + return isAvailable() && Native.IS_SUPPORTING_TCP_FASTOPEN_CLIENT; + } + + /** + * Returns {@code true} if the epoll native transport is both {@linkplain #isAvailable() available} and supports + * {@linkplain ChannelOption#TCP_FASTOPEN server-side TCP FastOpen}. + * + * @return {@code true} if it's possible to use server-side TCP FastOpen via epoll, otherwise {@code false}. + */ + public static boolean isTcpFastOpenServerSideAvailable() { + return isAvailable() && Native.IS_SUPPORTING_TCP_FASTOPEN_SERVER; + } + private Epoll() { } } diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Native.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Native.java index 8a409dd108f..018f7ff8dee 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/Native.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/Native.java @@ -128,7 +128,8 @@ public void run() { static final boolean IS_SUPPORTING_TCP_FASTOPEN_SERVER = (TCP_FASTOPEN_MODE & TFO_ENABLED_SERVER_MASK) == TFO_ENABLED_SERVER_MASK; /** - * @deprecated Use {@link #IS_SUPPORTING_TCP_FASTOPEN_CLIENT} or {@link #IS_SUPPORTING_TCP_FASTOPEN_SERVER}. + * @deprecated Use {@link Epoll#isTcpFastOpenClientSideAvailable()} + * or {@link Epoll#isTcpFastOpenServerSideAvailable()}. */ @Deprecated public static final boolean IS_SUPPORTING_TCP_FASTOPEN = IS_SUPPORTING_TCP_FASTOPEN_CLIENT ||