Skip to content

Commit 371f7a3

Browse files
committed
[3.8] bpo-42237: Fix os.sendfile() on illumos (pythonGH-23154).
(cherry picked from commit fd4ed57) Co-authored-by: Jakub Stasiak <[email protected]>
1 parent c745b36 commit 371f7a3

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9281,9 +9281,27 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
92819281
if (!Py_off_t_converter(offobj, &offset))
92829282
return NULL;
92839283

9284+
9285+
#if defined(__sun) && defined(__SVR4)
9286+
// On illumos specifically sendfile() may perform a partial write but
9287+
// return -1/an error (in one confirmed case the destination socket
9288+
// had a 5 second timeout set and errno was EAGAIN) and it's on the client
9289+
// code to check if the offset parameter was modified by sendfile().
9290+
//
9291+
// We need this variable to track said change.
9292+
off_t original_offset = offset;
9293+
#endif
9294+
92849295
do {
92859296
Py_BEGIN_ALLOW_THREADS
92869297
ret = sendfile(out, in, &offset, count);
9298+
#if defined(__sun) && defined(__SVR4)
9299+
// This handles illumos-specific sendfile() partial write behavior,
9300+
// see a comment above for more details.
9301+
if (ret < 0 && offset != original_offset) {
9302+
ret = offset - original_offset;
9303+
}
9304+
#endif
92879305
Py_END_ALLOW_THREADS
92889306
} while (ret < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
92899307
if (ret < 0)

0 commit comments

Comments
 (0)