bpo-36488: os.sendfile() on BSD and macOS doesn't return bytes sent on EINTR by giampaolo · Pull Request #12807 · python/cpython (original) (raw)
I'm not sure why you're adding this. Would you care to explain or add a comment?
Sorry for the delayed response. I added a comment which should clarify what's going on. Basically sendfile() on OSX/BSD can fail with EINTR, EAGAIN or EBUSY (usually happens when using non-blocking sockets) but the &len
param can be set to something != 0 in case some data was sent (partial send). In this case this PR exits the while loop, ignores the error condition and return the value of &len
(number of bytes being sent) instead of raising an exception. I did this in accordance with "man sendfile" on MACOS and FreeBSB which describes this possibility (sendfile() failure -> errno set + &len
being set).
Basically the downside here is suppressing the error (which may be undesired in case of CTRL+C?) but the upside is to avoid losing information (which is crucial when keeping track of the file offset when sending a file in non-blocking mode). I'm CC-ing @vstinner since he co-authored PEP-0475 with Antoine.
It seems sbytes can be undefined here (on non-Apple platforms), especially if sendfile returns with an error?
See above + sbytes is always defined on BSD/OSX (although not initialized).