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 7a8836ea6b..ab8ec805de 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 @@ -35,6 +35,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.ObjectUtil; 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 a19401dd8a..147523d7d0 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 @@ -31,6 +31,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.ObjectUtil; import io.netty.util.internal.StringUtil; import io.netty.util.internal.UnstableApi; @@ -471,7 +472,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 15d32460af..996d7b165a 100644 --- a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java +++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java @@ -55,6 +55,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(); @@ -82,7 +86,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 83a3cafb69..701e873cd7 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 @@ -30,6 +30,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.ObjectUtil; import io.netty.util.internal.SocketUtils; import io.netty.util.internal.PlatformDependent; @@ -598,4 +599,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(); + } }