0

I tried this sendfile example:
https://github.com/pijewski/sendfile-example/blob/master/sendfile.c

I noticed, I can use sendfile with normal files and it works as expected.

I thought, on Linux, it can be used only if destination is network socket?

How it works? Do copy is done with read / write loop, just inside the kernel.

Nick
  • 9,962
  • 4
  • 42
  • 80
  • Linux is open-source. You can download and look at the source yourself. But most likely it wont be done by a read/write loop. Perhaps some direct memory mapping of buffers? – Some programmer dude Jul 13 '22 at 09:19
  • The point is, the documentation say it should not be possible... – Nick Jul 13 '22 at 09:27
  • 1
    "In Linux kernels before 2.6.33, out_fd must refer to a socket. Since Linux 2.6.33 it can be any file. If it is a regular file, then sendfile() changes the file offset appropriately." https://man7.org/linux/man-pages/man2/sendfile.2.html – oakad Jul 13 '22 at 09:29

0 Answers0