Re: CGI ponderings
Tim Bunce (Tim.Bunce@ig.co.uk)
Sun, 18 Jun 1995 14:04:13 +0100
> From: Mark Anderson <mda@pure.com>
>
> > read_entity_body: read 734 of 1594 bytes
> >I read the comments in the code, and was looking for more background
> >on why the socket read would come up short. a deceiptful remote client?
>
A client is unlikely to be _that_ deceiptful.
> Read from a file descriptor is not guaranteed to complete in one step
> except when reading from a normal file.
That applies to the read() system call not perl's read() which actually
calls stdio fread(). I believe that fread() _should_ deal with partial reads.
The comments in CGI::Base say:
# Perl read() relies on C stdio fread() to deal with incomplete
# network reads. read() will block if trying to read too much.
> When reading from a handle which is a socket, you need to do something like
> the attached. (But maybe you knew that, or maybe perl's "read" already does
> this, or maybe CGI.pm is trying to do this and failing. I'm speaking here
> as someone with some experience with network programming but not much with
> perl or CGI.pm.)
>
> -mda
>
> sub read_on_socket
> while($nleft > 0)
> my $nread = sysread($handle, $buf, $nleft, $offset);
> $nleft -= $num_bytes;
> $offset += $nread;
>
At one point read_entity_body did something like this but after testing
with some big POST bodies I removed it and this is the first complaint.
Tom, could you try adding an extra read() inside that 'if' block to
try to read and append the left-over unread input. If that works then
I'll add some looping code back in. (If it does work I think it implies
that your stdio is broken. What platform are you on?)
Tim.
p.s. If I do put in the looping code it will use read() not sysread()
since mixing sysread() with $line=<$fh> style input used elsewhere
will not work reliably.