Uwe Kubosch wrote:
On Sat, 2008-09-06 at 04:46 -0500, Charles Oliver Nutter wrote:
Uwe Kubosch wrote:
No, it is not working in JRuby, only on MRI. And I am running out of
options.  Next thing to try is using javax.comm API and RXTX, but I had
REALLY hoped to avoid using native code...

Currently File#getc fails with "Illegal Seek" when reading
from /dev/ttyS0 on Linux.  If that worked, I could keep the reader
thread separate, and only have a timeout on threads copying data from my
own input buffer.
Ok...no guarantees on when, but we can make it a priority. Have you already filed a bug for the issue? Do so if not. Hopefully we can find a way to make this interruptible/timeoutable for you. There's also the possibility of calling out to C via FFI to do a "real" select, though that would be a more drastic measure. At any rate, we'll find a way.

Thanks a lot!  I keep being impressed by how quickly you respond.  For
time frame:  We need to have a working system this month :)  Serial
communication i critical core functionality, and must work reliably.

I'm at home now and for some reason my laptop has no serial port, so
Linux reports IOError on any operation on /dev/ttyS0, but I will enter
the bug report into JIRA from memory.  Spent all of yesterday and
Thursday on this :)  Will retry on monday.

My primary worry at this point is that select on a serial port *file* may simply not work, or may always immediately return that the file is ready to be read. This is half standard select behavior, half JVM not allowing us to select on files. So that could be a problem if in this case select is supposed to do the right thing.

If it turns out that selecting on a serial port is simply not possible with NIO, we may have to turn to the alternatives like FFI to open the port and select on it or javacomm. Neither are particularly appealing.

You might do some research to see if you can find other cases of people wanting to be able to do interruptible IO against a serial port file.

There is also a third option...Java does allow interrupting an IO read on just about anything, but it renders the underlying channel unusable (since it can no longer guarantee the state of buffers and such). So we could simply make it possible for you to *directly* interrupt a thread. This might even work already if you go after the real native thread representing a Ruby thread; but be forewarned the channel will probably not be usable afterward:

native_thread = nil
ruby_thread = Thread.new do
  native_thread = java.lang.Thread.current
  ... blocking read operation here
end
1 until native_thread

...

if timeout_exceeded
  native_thread.interrupt
end

Don't tell anyone I showed you how to do this. :)

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to