Skip to content

Commit

Permalink
Replace ctx.channel().writeAndFlush with ctx.writeAndFlush in WebSock…
Browse files Browse the repository at this point in the history
…ets handlers (netty#12540)

Motivation:

There is no actual need to call `ctx.channel().writeAndFlush` instead of `ctx.writeAndFlush`.  Using the context is also more correct as it start at the right place in the pipeline.

Modification:

Use the context and not the channel

Result:

More correct code
  • Loading branch information
doom369 authored and franz1981 committed Aug 22, 2022
1 parent 9d3614b commit ed995b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -69,7 +69,7 @@ abstract class WebSocketProtocolHandler extends MessageToMessageDecoder<WebSocke
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception {
if (frame instanceof PingWebSocketFrame) {
frame.content().retain();
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content()));
ctx.writeAndFlush(new PongWebSocketFrame(frame.content()));
readIfNeeded(ctx);
return;
}
Expand Down
Expand Up @@ -142,7 +142,7 @@ private boolean checkNextUri(String uri, String websocketPath) {
}

private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
ChannelFuture f = ctx.channel().writeAndFlush(res);
ChannelFuture f = ctx.writeAndFlush(res);
if (!isKeepAlive(req) || res.status().code() != 200) {
f.addListener(ChannelFutureListener.CLOSE);
}
Expand Down

0 comments on commit ed995b0

Please sign in to comment.