multiplexer (Selector) Received OP_READ event :
Handle OP_READ event : NioSocketChannel.NioSocketChannelUnsafe.read()
- Receive data
- Determine whether the accepted data size is <0, If it is , The instructions are to close , Start closing :
- close channel( contain cancel Multiplexers key)
- Clean up messages : Don't accept new information ,fail Drop everything queue Chinese News
- Trigger fireChannellnactive and fireChannelUnregistered.
Close the connection , Will trigger OP_READ event ：
So add conditional breakpoints here
Break point when client disconnects
Writing data is done
The number of bytes read is **-1** For normal shutdown .
At the end of the day , close selection Upper selectionkey, such selector It won't happen again channel All kinds of events on .
- Channel The closure of includes SelectionKey Of cancel
If you send data , All of a sudden the connection was shut down , How is this abnormal disconnection performed ？
- When data reading is in progress , force close , Flip a IOException
- Capture here
- Handle IO abnormal
- So normal shutdown and abnormal shutdown handling are different
本文为[The official account -JavaEdge]所创，转载请带上原文链接，感谢