fcntl( $tail, F_SETFL(), O_NONBLOCK() );
sets the file to non-blocking. When the code gets to
if ( @lines = (<$tail>) ) {
It skips right by if nothing new has been added to the file. In fact, the fcntl statement might not be needed, because this line reads to the current EOF and then continues. The clearerr statement resets the EOF each time around so that the file can be tailed.
The select statement:
($new_readable) = IO::Select->select( $readable_handles, undef, undef, $TIMEOUT );
times out when no-one is connecting. I'm setting $TIMEOUT to 0.25 seconds. It will only block for that long, before continuing around the loop back to the file read. I'm using 0.25 as a compromise between availability and CPU usage.
In reply to Re^4: blocking, non-blocking, and semi-blocking
by genecutl
in thread blocking, non-blocking, and semi-blocking
by genecutl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |