Limit flush and object allocation
This commit is contained in:
parent
5bda3a25b0
commit
7f780f439a
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user