Skip to content

Commit

Permalink
Make it possible to query Epoll if TCP FastOpen is available (netty#1…
Browse files Browse the repository at this point in the history
…1762)

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.
  • Loading branch information
chrisvest authored and 夏无影 committed Jul 8, 2022
1 parent 37df917 commit f65696c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
}
}
Expand Up @@ -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 ||
Expand Down

0 comments on commit f65696c

Please sign in to comment.