[#735] Improve the notification of the handshake future

This commit is contained in:
Norman Maurer 2012-11-13 20:05:54 +01:00
parent efaa5c2ff5
commit 3b729848dc
3 changed files with 21 additions and 9 deletions

View File

@ -19,7 +19,6 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelFutureNotifier;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
@ -173,7 +172,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
request.setContent(Unpooled.copiedBuffer(key3));
ChannelFuture handshakeFuture = channel.newFuture();
final ChannelFuture handshakeFuture = channel.newFuture();
ChannelFuture future = channel.write(request);
future.addListener(new ChannelFutureListener() {
@ -183,9 +182,14 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
p.addAfter(
p.context(HttpRequestEncoder.class).name(),
"ws-encoder", new WebSocket00FrameEncoder());
if (future.isSuccess()) {
handshakeFuture.setSuccess();
} else {
handshakeFuture.setFailure(future.cause());
}
}
});
future.addListener(new ChannelFutureNotifier(handshakeFuture));
return handshakeFuture;
}

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelFutureNotifier;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
@ -152,7 +151,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
}
}
ChannelFuture handshakeFuture = channel.newFuture();
final ChannelFuture handshakeFuture = channel.newFuture();
ChannelFuture future = channel.write(request);
future.addListener(new ChannelFutureListener() {
@ -162,9 +161,14 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
p.addAfter(
p.context(HttpRequestEncoder.class).name(),
"ws-encoder", new WebSocket08FrameEncoder(true));
if (future.isSuccess()) {
handshakeFuture.setSuccess();
} else {
handshakeFuture.setFailure(future.cause());
}
}
});
future.addListener(new ChannelFutureNotifier(handshakeFuture));
return handshakeFuture;
}

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelFutureNotifier;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultHttpRequest;
import io.netty.handler.codec.http.HttpHeaders.Names;
@ -152,7 +151,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
}
}
ChannelFuture handshakeFuture = channel.newFuture();
final ChannelFuture handshakeFuture = channel.newFuture();
ChannelFuture future = channel.write(request);
future.addListener(new ChannelFutureListener() {
@ -162,9 +161,14 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
p.addAfter(
p.context(HttpRequestEncoder.class).name(),
"ws-encoder", new WebSocket13FrameEncoder(true));
if (future.isSuccess()) {
handshakeFuture.setSuccess();
} else {
handshakeFuture.setFailure(future.cause());
}
}
});
future.addListener(new ChannelFutureNotifier(handshakeFuture));
return handshakeFuture;
}