0

当前代码,在调用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);
    }
}
4

1 回答 1

0

这将是一个坏主意,因为我们可能会破坏用户自己设置的标记。

于 2012-07-11T07:46:47.140 回答