Netty-(interestOps & readInterestOp) != 0写法的意义
Posted 征服.刘华强
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Netty-(interestOps & readInterestOp) != 0写法的意义相关的知识,希望对你有一定的参考价值。
//OP_READ = 1 00000001 //OP_WRITE = 4 00000100 //OP_CONNECT = 8 00001000 //OP_ACCEPT = 16 00010000
protected final void removeReadOp()
SelectionKey key = selectionKey();
// Check first if the key is still valid as it may be canceled as part of the deregistration
// from the EventLoop
// See https://github.com/netty/netty/issues/2104
if (!key.isValid())
return;
int interestOps = key.interestOps();
if ((interestOps & readInterestOp) != 0)
// only remove readInterestOp if needed
key.interestOps(interestOps & ~readInterestOp);
在NIO中,我们常见这种写法,那它到底是什么意思呢? (interestOps & OP_READ ) != 0 如果不为0,说明interestOps一定包含OP_READ。 key.interestOps(interestOps & ~OP_READ); ~OP_READ按位取反 11111110,那 interestOps&11111110,相当于把OP_READ去掉。
以上是关于Netty-(interestOps & readInterestOp) != 0写法的意义的主要内容,如果未能解决你的问题,请参考以下文章
Day472&473&474.Netty 核心模块组件 -netty
Day477&478&479.Netty核心源码 -netty