I'm doing something similar to that.

The problem I'm having now is that select returns, but read() blocks.
If I select non-blocking IO using fcntl, then I get an exception
instead.  If I use sysread, then I am told that I am using sysread for
buffered IO.

Curious as to how to get around the problem, I started to dig into io.c.
Both read() and sysread() call READ_DATA_PENDING, which is a macro that
expands to ReadDataPending.  But where is ReadDataPending defined?

Any ideas on how to read only the data that is available, and then
return to select() once that is done?  I know I can read byte-at-a-time
and catch EWOULDBLOCK, but that's not ideal.

Paul