I am picking up the HTTP Range header to find the starting byte value and trying to pass that value as the offset param to sendfile. It appears to work (see below) for something like the first half of the file, and then stops working at all, returning immediately from sendfile().
Here's some code.
my $filename = "/path/to/file"; my $size = (stat($filename))[7];
$r->headers_out->set('Content-Length' => $size);
# check for Range header to see if we should start at an offset # A Range header looks like: # bytes=15361655- my $offset = 0; my $range = $r->headers_in->get('Range'); if ($range) { $offset = $range; $offset =~ s/bytes=//; $offset =~ s/-$//; $offset = 0 if ($offset =~ /\D/); # set back to 0 if no numbers }
$r->sendfile($filename, $offset);
I can find very little documention about the offset variable, only this: $ret = $r->sendfile($filename, $offset, $len);
* arg1: $r (Apache::RequestRec) * arg2: $filename (Apache::RequestRec) * arg3: $offset (string) * arg4: $len (integer) * ret: $ret (integer)
What gets me is, why is offset listed as a string and not an integer? Is it not an offset in bytes? My first thought is maybe this is an offset in hex because it did work for the first part of the file but stopped later in the fille as if it was trying to seek beyond the end of the file.
I know the offset value is being transposed to something at least, because I did a test download using several 206 requests, and the resluting file had gaps in it where it was resumed instead of being seamless.
Does anyone know anything about sendfile or offset in mp2? I am running Apache 2.0.48, mod_perl 1.99_10, with Perl 5.8.2 on Gentoo.
Thanks, -Andy
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html