我是 netty 的新手,我尝试从服务器(非 netty)接收字节响应。但是,我相信我误解了引用计数。在阅读回复时,我遇到了IllegalReferenceCountException: refCnt:0
我所做的并不那么复杂。我设置了客户端,然后我发送了一条消息,我正在等待回复。
我的 ResponseHandler 看起来像这样:
public class ResponseHandler extends DriverResponseHandler
{
private ByteBuf received;
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
{
super.handlerAdded(ctx);
received = ctx.alloc().buffer(32);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
{
super.channelRead(ctx, msg);
received.writeBytes((ByteBuf) msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception
{
super.channelReadComplete(ctx);
if (received.writerIndex() == received.capacity() || received.readerIndex() == received.capacity()) {
received.clear();
received = ctx.alloc().buffer(32);
}
processResponse(received);
}
}
在读取channelRead
异常中的响应时发生。为什么会发生。有人可以向我解释吗?