So, I push my handles into the IO::Select object and supposedly both IO::Select->can_read() and IO::Select->select($handles, undef, undef, 0) are supposed to block until any one of the handles has some data, e.g.:
can_read ( [ TIMEOUT ] ) Return an array of handles that are ready for reading. "TIMEOU +T" is the maximum amount of time to wait before returning an empty l +ist, in seconds, possibly fractional. If "TIMEOUT" is not given and + any handles are registered then the call will block.
But when I try this, it doesn't block on the filehandle, and keeps looping with no new data in the file. Here is my sample minimal code where I am only working with the file handle and no TCP sockets:
#!/usr/bin/perl use IO::Select; open $fh, '/tmp/test_file'; $sel = new IO::Select( $fh ); while(@ready = $sel->can_read) { print "looping\n"; foreach $h (@ready) { if ($h == $fh) { print "reading from fh\n"; while ($buf = <$h>) { print $loop++," $buf"; } } else { print "handle is unknown\n"; } } }
This tails my file just fine, but it doesn't block when the file is not changing. Any suggestions?
(I do know about File::Tail, in case anyone was going to suggest that, but I couldn't see how to implement it non-blocking and integrate that with the socket listener.)
Thanks.
In reply to blocking, non-blocking, and semi-blocking by genecutl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |