Disable timeouts if they are set to 0

This commit is contained in:
Trustin Lee 2012-09-28 13:52:05 +09:00
parent adebda1560
commit 7514a82c35

View File

@ -290,7 +290,9 @@ public class SslHandler
public ChannelFuture handshake(final ChannelFuture future) {
final ChannelHandlerContext ctx = this.ctx;
ctx.executor().schedule(new Runnable() {
final ScheduledFuture<?> timeoutFuture;
if (handshakeTimeoutMillis > 0) {
timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
if (future.isDone()) {
@ -303,10 +305,17 @@ public class SslHandler
ctx.close();
}
}, handshakeTimeoutMillis, TimeUnit.MILLISECONDS);
} else {
timeoutFuture = null;
}
ctx.executor().execute(new Runnable() {
@Override
public void run() {
try {
if (timeoutFuture != null) {
timeoutFuture.cancel(false);
}
engine.beginHandshake();
handshakeFutures.add(future);
flush(ctx, ctx.newFuture());
@ -912,8 +921,10 @@ public class SslHandler
return;
}
final ScheduledFuture<?> timeoutFuture;
if (closeNotifyTimeoutMillis > 0) {
// Force-close the connection if close_notify is not fully sent in time.
final ScheduledFuture<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
logger.warn(
@ -922,13 +933,19 @@ public class SslHandler
ctx.close(closeFuture);
}
}, closeNotifyTimeoutMillis, TimeUnit.MILLISECONDS);
} else {
timeoutFuture = null;
}
// Close the connection if close_notify is sent in time.
flushFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture f)
throws Exception {
if (timeoutFuture != null) {
timeoutFuture.cancel(false);
}
if (ctx.channel().isActive()) {
ctx.close(closeFuture);
}