From 076c35f7852ac9d7593ccffc9cf889a78ecc5e6c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 30 Aug 2020 21:13:52 +0200 Subject: [PATCH] Fallback to simple write when we can not allocate iovec array and correctly handle poll mask --- .../channel/uring/AbstractIOUringChannel.java | 7 ++++-- .../netty/channel/uring/IOUringEventLoop.java | 22 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java index 383903d9d9..58a177f26b 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java @@ -290,7 +290,8 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha try { in.forEachFlushedMessage(iovecArray); } catch (Exception e) { - + // This should never happem, anyway fallback to single write. + doWriteSingle((ByteBuf) in.current()); } if (iovecArray.count() > 0) { @@ -298,8 +299,10 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha submissionQueue().submit(); writeScheduled = true; } + } else { + // We were not be able to create a new iovec, fallback to single write. + doWriteSingle((ByteBuf) in.current()); } - //Todo error handling } diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java index 2ce47f8123..0f2405ce6f 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringEventLoop.java @@ -192,6 +192,8 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements ((AbstractIOUringChannel.AbstractUringUnsafe) readChannel.unsafe()).readComplete(res); break; case IOUring.OP_WRITEV: + // Fall-through + case IOUring.OP_WRITE: AbstractIOUringChannel writeChannel = channels.get(fd); if (writeChannel == null) { @@ -219,18 +221,14 @@ final class IOUringEventLoop extends SingleThreadEventLoop implements if (channel == null) { break; } - switch (pollMask) { - case IOUring.POLLMASK_IN: - ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollIn(res); - break; - case IOUring.POLLMASK_OUT: - ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollOut(res); - break; - case IOUring.POLLMASK_RDHUP: - ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollRdHup(res); - break; - default: - break; + if ((pollMask & IOUring.POLLMASK_OUT) != 0) { + ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollOut(res); + } + if ((pollMask & IOUring.POLLMASK_IN) != 0) { + ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollIn(res); + } + if ((pollMask & IOUring.POLLMASK_RDHUP) != 0) { + ((AbstractIOUringChannel.AbstractUringUnsafe) channel.unsafe()).pollRdHup(res); } } break;