in reply to nonblocking I/O - testing whether file has more data to read

Oh my head hurts thinking about all those low-level details, and I'm not sure I'm correctly interpreting your problem. But I thought you might like to read perldoc -q filehandle which has some code for dealing with blocking filehandles. I used the following code to test for anything in the pipe, before trying to read it. That way, you read if there is something there, else move on to the next.
#see which filehandles have output from perldoc -q filehandle $esize = pack("L", 0); ioctl(\*ERROR, FIONREAD(), $esize) or die "Couldn't call ioctl: +$!\n"; $esize = unpack("L", $esize); print "esize-> $esize\n" unless ($esize < 1); $rsize = pack("L", 0); ioctl(\*READ, FIONREAD(), $rsize) or die "Couldn't call ioctl: $ +!\n"; $rsize = unpack("L", $rsize); print "rsize-> $rsize\n" unless ($rsize <1); #get the output from bc if($esize > 0){sysread(ERROR,$error,$esize); $errortot = $errorto +t.$error} if($rsize > 0){sysread(READ,$answer,$rsize); $answertot = $answer +tot.$answer} } until(($esize > 0)or(($rsize > 0)and($rsize < 4060)));

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re: Re: nonblocking I/O - testing whether file has more data to read
by hv (Prior) on Apr 12, 2004 at 16:24 UTC

    Interesting stuff, if painfully low level. However, characteristics of individual ioctl calls are device-dependent, and that FAQ mentions lower down:

    FIONREAD requires a filehandle connected to a stream, meaning that sockets, pipes, and tty devices work, but not files.

    Since I am reading plain files, that isn't going to work for me.

    Hugo