Using OP_CONNECT with Selector.select causes selector to fire repeatedly
Deven You
youdwei at linux.vnet.ibm.com
Wed May 9 00:26:56 PDT 2012
Hi All,
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[1], 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[2].
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[3] for this approach.
Could anyone take a look at this patch to see if we could solve this
problem in this way!
[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4919127
[2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4960791
[3] http://cr.openjdk.java.net/~littlee/ojdk-317/webrev.00/
<http://cr.openjdk.java.net/%7Elittlee/ojdk-317/webrev.00/>
Thanks a lot!
--
Best Regards,
Deven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20120509/ae4ba4f2/attachment.html
More information about the net-dev
mailing list