注册方法
1.调用doRegister()方法进行注册,如果是NIO实现,如下
2.通过调用底层jdk的nio方法进行注册,本质上为放到channelArray
this.channelArray[this.totalChannels] = var1;
5.如果配置了自动读autoRead,那么beginRead,开始读取
6.首先检查对应的selectionKey是合法的valid
7.然后设置selectionKey为读标记位
二、channel的bind实现
2.1 直接看NioServerSocketChannel的doBind方法,如果jdk7版本及以上,就调用
javaChannel().bind(localAddress, config.getBacklog()); 调用底层实现,Net.bind方法,绑定到对应的地址
2.2 jdk7以下版本,就调用以下的方法,绑定到address
javaChannel().socket().bind(localAddress, config.getBacklog());
2.2 jdk7以下版本,就调用以下的方法,绑定到address
javaChannel().socket().bind(localAddress, config.getBacklog());
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
三、disConnect方法,只能客户端发起,在NioSocketChannel
3.1 doClose()方法,先调用super.doClose
3.2 javaChannel().close();还是调用底层,把selectionKey设置为cancel
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
四、核心方法write()
4.1 校验对应的outboundBuffer不为null, 如果为null设置promise为failure
4.2 把对应的msg写入到outBoundBuffer
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
五、flush方法
5.1 首先检测outboundBuffer不为空
5.2 然后校验此时channel不能是inactive
5.3 循环把buffer写入到channel,调用ch.write(buffer);