【问题标题】:Reading source code of netty in trouble阅读netty源码遇到麻烦
【发布时间】:2013-10-25 11:20:14
【问题描述】:

我正在阅读 Netty 4.0.10.Final 的源代码。 在 AbstractChannel.AbstractUnsafe 类中

    private void invokeLater(Runnable task) {
        // This method is used by outbound operation implementations to trigger an inbound event later.
        // They do not trigger an inbound event immediately because an outbound operation might have been
        // triggered by another inbound event handler method.  If fired immediately, the call stack
        // will look like this for example:
        //
        //   handlerA.inboundBufferUpdated() - (1) an inbound handler method closes a connection.
        //   -> handlerA.ctx.close()
        //      -> channel.unsafe.close()
        //         -> handlerA.channelInactive() - (2) another inbound handler method called while in (1) yet
        //
        // which means the execution of two inbound handler methods of the same handler overlap undesirably.
        eventLoop().execute(task);
    }

cmets 让我很困惑。 为什么出站事件会立即触发入站事件。 有人可以为我解释细节吗?谢谢!

【问题讨论】:

标签: netty


【解决方案1】:

(我已经回答了这个问题,但我再次回答以完成此条目。)

评论所说的基本上是我们要确保在同一个处理程序中处理程序方法的执行不会重叠。如果没有invokeLater()handlerA.channelInactive() 甚至会在handlerA.inboundBufferUpdated() 返回之前被调用。

【讨论】:

    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多