in reply to Non-blocking I/O woes

The $select->can_read() does not block, despite what documentation says. It keeps reporting that there's something in STDIN, even if there's nothing there for sure

Define "nothing", sysread returning false? Then the handle is closed due to error (undef) or due to eof (zero). You need to handle those conditions. You are calling select (via can_read) on a handle that can't possibly ever return data.


By the way, the following is buggy:

my $rv = $handle->sysread($bufline, 4096); $line .= $bufline; while ($rv == 4096) { $rv = $handle->sysread($bufline, 4096); $line .= $bufline unless !$rv; }

It'll block if there's exactly 4096 bytes waiting. Remove the loop completely. You need to rely on your select (can_read) loop. What follows in the code should just restart the select loop unless it detects that it received a full message. This requires moving your handle's buffer ($line) outside of the loop, of course. In other words, the code should follow the following pattern:

- While there are handles from which to read, - Wait for data to arrive. - Read into the handle's buf. -> Don't forget to handle eof and error. - While the buf has a full command, - Remove the command from the buf. - Process the command.

By the way,

my $bufline = ""; my $rv = $handle->sysread($bufline, 4096); $line .= $bufline;

can be written as

my $rv = $handle->sysread($line, 4096, length($line));