When ServerBootstrap is registered in Netty, the registered interestOps is 0

problem description

when you look at the ServerBootstrap startup process in Netty, you find that the interestOps registered by NIOServerSocketChannel is 0.
what does it mean to register as 0? shouldn"t ServerSocketChannel register the value of OP_CONNECT (8) or OP_ACCEPT (16)?
how does ServerSocketChannel know about channel establishment and connection?

related codes

@Override
protected void doRegister() throws Exception {
    boolean selected = false;
    for (;;) {
        try {
            selectionKey = javaChannel().register(eventLoop().unwrappedSelector(), 0, this);
            return;
        } catch (CancelledKeyException e) {
            if (!selected) {
                // Force the Selector to select now as the "canceled" SelectionKey may still be
                // cached and not removed because no Select.select(..) operation was called yet.
                eventLoop().selectNow();
                selected = true;
            } else {
                // We forced a select operation on the selector before but the SelectionKey is still cached
                // for whatever reason. JDK bug ?
                throw e;
            }
        }
    }
}

ask God for help, thank you!

Dec.18,2021

there are two ways to register interestOps:
1. One is register with parameters;
2. The other is SelectionKey-sharpinterestOps

netty uses the latter. The specific code is AbstractNioChannel-sharpdoBeginRead

.
    @Override
    protected void doBeginRead() throws Exception {
        // Channel.read() or ChannelHandlerContext.read() was called
        final SelectionKey selectionKey = this.selectionKey;
        if (!selectionKey.isValid()) {
            return;
        }

        readPending = true;

        final int interestOps = selectionKey.interestOps();
        if ((interestOps & readInterestOp) == 0) {
            selectionKey.interestOps(interestOps | readInterestOp);
        }
    }

for the scenario you describe, it is actually NioServerSocketChannel . The above function is called when bind , and the value of the member variable interestOps used in the method is passed in during construction:

    /**
     * Create a new instance using the given {@link ServerSocketChannel}.
     */
    public NioServerSocketChannel(ServerSocketChannel channel) {
        super(null, channel, SelectionKey.OP_ACCEPT);
        config = new NioServerSocketChannelConfig(this, javaChannel().socket());
    }

so, what is registered is actually OPS_ACCEPT , that is, 16 .
is also registered in the above way for ordinary Channel .

above.

ps: this question I remember a classmate on gayhub mentioned issues, or Chinese questions, for the time being can not find.
Menu