Netty 源码阅读笔记(5) NioServerSocketChannel

    技术2026-01-08  15

    目录

    类关系图5.1 构造方法

    类关系图

    5.1 构造方法

    public NioServerSocketChannel() { this(newSocket(DEFAULT_SELECTOR_PROVIDER)); } public NioServerSocketChannel(ServerSocketChannel channel) { //成员变量赋值,还没有真正的绑定事件 super(null, channel, SelectionKey.OP_ACCEPT); config = new NioServerSocketChannelConfig(this, javaChannel().socket()); }

    类 AbstractNioMessageChannel

    protected AbstractNioMessageChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent, ch, readInterestOp); }

    类 AbstractNioChannel

    protected AbstractNioChannel(Channel parent, SelectableChannel ch, int readInterestOp) { super(parent); this.ch = ch; //成员变量赋值SelectionKey.OP_ACCEPT,还没有真正的绑定事件 this.readInterestOp = readInterestOp; try { //设置非阻塞 ch.configureBlocking(false); } catch (IOException e) { try { ch.close(); } catch (IOException e2) { if (logger.isWarnEnabled()) { logger.warn( "Failed to close a partially initialized socket.", e2); } } throw new ChannelException("Failed to enter non-blocking mode.", e); } }

    类 AbstractChannel

    protected AbstractChannel(Channel parent) { this.parent = parent; id = newId(); unsafe = newUnsafe(); //创建了当前channel的pipeline和头尾handler 见(6) pipeline = newChannelPipeline(); }

    Netty 源码阅读笔记(6) DefaultChannelPipeline

    Processed: 0.043, SQL: 9