Skip to content

Commit 8c0be6f

Browse files
authored
bpo-41687: Fix sendfile implementation to work with Solaris (python#22040)
1 parent dd18001 commit 8c0be6f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Lib/test/test_asyncio/test_sendfile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ def test_sendfile_ssl_close_peer_after_receiving(self):
446446
self.assertEqual(srv_proto.data, self.DATA)
447447
self.assertEqual(self.file.tell(), len(self.DATA))
448448

449+
# On Solaris, lowering SO_RCVBUF on a TCP connection after it has been
450+
# established has no effect. Due to its age, this bug affects both Oracle
451+
# Solaris as well as all other OpenSolaris forks (unless they fixed it
452+
# themselves).
453+
@unittest.skipIf(sys.platform.startswith('sunos'),
454+
"Doesn't work on Solaris")
449455
def test_sendfile_close_peer_in_the_middle_of_receiving(self):
450456
srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
451457
with self.assertRaises(ConnectionError):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix implementation of sendfile to be compatible with Solaris.

Modules/posixmodule.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9518,6 +9518,25 @@ os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
95189518
if (!Py_off_t_converter(offobj, &offset))
95199519
return NULL;
95209520

9521+
#if defined(__sun) && defined(__SVR4)
9522+
// On Solaris, sendfile raises EINVAL rather than returning 0
9523+
// when the offset is equal or bigger than the in_fd size.
9524+
int res;
9525+
struct stat st;
9526+
9527+
do {
9528+
Py_BEGIN_ALLOW_THREADS
9529+
res = fstat(in_fd, &st);
9530+
Py_END_ALLOW_THREADS
9531+
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
9532+
if (ret < 0)
9533+
return (!async_err) ? posix_error() : NULL;
9534+
9535+
if (offset >= st.st_size) {
9536+
return Py_BuildValue("i", 0);
9537+
}
9538+
#endif
9539+
95219540
do {
95229541
Py_BEGIN_ALLOW_THREADS
95239542
ret = sendfile(out_fd, in_fd, &offset, count);

0 commit comments

Comments
 (0)