From 14306fc99ece759f4df1810d30fdc510966cd106 Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 10 Aug 2021 13:55:27 +0200 Subject: [PATCH] When using connectx for TFO on non-blocking sockets, it will return EINPROGRESS Make sure we handle that as a successful call. --- .../src/main/java/io/netty/channel/kqueue/BsdSocket.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/BsdSocket.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/BsdSocket.java index e3fcfe57a2c..5e8332d352d 100644 --- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/BsdSocket.java +++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/BsdSocket.java @@ -27,6 +27,7 @@ import static io.netty.channel.kqueue.AcceptFilter.PLATFORM_UNSUPPORTED; import static io.netty.channel.kqueue.Native.CONNECT_TCP_FASTOPEN; +import static io.netty.channel.unix.Errors.ERRNO_EINPROGRESS_NEGATIVE; import static io.netty.channel.unix.Errors.ioResult; import static io.netty.channel.unix.NativeInetAddress.ipv4MappedIpv6Address; import static io.netty.util.internal.ObjectUtil.checkNotNull; @@ -161,6 +162,12 @@ private int connectx(InetSocketAddress source, InetSocketAddress destination, Io UNSPECIFIED_SOURCE_INTERFACE, sourceIPv6, sourceAddress, sourceScopeId, sourcePort, destinationIPv6, destinationAddress, destinationScopeId, destinationPort, flags, iovAddress, iovCount, iovDataLength); + if (result == ERRNO_EINPROGRESS_NEGATIVE) { + // This is normal for non-blocking sockets. + // We'll know the connection has been established when the socket is selectable for writing. + // Tell the channel the data was written, so the outbound buffer can update its position. + return iovDataLength; + } if (result < 0) { return ioResult("connectx", result); }