Search code examples
c++clinuxsocketssendfile

Sendfile without file descriptor


I have a memory region which contains data that I would like to send over ethernet to the other client. To increase the throughput, currently I am fiddling with sendfile API instead of the classic send/write API. But as far as I understand, the sendfile API requires a file descriptor for input, but what I have is only raw memory data. So what should I do in order to use the sendfile API?


Solution

  • The primary benefit of sendfile() is that it allows you to avoid the overhead of having to first read() data from a file descriptor into memory before you can send() it. If the data you want to send is already in memory, sendfile() is not needed. Using weird workarounds to move the data into a file (like mmap()ing it) will only reduce performance.