V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
ingin
V2EX  ›  问与答

netty 中,为什么 ChannelOutboundHandler 会声明一个 read 方法

  •  
  •   ingin · Feb 20, 2022 · 1696 views
    This topic created in 1532 days ago, the information mentioned may be changed or developed.

    rt: 出站操作有 write 就好了,为什么会有 read 方法的声明呢,简单查了一下:

    inbound 代表外部引发的事件 event ,outbound 代表程序主动发起的操作 operation

    不知道这种理解是否正确?

    • read 方法的作用是什么
    • read 方法何时被调用
    2 replies    2022-02-21 17:28:56 +08:00
    wineway
        1
    wineway  
       Feb 21, 2022 via iPhone
    看看函数签名就懂了……
    huang119412
        2
    huang119412  
       Feb 21, 2022
    看一下 ChannelOutboundInvoker#read 的注释,一般不需要用户操心,每个 channel 默认都是 auto read 。TCP 面向流的协议,而应用层协议消息是有边界的,所以有时候会说粘包,当 read 方法调用是会重新触发 pipeline ,可以看一下 ByteToMessageDecoder 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2475 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.