Kevin White writes:
> I am working on a java wrapper for a linux library that uses files to
> open(), read(), and issue ioctl() calls to a device. I assume I can
> open() and read() the device file as I would any standard file in java.
Yes. Be careful not to use Buffered{Input,Output}Stream with device
files unless you really mean it. Also, devices (depending on how
they're written) often capriciously return less data than you asked
for. That's not a bug; if it happens, it just means you have to call
read() multiple times to get all the data you want, just like you must
when reading from a socket.
> What about the ioctl() calls? Can I do these in java wthout using JNI?
Not portably, no.
> If I use jni, I have seen references that certain system calls (open(),
> read(), etc.) cannot be used in the native code, due to green thread
> issues. Is this still the case? Is there anyway I will be able to make
> the ioctl calls?
I haven't tried this, but it shouldn't be a problem. When using
green_threads, only system calls which might block are restricted --
that's because you don't want all the threads to stop when one thread
goes into one of those system calls. Most drivers don't sleep for
ioctl() calls, so you probably don't need to worry about this.
If your driver's ioctl() might sleep, then you have problems;
specifically you have to live with all your threads stopping when that
ioctl() sleeps. (When calling read() and write() from native code
under green_threads, you can link against wrapper functions that
transfer control to another thread instead of blocking.
Unfortunately, since there's no way to predict whether an ioctl() will
block--since it's not "supposed" to block in the first place--the same
trick won't work there.
Best,
daniel dulitz
Valley Technologies, Inc. Peak Performance Real-Time DSP
State College, PA
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]