How does sendfile() operate internally?
I want to know whether the sendfile() function in Linux works by implementing splice() function or not, for the purpose of copying the contents of one file to another.
If I write the following: sendfile(source,dest,NULL,block); Or this: splice(source,0,pipefd[1],NULL,block,SPLICE_F_MORE|SPLICE_F_MOVE); splice(pipefd[0],NULL,dest,0,block,SPLICE_F_MORE|SPLICE_F_MOVE); Will both methods work in a similar way internally? Does sendfile() also make use of pipes? |
Sendfile() can be used to transmit data from a "file" to a "socket"to get data from one machine to another machine. Sendfile() needs the source of data to be "page/buffer" cache. Sendfile does copy data.
Splice requires that at least either the source or target file descriptors be a pipe. It only reads and writes. It does not actually copy. References for your benefit: http://blog.superpat.com/2010/06/01/...le-and-splice/ kerneltrap.org/node/6505 (Linus Torvalds word on the topic of splice() and tee(). ) Hope this helps. |
Quote:
|
The second link that you provided, proved to be helpful. Thank you for the help.
But I believe you were wrong when you said that sendfile() can be used to copy contents between a file and a socket. The sendfile() man page clearly states that since Linux kernels 2.6.33, the destination file descriptor can be either a socket or a regular file. In the latter case, sendfile copies contents of one file to another. |
Glad I could help. Sorry for the improper definition of sendfile() .
You should mark in your initial post TITLE that the topic is solved, if your satisfied. |
All times are GMT -5. The time now is 03:47 PM. |