() ludo@gnu.org (Ludovic Courtès) () Tue, 16 Apr 2013 18:31:00 +0200 Thien-Thi Nguyen skribis: > My reading of sendfile(2) is that it does its best to send as much > as possible, but does not guarantee sending everything. What it > does succeed in sending, it reports to the caller. The caller > loops as desired, after evaluating (in some caller-meaningful way) > the returned information. Just a note, this information is definitely not conveyed by the man page: sendfile() copies data between one file descriptor and another. [...] count is the number of bytes to copy between the file descriptors. Yes, that part is what you tell (request of) the OS, not what the OS tells (reports to) you. I think the manpage is not remiss here. Of course the return type hints at a write(2)-like interface, but the truth is that short writes had to be evidenced by experimental validation, so to speak. Well, i don't know what the truth is, but certainly it can be easy to misinterpret the sendfile(2) manpage if you don't take all of it into account. The major hint is actually: If offset is not NULL, then it points to a variable holding the file offset from which sendfile() will start reading data from in_fd. When sendfile() returns, this variable will be set to the offset of the byte following the last byte that was read. That is basically another way of saying that the syscall "does its best to send as much as possible, but does not guarantee sending everything". This is also conveyed in the general context of system programming, where an OS that guarantees a single-syscall full write of a possibly multi-gigabyte file is an OS that can be easily bludgeoned to death by mischievous (or simply misbehaving) userland programs, the eventual consequence being OS writers tend to avoid making such guarantees (especially for i/o, where the Real World is known to be Real Weird). Anyway, i hope Guile grows a ‘sendfile-some’ (or whatever) so that i can adapt my programs to use it instead of the ttn-do ‘sendfile’: http://www.gnuvola.org/software/ttn-do/ttn-do.html.gz#zz-sys-linux-gnu Until then, happy hacking! -- Thien-Thi Nguyen GPG key: 4C807502