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.
This commit is contained in:
Trustin Lee 2009-09-04 06:57:45 +00:00
parent 16124dc14c
commit 8cf237f7f0
3 changed files with 25 additions and 5 deletions

View File

@ -174,9 +174,21 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler
} }
this.timer = timer; this.timer = timer;
readerIdleTimeMillis = unit.toMillis(readerIdleTime); if (readerIdleTime <= 0) {
writerIdleTimeMillis = unit.toMillis(writerIdleTime); readerIdleTimeMillis = 0;
allIdleTimeMillis = unit.toMillis(allIdleTime); } 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);
}
} }
/** /**

View File

@ -101,9 +101,13 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler
if (unit == null) { if (unit == null) {
throw new NullPointerException("unit"); throw new NullPointerException("unit");
} }
if (timeout <= 0) {
throw new IllegalArgumentException(
"timeout: " + timeout + " (expected: a positive integer)");
}
this.timer = timer; this.timer = timer;
timeoutMillis = unit.toMillis(timeout); timeoutMillis = Math.max(unit.toMillis(timeout), 1);
} }
/** /**

View File

@ -97,9 +97,13 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler
if (unit == null) { if (unit == null) {
throw new NullPointerException("unit"); throw new NullPointerException("unit");
} }
if (timeout <= 0) {
throw new IllegalArgumentException(
"timeout: " + timeout + " (expected: a positive integer)");
}
this.timer = timer; this.timer = timer;
timeoutMillis = unit.toMillis(timeout); timeoutMillis = Math.max(unit.toMillis(timeout), 1);
} }
/** /**