Fix #204 - Increate the granularity of connect timeout in NIO

* Changed the Selector timeout from 500 to 10 so that the timeout is checked every 10 milliseconds
This commit is contained in:
Trustin Lee 2012-02-27 12:56:18 -08:00
parent 2b9df060dd
commit 4612568687
2 changed files with 6 additions and 6 deletions

View File

@ -262,7 +262,7 @@ class SctpClientPipelineSink extends AbstractChannelSink {
wakenUp.set(false);
try {
int selectedKeyCount = selector.select(500);
int selectedKeyCount = selector.select(10);
// 'wakenUp.compareAndSet(false, true)' is always evaluated
// before calling 'selector.wakeup()' to reduce the wake-up
@ -302,9 +302,9 @@ class SctpClientPipelineSink extends AbstractChannelSink {
processSelectedKeys(selector.selectedKeys());
}
// Handle connection timeout every 0.5 seconds approximately.
// Handle connection timeout every 10 milliseconds approximately.
long currentTimeNanos = System.nanoTime();
if (currentTimeNanos - lastConnectTimeoutCheckTimeNanos >= 500 * 1000000L) {
if (currentTimeNanos - lastConnectTimeoutCheckTimeNanos >= 10 * 1000000L) {
lastConnectTimeoutCheckTimeNanos = currentTimeNanos;
processConnectTimeout(selector.keys(), currentTimeNanos);
}

View File

@ -242,7 +242,7 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
wakenUp.set(false);
try {
int selectedKeyCount = selector.select(500);
int selectedKeyCount = selector.select(10);
// 'wakenUp.compareAndSet(false, true)' is always evaluated
// before calling 'selector.wakeup()' to reduce the wake-up
@ -282,9 +282,9 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
processSelectedKeys(selector.selectedKeys());
}
// Handle connection timeout every 0.5 seconds approximately.
// Handle connection timeout every 10 milliseconds approximately.
long currentTimeNanos = System.nanoTime();
if (currentTimeNanos - lastConnectTimeoutCheckTimeNanos >= 500 * 1000000L) {
if (currentTimeNanos - lastConnectTimeoutCheckTimeNanos >= 10 * 1000000L) {
lastConnectTimeoutCheckTimeNanos = currentTimeNanos;
processConnectTimeout(selector.keys(), currentTimeNanos);
}