当前代码,在调用resetReaderIndex()
等待更多数据之前,我们必须在子类的markReaderIndex()
第一行调用。decode()
FrameDecoder
你能在下面插入cumulation.markReaderIndex();
之前Object frame = decode(context, channel, cumulation);
用FrameDecoder.java
“<<<<<”标记的内容吗?它对初学者有用且重要。谢谢:
//org.jboss.netty.handler.codec.frame.FrameDecoder.java:
private void callDecode(
ChannelHandlerContext context, Channel channel,
ChannelBuffer cumulation, SocketAddress remoteAddress) throws Exception {
while (cumulation.readable()) {
int oldReaderIndex = cumulation.readerIndex();
cumulation.markReaderIndex();//WangHongguangAdd20120711<<<<<<<<<<<<
Object frame = decode(context, channel, cumulation);
if (frame == null) {
if (oldReaderIndex == cumulation.readerIndex()) {
// Seems like more data is required.
// Let us wait for the next notification.
break;
} else {
// Previous data has been discarded.
// Probably it is reading on.
continue;
}
...
}
unfoldAndFireMessageReceived(context, remoteAddress, frame);
}
}