V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ingin
V2EX  ›  问与答

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

  •  
  •   ingin · 2022-02-20 19:44:54 +08:00 · 865 次点击
    这是一个创建于 767 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    • read 方法的作用是什么
    • read 方法何时被调用
    2 条回复    2022-02-21 17:28:56 +08:00
    wineway
        1
    wineway  
       2022-02-21 10:01:37 +08:00 via iPhone
    看看函数签名就懂了……
    huang119412
        2
    huang119412  
       2022-02-21 17:28:56 +08:00
    看一下 ChannelOutboundInvoker#read 的注释,一般不需要用户操心,每个 channel 默认都是 auto read 。TCP 面向流的协议,而应用层协议消息是有边界的,所以有时候会说粘包,当 read 方法调用是会重新触发 pipeline ,可以看一下 ByteToMessageDecoder 。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5375 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:39 · PVG 16:39 · LAX 01:39 · JFK 04:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.