sendfile() doesn't work to copy normal text file
Question
The problem with sendfile is it can't copy two text files using the file fds. The error is EINVAL. // Descriptor is not valid or locked, or an mmap()-like operation is not available for in_fd.
What does this really mean ?
From the man page of sendfile ( man sendfile ) I found this statement. Not sure if it will work to copy two regular files or not.
Presently (Linux 2.6.9): in_fd, must correspond to a file which supports mmap()-like operations (i.e., it cannot be a socket); and out_fd must refer to a socket.
Applications may wish to fall back to read(2)/write(2) in the case where sendfile() fails with EINVAL or ENOSYS.
Solution
The idea behind sendfile()
is to quickly send a file over a socket (think web servers). Regular files can be mmap()
ed, but are not sockets, so it's blowing up when you hand it a regular file as the destination.