in reply to Can read() return less than LENGTH bytes?
Also, on some Unixes, if a signal arrives then it can interrupt the system call and cause it to return prematurely (with $! set to EAGAIN which means that there was no error and you should try the call again). I tried to construct an example for this but it didn't work, possibly because perl handles signals in a reasonably robust manner and restarts the read for you automatically.
That said, it seems that you don't need non-blocking IO or signals to get an example using sysread
when I type something in and hit enter the sysread returns immediately with far less than 1000 chars.sysread(STDIN, $buffer, 1000); print "read ".length($buffer). " chars\n$buffer\n";
|
|---|