简体   繁体   中英

How does netty determine when a read is complete?

Below is a ChannelHandler for a echo server.

在此输入图像描述

Netty framework will call channelReadComplete() method to notify the handler that the last call made to channelRead() was the last message in the current batch.

My question is, since data are transferred on wire in trunks, how could Netty know when a batch of message is complete?

channelReadComplete() is triggered once there is no more data to read from the underlying transport. When talking about SocketChannels this would be either of these two cases:

  1. read(...) returns 0
  2. read(...) got a buffer passed to it that has 1024 bytes to fill, but less than 1024 are filled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM