I'm working on a program that uses an epoll-based event loop to handle multiple simultaneous socket connections. When the app detects that there is data to be read, it calls a process_request() sub, which uses buffered IO. For example:
sub process_request {
my ( $fh ) = @_;
if ( my $line = <$fh> ) {
# Do something interesting
}
}
The trouble is that by using buffered I/O here, epoll doesn't know that there's unread data waiting in the buffer, so it doesn't call process_request() again.
So the question is, how can I detect if there is unread data in filehandle in Perl, so that I can call process_request() again as long as data remains in the buffer?