Using OP_CONNECT with Selector.select causes selector to fire repeatedly

Deven You youdwei at linux.vnet.ibm.com
Wed May 9 00:33:29 PDT 2012


I suddenly realized this topic should be in nio-dev mailing list. Please 
ignore previous mail.

Thanks a lot!

On 05/09/2012 03:26 PM, Deven You wrote:
> 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


-- 
Best Regards,

Deven

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20120509/c128de9f/attachment.html 


More information about the nio-dev mailing list