LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-07-2012, 08:17 AM   #1
Joohi
LQ Newbie
 
Registered: Feb 2012
Posts: 4

Rep: Reputation: Disabled
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?
 
Old 02-07-2012, 04:52 PM   #2
NEQTAN
Member
 
Registered: Jan 2012
Location: ND USA
Distribution: Linux Mint 12
Posts: 52

Rep: Reputation: 1
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.
 
1 members found this post helpful.
Old 02-07-2012, 05:28 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,154

Rep: Reputation: 333Reputation: 333Reputation: 333Reputation: 333
Quote:
Originally Posted by NEQTAN View Post
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/
http://kerneltrap.org/node/6505 (Linus Torvalds word on the topic of splice() and tee(). )

Hope this helps.
Restating the second reference as a link . . .
 
Old 02-08-2012, 12:11 AM   #4
Joohi
LQ Newbie
 
Registered: Feb 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.
 
Old 02-08-2012, 09:54 PM   #5
NEQTAN
Member
 
Registered: Jan 2012
Location: ND USA
Distribution: Linux Mint 12
Posts: 52

Rep: Reputation: 1
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.

Last edited by NEQTAN; 02-08-2012 at 10:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Support for sendfile system call on linux kernels later than 2.6.33 ankit.s.shah Linux - Kernel 2 12-25-2011 03:50 AM
How to prepend header to sendfile? vargadanis Programming 0 08-07-2008 03:04 PM
Disabling sendfile and mmap in lighttpd benrose111488 Linux - Software 0 07-05-2007 11:12 PM
LXer: An improved sendfile facility for FreeBSD LXer Syndicated Linux News 0 09-21-2006 09:03 AM
What prevents the implementation of sendfile() from socket to file? shy Programming 12 11-20-2004 02:26 PM


All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration