sendfile reports success but no data sent in special case
When I send a small header with send() first, and then send a particular file with sendfile(), sendfile() will report success of all data sent, but not send any data to the socket, seemingly related to send length. I have created a minimal test case which reproduces the issue on my system.
I compile sendfile_case.c with:
$ cc -o sendfile_case sendfile_case.c
In another terminal, I run:
$ netcat -l -p 8089 > feed.log
sbytes = 16275
It exits fine, showing the whole file contents being sent, but netcat will be hung, and only will have printed the header.
This code works fine on Linux and OS X (in my application, with IFDEFs for different sendfile argument semantics, of course). The minimal case only does the DragonFly sendfile() call (and probably FreeBSD). I actually bisected it to find the failure threshold:
1792 failed (multiple times)
1791 succeeded (multiple times)
1791 sendfile bytes succeeds, and 1792 sendfile bytes fails. The previously sent header is 79 bytes, so 1870 total bytes succeeds, and 1871 total bytes failed.
The version I am running is about 2 months old. I searched for changes to the system call since then, and searched here, and didn't see anything related.