in reply to I got IPC::Open3 to work!
It doesn't look like you're handling partial reads or other exceptional conditions in your call to sysread(). Something like this might be a start.
use POSIX qw(EINTR EWOULDBLOCK EAGAIN); ... # Try to read 4096 bytes from $fh using sysread(). Icky. my $data; my $offset = 0; my $length = 4096; while($length > 0) # Handle partial reads { my $read = sysread($fh, $data, $length, $offset); unless(defined $read) { next if($! == EINTR || $! == EWOULDBLOCK || !$ == EAGAIN); # Handle other errors here ... } last if($read == 0); # EOF $offset += $read; $length -= $read; }
In practice, the details are somewhat reliant on the exact nature of the read(2) system call on your OS. The code above almost certainly does NOT handle all potential errors, but it's a start.
The big point is that you can't expect sysread() to actually read as much data as you ask it to read. At the very least, you have to handle partial reads and then either loop until you've read what you want (as shown above) or make some other sort of decision.
What you definitely don't want to do is treat something like an undef return caused by EINTR as a fatal error. That type of thing tends to crop up at the worst times (e.g., on a busy machine but never on your idle development box).
sysread() has similar annoyances associated with it. If it's at all possible to use the blocking versions (read() and write()) it will make your life a lot easier.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I got IPC::Open3 to work!
by ikegami (Patriarch) on Jul 23, 2005 at 07:31 UTC | |
by siracusa (Friar) on Jul 23, 2005 at 12:36 UTC | |
by harleypig (Monk) on Jul 24, 2005 at 16:04 UTC |