Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:01:46+00:00 2026-06-13T22:01:46+00:00

sendfile() copies data between two file descripters within kernel space. Somewhere I saw if

  • 0

sendfile() copies data between two file descripters within kernel space. Somewhere I saw if you are writing a web server in C in linux you should use send() and recv() instead of using write() and read(). So is the send() use the kernel space as well?

Whatever I use for sending – sendfile() or send() – on the client side I’ll be using recv() right?

On the flip side, man page says: “The only difference between send() and write(2) is the presence of flags. With a zero flags argument, send() is equivalent to write(2).”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:01:47+00:00Added an answer on June 13, 2026 at 10:01 pm

    If fd is a socket file descriptor, then these system calls are identical:

    • send(fd, data, length, 0) is the same as write(fd, data, length)
    • recv(fd, data, length, 0) is the same as read(fd, data, length)

    So, unless you need to set a non-zero flags parameter, it makes no difference whether you use send/recv or write/read.

    The sendfile system call is an optimization. If you have a socket sockfd and a regular file filefd and you want to copy some file data to the socket (e.g. if you’re a web server serving up a file), then you might write it like this:

    // Error checking omitted for expository purposes
    while(not done)
    {
        char buffer[BUFSIZE];
        int n = read(filefd, buffer, BUFSIZE);
        send(sockfd, buffer, n, 0);
    }
    

    However, this is inefficient: this involves the kernel copying the file data into userspace (in the read call) and then copying the same data back into kernel space (in the send call).

    The sendfile system call lets us skip all of that copying and have the kernel directly read the file data and send it on the socket in one fell swoop:

    sendfile(sockfd, filefd, NULL, BUFSIZE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to send a file to a web service (ebridge) using their SendFile
I'm building a basic file server and my program cannot find files. def sendfile(sock,
I want my web application users to download some data as an Excel file.
Can sendfile() linux syscall be used to send part of file from one mmaped
I'm trying to test the sendfile() system call under Linux 2.6.32 to zero-copy data
I have two programs, sendfile.py and recvfile.py that are supposed to interact to send
I have two programs, recvfile.py and sendfile.cpp. They work except that I end up
Here's the code: private void sendFile(InputStream file, OutputStream out) throws IOException { Log.d(TAG, trying
I have a file transfer application (server-client) ... while sending a file, i want
Where I can get sendfile function sources? I can't find it in kernel sources...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.