I am developing a program by read data from disk and sent to network socket.
I use memfd_create()
to create a memory file as buffer and get the mem_fd
, use ftruncate()
to set the file size, and mmap()
to map the buffer address buf
.
The program repeatedly read data into buf
, and sent mem_fd
using sendfile()
. When sendfile()
call returns, the return value is checked (it says all data has been sent), then new data starts overwrite into buf
.
But I found the data may be wrong sometimes, it looks like sendfile()
sending the overwritten data rather than the old data.