The asynchronous operations should not throw an exception directly

This commit is contained in:
Trustin Lee 2009-10-22 10:21:20 +00:00
parent 2fea789309
commit 2ac4719fae

View File

@ -305,21 +305,28 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
* @return a {@link ChannelFuture} which is notified when the handshake * @return a {@link ChannelFuture} which is notified when the handshake
* succeeds or fails. * succeeds or fails.
*/ */
public ChannelFuture handshake(Channel channel) throws SSLException { public ChannelFuture handshake(Channel channel) {
// FIXME do not throw SSLException - return a failed future.
ChannelFuture handshakeFuture; ChannelFuture handshakeFuture;
synchronized (handshakeLock) { synchronized (handshakeLock) {
if (handshaking) { if (handshaking) {
return this.handshakeFuture; return this.handshakeFuture;
} else { } else {
engine.beginHandshake(); try {
runDelegatedTasks(); engine.beginHandshake();
handshakeFuture = this.handshakeFuture = future(channel); runDelegatedTasks();
handshakeFuture = this.handshakeFuture = future(channel);
} catch (SSLException e) {
handshakeFuture = this.handshakeFuture = failedFuture(channel, e);
}
handshaking = true; handshaking = true;
} }
} }
wrapNonAppData(context(channel), channel); try {
wrapNonAppData(context(channel), channel);
} catch (SSLException e) {
handshakeFuture.setFailure(e);
}
return handshakeFuture; return handshakeFuture;
} }
@ -327,11 +334,14 @@ public class SslHandler extends FrameDecoder implements ChannelDownstreamHandler
* Sends an SSL {@code close_notify} message to the specified channel and * Sends an SSL {@code close_notify} message to the specified channel and
* destroys the underlying {@link SSLEngine}. * destroys the underlying {@link SSLEngine}.
*/ */
public ChannelFuture close(Channel channel) throws SSLException { public ChannelFuture close(Channel channel) {
// FIXME do not throw SSLException - return a failed future. try {
ChannelHandlerContext ctx = context(channel); ChannelHandlerContext ctx = context(channel);
engine.closeOutbound(); engine.closeOutbound();
return wrapNonAppData(ctx, channel); return wrapNonAppData(ctx, channel);
} catch (SSLException e) {
return failedFuture(channel, e);
}
} }
private ChannelHandlerContext context(Channel channel) { private ChannelHandlerContext context(Channel channel) {