Skip to content

Commit fd4ed57

Browse files
authored
bpo-42237: Fix os.sendfile() on illumos (GH-23154)
1 parent 877df85 commit fd4ed57

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix `os.sendfile()` on illumos.

Modules/posixmodule.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9873,11 +9873,26 @@ os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
98739873
if (offset >= st.st_size) {
98749874
return Py_BuildValue("i", 0);
98759875
}
9876+
9877+
// On illumos specifically sendfile() may perform a partial write but
9878+
// return -1/an error (in one confirmed case the destination socket
9879+
// had a 5 second timeout set and errno was EAGAIN) and it's on the client
9880+
// code to check if the offset parameter was modified by sendfile().
9881+
//
9882+
// We need this variable to track said change.
9883+
off_t original_offset = offset;
98769884
#endif
98779885

98789886
do {
98799887
Py_BEGIN_ALLOW_THREADS
98809888
ret = sendfile(out_fd, in_fd, &offset, count);
9889+
#if defined(__sun) && defined(__SVR4)
9890+
// This handles illumos-specific sendfile() partial write behavior,
9891+
// see a comment above for more details.
9892+
if (ret < 0 && offset != original_offset) {
9893+
ret = offset - original_offset;
9894+
}
9895+
#endif
98819896
Py_END_ALLOW_THREADS
98829897
} while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
98839898
if (ret < 0)

0 commit comments

Comments
 (0)