New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io.netty.channel.socket.nio.AbstractNioChannel doRegister() ?? #1836
Comments
It's an intentional stuff to deal with a potential JDK bug where it returns a selection key with readyOps set to 0 for no good reason, leading to a spin loop. So, I'd leave it as it is. |
@trustin maybe we could just have a comment here to know later again why we 2013/9/15 Trustin Lee notifications@github.com
|
Added a comment to clearify. |
for (;;) { why set 0 in register method? avoid jdk bug here? version4.0.17.final if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) { |
你好,我很久没有看这个项目了,当时也没有看透。 ------------------ 原始邮件 ------------------ for (;;) { why set 0 in register method? avoid jdk bug here? version4.0.17.final if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) { — |
There are two way to register interested events:
netty use 2. After binding channel to selector with interestOps 0, netty will invoke fireChannelActive()
|
It took me a day to find the place to register “SelectionKey.OP_ACCEPT”,finally,I found that,case 1 eq case 2
|
@OverRide
protected void doRegister() throws Exception {.............
selectionKey = javaChannel().register(eventLoop().selector, 0, this);
what does the "opt==0" means ?
1=OP_READ
2=OP_WRITE
8=OP_CONNECT
16=OP_ACCEPT
0=??
but ,I found that:
NioEventLoop.has method :
private static void processSelectedKey(SelectionKey k, AbstractNioChannel ch) {
............
....................
try {
int readyOps = k.readyOps();
if ((readyOps & (SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) != 0 || readyOps == 0) {
unsafe.read();
if (!ch.isOpen()) {
// Connection already closed - no need to handle write.
return;
}
}
........
"readyOps==0" ,why?
thanks you!
The text was updated successfully, but these errors were encountered: