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