Liu, Hui (GXS) wrote:
There appears to be a bug with the read and sysread functions when being used in a loop to read STDIN. We're using a loop to read from STDIN in 4k blocks, and the read or sysread appears to work great until the very last read to pick up the final partial block. Here is the code:

$readSize = &min($bytesLeft, $blockReadSize); $bufferLength = length($buffer); $bytesRead = sysread(STDIN, $dataRead, $readSize); &html("bytesRead=[$bytesRead . $bufferLength . $dataRead]") if ($debug);
if (!(defined $bytesRead)) { $bytesRead = 0; } $buffer .= $dataRead; In the last loop, the values that are returned in the debug statement are: 674 . 3268 .
So sysread says that 674 bytes were read, however $dataRead is empty. Both read and sysread exhibit the same behavior, returning the right number of bytes to be read, but not populating the variable with the actual data. This code works fine in versions of Perl other than Apache modperl. Has anyone experienced this behavior and have any suggestions?

Could it be the buffering issue as described in the manpage?


perldoc -f sysread:

       sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
       sysread FILEHANDLE,SCALAR,LENGTH
               Attempts to read LENGTH characters of data into variable SCALAR
               from the specified FILEHANDLE, using the system call read(2).
               It bypasses buffered IO, so mixing this with other kinds of
               reads, "print", "write", "seek", "tell", or "eof" can cause
               confusion because stdio usually buffers data.  Returns the num-
               ber of characters actually read, 0 at end of file, or undef if
               there was an error.  SCALAR will be grown or shrunk so that the
               last byte actually read is the last byte of the scalar after
               the read.
               [...]

can you try whether you get all the data, by reading via <STDIN> (even though you have no control over chunks size)



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



Reply via email to