diff --git a/transport-native-epoll/src/main/c/netty_epoll_native.c b/transport-native-epoll/src/main/c/netty_epoll_native.c index f754a3e462..3f08c341cf 100644 --- a/transport-native-epoll/src/main/c/netty_epoll_native.c +++ b/transport-native-epoll/src/main/c/netty_epoll_native.c @@ -385,7 +385,7 @@ static jint netty_epoll_native_splice0(JNIEnv* env, jclass clazz, jint fd, jlong loff_t off_out = (loff_t) offOut; loff_t* p_off_in = off_in >= 0 ? &off_in : NULL; - loff_t* p_off_out = off_in >= 0 ? &off_out : NULL; + loff_t* p_off_out = off_out >= 0 ? &off_out : NULL; do { res = splice(fd, p_off_in, fdOut, p_off_out, (size_t) len, SPLICE_F_NONBLOCK | SPLICE_F_MOVE); diff --git a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java index e2b3da728b..db4878c1ef 100644 --- a/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java +++ b/transport-native-epoll/src/main/java/io/netty/channel/epoll/AbstractEpollStreamChannel.java @@ -205,7 +205,7 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im public final ChannelFuture spliceTo(final FileDescriptor ch, final int offset, final int len, final ChannelPromise promise) { checkPositiveOrZero(len, "len"); - checkPositiveOrZero(offset, "offser"); + checkPositiveOrZero(offset, "offset"); if (config().getEpollMode() != EpollMode.LEVEL_TRIGGERED) { throw new IllegalStateException("spliceTo() supported only when using " + EpollMode.LEVEL_TRIGGERED); } @@ -977,7 +977,7 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im private final class SpliceFdTask extends SpliceInTask { private final FileDescriptor fd; private final ChannelPromise promise; - private final int offset; + private int offset; SpliceFdTask(FileDescriptor fd, int offset, int len, ChannelPromise promise) { super(len, promise); @@ -1007,6 +1007,7 @@ public abstract class AbstractEpollStreamChannel extends AbstractEpollChannel im } do { int splicedOut = Native.splice(pipeIn.intValue(), -1, fd.intValue(), offset, splicedIn); + offset += splicedOut; splicedIn -= splicedOut; } while (splicedIn > 0); if (len == 0) { diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java index b65fc26611..a8d9d72aa9 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSpliceTest.java @@ -189,7 +189,7 @@ public class EpollSpliceTest { } } - @Test + @Test(timeout = 10000) public void spliceToFile() throws Throwable { EventLoopGroup group = new EpollEventLoopGroup(1); File file = File.createTempFile("netty-splice", null); @@ -215,7 +215,7 @@ public class EpollSpliceTest { i += length; } - while (sh.future == null || !sh.future.isDone()) { + while (sh.future2 == null || !sh.future2.isDone() || !sh.future.isDone()) { if (sh.exception.get() != null) { break; } @@ -291,8 +291,8 @@ public class EpollSpliceTest { private static class SpliceHandler extends ChannelInboundHandlerAdapter { private final File file; - volatile Channel channel; volatile ChannelFuture future; + volatile ChannelFuture future2; final AtomicReference exception = new AtomicReference(); SpliceHandler(File file) { @@ -300,13 +300,13 @@ public class EpollSpliceTest { } @Override - public void channelActive(ChannelHandlerContext ctx) - throws Exception { - channel = ctx.channel(); + public void channelActive(ChannelHandlerContext ctx) throws Exception { final EpollSocketChannel ch = (EpollSocketChannel) ctx.channel(); final FileDescriptor fd = FileDescriptor.from(file); - future = ch.spliceTo(fd, 0, data.length); + // splice two halves separately to test starting offset + future = ch.spliceTo(fd, 0, data.length / 2); + future2 = ch.spliceTo(fd, data.length / 2, data.length / 2); } @Override