From 1f9d165583172bcb764827e259421e3a1f098802 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 19 Dec 2012 21:16:41 +0100 Subject: [PATCH] [#836] Correctly reset timeout on sendFile(...) --- .../handler/timeout/WriteTimeoutHandler.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java b/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java index c1b4ce0d39..2558bdba18 100644 --- a/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java +++ b/handler/src/main/java/io/netty/handler/timeout/WriteTimeoutHandler.java @@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerAdapter; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOperationHandlerAdapter; +import io.netty.channel.FileRegion; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -104,6 +105,19 @@ public class WriteTimeoutHandler extends ChannelOperationHandlerAdapter { @Override public void flush(final ChannelHandlerContext ctx, final ChannelFuture future) throws Exception { + scheduleTimeout(ctx, future); + + super.flush(ctx, future); + } + + @Override + public void sendFile(ChannelHandlerContext ctx, FileRegion region, ChannelFuture future) throws Exception { + scheduleTimeout(ctx, future); + + super.sendFile(ctx, region, future); + } + + private void scheduleTimeout(final ChannelHandlerContext ctx, final ChannelFuture future) { if (timeoutMillis > 0) { // Schedule a timeout. final ScheduledFuture sf = ctx.executor().schedule(new Runnable() { @@ -128,8 +142,6 @@ public class WriteTimeoutHandler extends ChannelOperationHandlerAdapter { } }); } - - super.flush(ctx, future); } protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception {