Skip to content

Commit 7e356f1

Browse files
ambvkulikjak
andauthored
[3.9] bpo-41687: Fix sendfile implementation to work with Solaris (GH-22040) (GH-22273)
(cherry picked from commit 8c0be6f) Co-authored-by: Jakub Kulík <[email protected]>
1 parent a467706 commit 7e356f1

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
@@ -445,6 +445,12 @@ def test_sendfile_ssl_close_peer_after_receiving(self):
445445
self.assertEqual(srv_proto.data, self.DATA)
446446
self.assertEqual(self.file.tell(), len(self.DATA))
447447

448+
# On Solaris, lowering SO_RCVBUF on a TCP connection after it has been
449+
# established has no effect. Due to its age, this bug affects both Oracle
450+
# Solaris as well as all other OpenSolaris forks (unless they fixed it
451+
# themselves).
452+
@unittest.skipIf(sys.platform.startswith('sunos'),
453+
"Doesn't work on Solaris")
448454
def test_sendfile_close_peer_in_the_middle_of_receiving(self):
449455
srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
450456
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
@@ -9453,6 +9453,25 @@ os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
94539453
if (!Py_off_t_converter(offobj, &offset))
94549454
return NULL;
94559455

9456+
#if defined(__sun) && defined(__SVR4)
9457+
// On Solaris, sendfile raises EINVAL rather than returning 0
9458+
// when the offset is equal or bigger than the in_fd size.
9459+
int res;
9460+
struct stat st;
9461+
9462+
do {
9463+
Py_BEGIN_ALLOW_THREADS
9464+
res = fstat(in_fd, &st);
9465+
Py_END_ALLOW_THREADS
9466+
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
9467+
if (ret < 0)
9468+
return (!async_err) ? posix_error() : NULL;
9469+
9470+
if (offset >= st.st_size) {
9471+
return Py_BuildValue("i", 0);
9472+
}
9473+
#endif
9474+
94569475
do {
94579476
Py_BEGIN_ALLOW_THREADS
94589477
ret = sendfile(out_fd, in_fd, &offset, count);

0 commit comments

Comments
 (0)