diff options
author | Jakub Stasiak <jakub@stasiak.at> | 2020-11-12 09:49:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-12 09:49:30 (GMT) |
commit | fd4ed57674c675e05bd5d577dd5047a333c76c78 (patch) | |
tree | 18a6b87609ebbbe54a71234397333600fa41da64 /Modules/posixmodule.c | |
parent | 877df851c3ecdb55306840e247596e7b7805a60a (diff) | |
download | cpython-fd4ed57674c675e05bd5d577dd5047a333c76c78.zip cpython-fd4ed57674c675e05bd5d577dd5047a333c76c78.tar.gz cpython-fd4ed57674c675e05bd5d577dd5047a333c76c78.tar.bz2 |
bpo-42237: Fix os.sendfile() on illumos (GH-23154)
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 70b47c4..6b51d8a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -9873,11 +9873,26 @@ done: if (offset >= st.st_size) { return Py_BuildValue("i", 0); } + + // On illumos specifically sendfile() may perform a partial write but + // return -1/an error (in one confirmed case the destination socket + // had a 5 second timeout set and errno was EAGAIN) and it's on the client + // code to check if the offset parameter was modified by sendfile(). + // + // We need this variable to track said change. + off_t original_offset = offset; #endif do { Py_BEGIN_ALLOW_THREADS ret = sendfile(out_fd, in_fd, &offset, count); +#if defined(__sun) && defined(__SVR4) + // This handles illumos-specific sendfile() partial write behavior, + // see a comment above for more details. + if (ret < 0 && offset != original_offset) { + ret = offset - original_offset; + } +#endif Py_END_ALLOW_THREADS } while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals())); if (ret < 0) |