Skip to content

Commit

Permalink
Limit flush and object allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Feb 20, 2013
1 parent 5bda3a2 commit 7f780f4
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,16 @@ private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame fram
}

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 {
Expand All @@ -117,6 +109,13 @@ private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame fram
}
}

@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).
Expand Down

0 comments on commit 7f780f4

Please sign in to comment.