Take advantage of the new method in ChannelInboundStreamHandlerAdapter

This commit is contained in:
Trustin Lee 2012-05-31 09:07:10 -07:00
parent 3584da2dad
commit 633fada6ec
2 changed files with 6 additions and 4 deletions

View File

@ -54,9 +54,10 @@ public class DiscardClientHandler extends ChannelInboundStreamHandlerAdapter {
@Override @Override
public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx) public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx, ChannelBuffer in)
throws Exception { throws Exception {
// Server is supposed to send nothing. Therefore, do nothing. // Server is supposed to send nothing, but if it sends something, discard it.
in.clear();
} }

View File

@ -15,6 +15,7 @@
*/ */
package io.netty.example.discard; package io.netty.example.discard;
import io.netty.buffer.ChannelBuffer;
import io.netty.channel.ChannelInboundHandlerContext; import io.netty.channel.ChannelInboundHandlerContext;
import io.netty.channel.ChannelInboundStreamHandlerAdapter; import io.netty.channel.ChannelInboundStreamHandlerAdapter;
@ -31,10 +32,10 @@ public class DiscardServerHandler extends ChannelInboundStreamHandlerAdapter {
@Override @Override
public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx) public void inboundBufferUpdated(ChannelInboundHandlerContext<Byte> ctx, ChannelBuffer in)
throws Exception { throws Exception {
// Discard the received data silently. // Discard the received data silently.
ctx.inbound().byteBuffer().clear(); in.clear();
} }