Limit flush and object allocation

This commit is contained in:
Norman Maurer 2013-02-20 07:05:35 +01:00
parent 5bda3a25b0
commit 7f780f439a

View File

@ -91,24 +91,16 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
}
if (frame instanceof CloseWebSocketFrame) {
frame.retain();
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
} else if (frame instanceof PingWebSocketFrame) {
frame.data().retain();
ctx.channel().write(
new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.data()));
ctx.nextOutboundMessageBuffer().add(
new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.data().retain()));
} else if (frame instanceof TextWebSocketFrame) {
frame.data().retain();
ctx.channel().write(
new TextWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.data()));
ctx.nextOutboundMessageBuffer().add(frame.retain());
} else if (frame instanceof BinaryWebSocketFrame) {
frame.data().retain();
ctx.channel().write(
new BinaryWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.data()));
ctx.nextOutboundMessageBuffer().add(frame.retain());
} else if (frame instanceof ContinuationWebSocketFrame) {
frame.data().retain();
ctx.channel().write(
new ContinuationWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.data()));
ctx.nextOutboundMessageBuffer().add(frame.retain());
} else if (frame instanceof PongWebSocketFrame) {
// Ignore
} else {
@ -117,6 +109,13 @@ public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<O
}
}
@Override
protected void endMessageReceived(ChannelHandlerContext ctx) throws Exception {
if (handshaker != null) {
ctx.flush().addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
}
}
private static void sendHttpResponse(
ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
// Generate an error page if response getStatus code is not OK (200).