Subject: | sendfile_freebsd |
FreeBSB sendfile implementation seems broken.
first, there is a little mistake line 176:
Show quoted text
> POSIX::lseek($_[1]+0, SEEK_CUR, $set);
SEEK_CUR and $set shall be reversed
secondly, freeebsd sendfile implementation returns -1 on partial reads,
so sendfile_freebsd should return $set when it is not null and errno ==
EAGAIN
so here is a modified version of sendfile_freebsd() :
use Errno "EAGAIN";
use constant SEEK_SET => &POSIX::SEEK_CUR; # POSIX fails to export real
constants
sub sendfile_freebsd {
my $offset = POSIX::lseek($_[1]+0, 0, SEEK_CUR) + 0;
my $sbytes_buf = "\0" x 8;
my $rv = syscall(
$SYS_sendfile,
$_[1] + 0, # fd (from)
$_[0] + 0, # socket (to)
$offset,
$_[2] + 0,
0, # struct sf_hdtr *hdtr
$sbytes_buf, # off_t *sbytes
0); # flags
return $rv if $rv < 0 && $! != EAGAIN;
if (my $set = unpack("L", $sbytes_buf)) {
POSIX::lseek($_[1]+0, $set, SEEK_CUR);
return $set;
}
return $rv < 0 ? $rv : 0;
}