Skip to content

Commit

Permalink
bpo-42237: Fix os.sendfile() on illumos (GH-23154)
Browse files Browse the repository at this point in the history
(cherry picked from commit fd4ed57)

Co-authored-by: Jakub Stasiak <jakub@stasiak.at>
  • Loading branch information
miss-islington and jstasiak authored Nov 12, 2020
1 parent 33922cb commit 7ae19ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `os.sendfile()` on illumos.
15 changes: 15 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -9469,11 +9469,26 @@ os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
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)
Expand Down

0 comments on commit 7ae19ef

Please sign in to comment.