Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Selector bug?

Reply
Thread Tools

Selector bug?

 
 
Andersen
Guest
Posts: n/a
 
      01-28-2006

I am doing non-blocking I/O with NIO when reading and writing to sockets.

My Selector.select() call returns with result 0, and does not block,
which it is supposed to do. What can be wrong? I am not doing wakeup()
and no exceptions are being thrown.
 
Reply With Quote
 
 
 
 
Andersen
Guest
Posts: n/a
 
      01-28-2006
Bug fixed.

Not sure if the bug is due to an undocumented NIO feature or not.

Here it is:
I was creating new channels, setting interest ops WRITE, READ, and
CONNECT. But in practise, I was connecting in blocking mode, ensuring
that connect() finishes properly. Thereafter I would put the channel in
non-blocking mode, and registering it with the above OPs...

I.e., OP_CONNECT was set as interested bit, but I was actually never
connect()ing with non-blocking IO. As a result, the select() was
returning with 0.

I now removed the OP_CONNECT and everything works perfectly.

Notice that select() never ever returned with the SelectionKey saying
isConnectable(), because I had already connected properly.

 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      01-28-2006
Andersen wrote:
>
> I am doing non-blocking I/O with NIO when reading and writing to sockets.
>
> My Selector.select() call returns with result 0, and does not block,
> which it is supposed to do. What can be wrong? I am not doing wakeup()
> and no exceptions are being thrown.


The remaining possibility, according to the documentation, is that the
thread has been interrupted. The docs do no mention clearing the status.
So presumably an interrupted selection thread will spin. You can check
and clearly the interrupt status with the oddly named Thread.interrupted.

http://download.java.net/jdk6/docs/a...l#interrupted()

OTOH, it's not exactly unknown for NIO to have bugs.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      02-07-2006
Andersen wrote:

> Bug fixed.
>
> Not sure if the bug is due to an undocumented NIO feature or not.
>
> Here it is:
> I was creating new channels, setting interest ops WRITE, READ, and
> CONNECT. But in practise, I was connecting in blocking mode, ensuring
> that connect() finishes properly. Thereafter I would put the channel in
> non-blocking mode, and registering it with the above OPs...
>
> I.e., OP_CONNECT was set as interested bit, but I was actually never
> connect()ing with non-blocking IO. As a result, the select() was
> returning with 0.
>
> I now removed the OP_CONNECT and everything works perfectly.


Leaving aside the issue of how best to use OP_WRITE, which has already
been dealt with, you should never register for OP_WRITE *and* OP_CONNECT
at the same time. If you want the connection completion event, register
for OP_CONNECT *only*: when you get it, deregister OP_CONNECT and *then*
register OP_READ and/or OP_WRITE.

Reason: under the hood OP_WRITE and OP_CONNECT may be the same thing,
and Java doesn't necessarily succeeded in pretending they are different.
Ditto for OP_READ and OP_ACCEPT at the server side.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Person Selector Control Johnny Holland ASP .Net 0 03-30-2005 04:03 PM
warning message for case statements where the selector signal is of type std_logic_vector profpenguin@shaw.ca VHDL 6 02-11-2005 05:38 AM
Multi list box selector and post back question Brian Henry ASP .Net 3 08-18-2004 11:31 PM
Data grid with current page combo box selector Brian Henry ASP .Net 2 07-22-2004 11:13 AM
Color selector Chris ASP .Net 1 12-10-2003 02:42 PM



Advertisments