Using OP_CONNECT with Selector.select causes selector to fire repeatedly
youdwei at linux.vnet.ibm.com
Wed May 9 00:26:56 PDT 2012
When start a simple server, listening on a port like 8765, which just
accepts connections. We then register a non-blocking SocketChannel (the
client) with a selector with interest in OP_CONNECT, so that we can use
the selector to notify us when the channel is ready to finish connecting.
We call client.connect and then selector.select in a loop. The selector
fires and with the client channel in the selected-keys set and we call
finishConnect() on the client's channel.
Then the problem occurs:
The selector repeatedly fires with no entries in its selected-keys set,
whereas it should block in the next select operation until there is at
least one key in the selected-keys set.
There is already a sun bug for this issue, when I looked into this
sun bug I realize the second scenario of this sun bug is described very
detailed by a duplicate sun bug.
One way to solve this problem is let selector reset the OP_CONNECT bit
as 0 after the channel is connected for the corresponding key using
key.interestOps(). I just make a patch for this approach.
Could anyone take a look at this patch to see if we could solve this
problem in this way!
Thanks a lot!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the net-dev