编程知识 cdmana.com

How does netty disconnect?

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.

Source code

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 .

  • Release cache
    At the end of the day , close selection Upper selectionkey, such selector It won't happen again channel All kinds of events on .

Close the root of the connection API(JDK Native )

  • 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]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224153141230i.html

Scroll to Top