I am trying to understand java.nio.I am making simple echo server. Suppose we got keyCycler - which is iterator and then:
SelectionKey key = (SelectionKey)keyCycler.next();
//Retrieve set of ready ops for
//this key (as a bit pattern)...
int keyOps = key.readyOps();
if ((keyOps & SelectionKey.OP_ACCEPT)== SelectionKey.OP_ACCEPT)
I want to know wheather this
if ((keyOps & SelectionKey.OP_ACCEPT)== SelectionKey.OP_ACCEPT)
always equal to this
if(key.isAcceptable())
if no, in which cases they are different. Probably I got the whole thing wrong..
Compare to the source code :
return (readyOps() & OP_CONNECT) != 0;
Since the bitmask of which OP_CONNECT
has mutually-exclusive bits, this is identical to your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.