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

Reply via email to