views:

107

answers:

1

Im programming webserver (C), which should send big files. My question is: What are the main differences in two syscalls: write and sendfile. Does sendfile depends on size of socket system buffer? I noticed that write often writes less then I requested.

For example, if got many requests for one file: should i open it, copy into memory and use write, or maybe I can do sendfile for each client?

Thanks in advance for all answers.

+3  A: 

Please read sendfile(2).

sendfile() copies data between one file descriptor and another. Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space.

Regarding return value any of write/read/senfile calls do not guarantee that entire block of data is written/read/sent

Daniel Băluţă