-############################################################################
-# sendfile functions
-############################################################################
-
-unless ($SYS_sendfile) {
- _load_syscall();
- $SYS_sendfile = eval { &SYS_sendfile; } || 0;
-}
-
-sub sendfile_defined { return $SYS_sendfile ? 1 : 0; }
-
-if ($^O eq "linux" && $SYS_sendfile) {
- *sendfile = \&sendfile_linux;
-} elsif ($^O eq "freebsd" && $SYS_sendfile) {
- *sendfile = \&sendfile_freebsd;
-} else {
- *sendfile = \&sendfile_noimpl;
-}
-
-sub sendfile_noimpl {
- $! = ENOSYS;
- return -1;
-}
-
-# C: ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count)
-# Perl: sendfile($write_fd, $read_fd, $max_count) --> $actually_sent
-sub sendfile_linux {
- return syscall(
- $SYS_sendfile,
- $_[0] + 0, # fd
- $_[1] + 0, # fd
- 0, # don't keep track of offset. callers can lseek and keep track.
- $_[2] + 0 # count
- );
-}
-
-sub sendfile_freebsd {
- my $offset = POSIX::lseek($_[1]+0, 0, SEEK_CUR) + 0;
- my $ct = $_[2] + 0;
- my $sbytes_buf = "\0" x 8;
- my $rv = syscall(
- $SYS_sendfile,
- $_[1] + 0, # fd (from)
- $_[0] + 0, # socket (to)
- $offset,
- $ct,
- 0, # struct sf_hdtr *hdtr
- $sbytes_buf, # off_t *sbytes
- 0); # flags
- return $rv if $rv < 0;
-
-
- my $set = unpack("L", $sbytes_buf);
- POSIX::lseek($_[1]+0, SEEK_CUR, $set);
- return $set;
-}
-
-