diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java index ecd714fed3..e8d3fe79c9 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java @@ -37,6 +37,7 @@ import io.netty.channel.unix.Errors.NativeIoException; import io.netty.channel.unix.Socket; import io.netty.channel.unix.UnixChannelUtil; import io.netty.util.ReferenceCountUtil; +import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.internal.RecyclableArrayList; import io.netty.util.internal.StringUtil; @@ -498,7 +499,9 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements } else { break; } - } while (allocHandle.continueReading()); + // We use the TRUE_SUPPLIER as it is also ok to read less then what we did try to read (as long + // as we read anything). + } while (allocHandle.continueReading(UncheckedBooleanSupplier.TRUE_SUPPLIER)); } catch (Throwable t) { exception = t; } diff --git a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java index 6efc29b10e..b6757a7c41 100644 --- a/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java +++ b/transport-native-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java @@ -33,6 +33,7 @@ import io.netty.channel.unix.DatagramSocketAddress; import io.netty.channel.unix.Errors; import io.netty.channel.unix.IovArray; import io.netty.channel.unix.UnixChannelUtil; +import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.internal.StringUtil; import io.netty.util.internal.UnstableApi; @@ -472,7 +473,10 @@ public final class KQueueDatagramChannel extends AbstractKQueueChannel implement pipeline.fireChannelRead(packet); byteBuf = null; - } while (allocHandle.continueReading()); + + // We use the TRUE_SUPPLIER as it is also ok to read less then what we did try to read (as long + // as we read anything). + } while (allocHandle.continueReading(UncheckedBooleanSupplier.TRUE_SUPPLIER)); } catch (Throwable t) { if (byteBuf != null) { byteBuf.release(); diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java index 0e57dc46a1..987c576f5f 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java @@ -56,6 +56,10 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel { super.doBeginRead(); } + protected boolean continueReading(RecvByteBufAllocator.Handle allocHandle) { + return allocHandle.continueReading(); + } + private final class NioMessageUnsafe extends AbstractNioUnsafe { private final List readBuf = new ArrayList<>(); @@ -83,7 +87,7 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel { } allocHandle.incMessagesRead(localRead); - } while (allocHandle.continueReading()); + } while (continueReading(allocHandle)); } catch (Throwable t) { exception = t; } diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index f7848bbf54..2c8f1a48f9 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -32,6 +32,7 @@ import io.netty.channel.nio.AbstractNioMessageChannel; import io.netty.channel.socket.DatagramChannelConfig; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.InternetProtocolFamily; +import io.netty.util.UncheckedBooleanSupplier; import io.netty.util.internal.SocketUtils; import io.netty.util.internal.StringUtil; @@ -579,4 +580,15 @@ public final class NioDatagramChannel } return super.closeOnReadError(cause); } + + @Override + protected boolean continueReading(RecvByteBufAllocator.Handle allocHandle) { + if (allocHandle instanceof RecvByteBufAllocator.ExtendedHandle) { + // We use the TRUE_SUPPLIER as it is also ok to read less then what we did try to read (as long + // as we read anything). + return ((RecvByteBufAllocator.ExtendedHandle) allocHandle) + .continueReading(UncheckedBooleanSupplier.TRUE_SUPPLIER); + } + return allocHandle.continueReading(); + } }