in reply to EINTR and sysread()
You are never going to lose any data when reading from a pipe, even if the system call is restarted. However, perhaps what could be happening is that your syswrite is getting interrupted and not writing all of $buffer. You really need to check what syswrite returns and re-buffer what didn't get written for a future write. Note that $wbytes != $rbytes doesn't necessarily mean that an error has occurred, especially when writing to a pipe. The write can be short if the pipe doesn't have enough space for the entire write buffer. The only return values from syswrite that signal an error are 0 and undef.
Update 1: I'll have to double check if a return value of 0 from syswrite signals an error. It does with the system call write but it might not be the case with perl.
Update 2: A common technique for handling an I/O buffer is as follows:
my $buf; while (1) { my $nr = sysread(IN, $buf, 1024, length($buf)); unless ($nr) { ...handle EOF or error... }; ... if (length($buf)) { my $nw = syswrite(OUT, $buf, length($buf)); unless (defined($nw)) { ...handle error... } substr($buf, 0, $nw, ''); } ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: EINTR and sysread()
by bot403 (Beadle) on Apr 03, 2008 at 17:00 UTC |