From 8cf237f7f0f15248ec02522a87602dd9d6edfc88 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 4 Sep 2009 06:57:45 +0000 Subject: [PATCH] Fixed issue: NETTY-225 ReadTimeoutHandler, WriteTimeoutHandler, and IdleStateHandler handles sub-millisecond time unit incorrectly * Unless the specified timeout is 0, the converted millisecond timeout should never be 0. --- .../handler/timeout/IdleStateHandler.java | 18 +++++++++++++++--- .../handler/timeout/ReadTimeoutHandler.java | 6 +++++- .../handler/timeout/WriteTimeoutHandler.java | 6 +++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java b/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java index 0c39c86d53..b49d227adc 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java +++ b/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java @@ -174,9 +174,21 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler } this.timer = timer; - readerIdleTimeMillis = unit.toMillis(readerIdleTime); - writerIdleTimeMillis = unit.toMillis(writerIdleTime); - allIdleTimeMillis = unit.toMillis(allIdleTime); + if (readerIdleTime <= 0) { + readerIdleTimeMillis = 0; + } else { + readerIdleTimeMillis = Math.max(unit.toMillis(readerIdleTime), 1); + } + if (writerIdleTime <= 0) { + writerIdleTimeMillis = 0; + } else { + writerIdleTimeMillis = Math.max(unit.toMillis(writerIdleTime), 1); + } + if (allIdleTime <= 0) { + allIdleTimeMillis = 0; + } else { + allIdleTimeMillis = Math.max(unit.toMillis(allIdleTime), 1); + } } /** diff --git a/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java b/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java index e6196a54a8..69ffc49b17 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java +++ b/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java @@ -101,9 +101,13 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler if (unit == null) { throw new NullPointerException("unit"); } + if (timeout <= 0) { + throw new IllegalArgumentException( + "timeout: " + timeout + " (expected: a positive integer)"); + } this.timer = timer; - timeoutMillis = unit.toMillis(timeout); + timeoutMillis = Math.max(unit.toMillis(timeout), 1); } /** diff --git a/src/main/java/org/jboss/netty/handler/timeout/WriteTimeoutHandler.java b/src/main/java/org/jboss/netty/handler/timeout/WriteTimeoutHandler.java index 15f28043c6..3da2ddd0e1 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/WriteTimeoutHandler.java +++ b/src/main/java/org/jboss/netty/handler/timeout/WriteTimeoutHandler.java @@ -97,9 +97,13 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler if (unit == null) { throw new NullPointerException("unit"); } + if (timeout <= 0) { + throw new IllegalArgumentException( + "timeout: " + timeout + " (expected: a positive integer)"); + } this.timer = timer; - timeoutMillis = unit.toMillis(timeout); + timeoutMillis = Math.max(unit.toMillis(timeout), 1); } /**