read过程
上一篇博文整理出来,当channel收到消息后的处理流程
//类名或对象名::调用方法
NioEventLoop::processSelectedKey //1. 开始处理消息
unsafe::read //2. 读取消息
pipeline::fireChannelRead //3. 交给channel对应的pipeline处理消息
AbstractChannelHandlerContext::invokeChannelRead(head, msg)//4. 从pipeline的head开始调用channelRead
ctx::findContextInbound //5. 从head开始寻找第一个inbound的handler
ctx::fireChannelRead

本文详细介绍了Netty中的read和write过程。在read过程中,消息从HeadContext传递,经过HttpServerCodec的HttpServerRequestDecoder进行Http解码,接着HttpObjectAggregator组装成FullHttpMessage,最终到达HttpFileServerHandler处理业务逻辑。write过程则从调用ctx.write开始,通过ChunkedWriteHandler和HttpServerCodec的HttpServerResponseEncoder进行消息编码并返回给客户端。channelInactive事件的处理方式与read相似。
最低0.47元/天 解锁文章
822





