[Python-checkins] (no subject)

Jakub Kulík webhook-mailer at python.org
Sat Sep 5 15:10:10 EDT 2020




To: python-checkins at python.org
Subject: bpo-41687: Fix sendfile implementation to work with Solaris (#22040)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/8c0be6fd9101746235b63ddfb84106d1e9ca=
286b
commit: 8c0be6fd9101746235b63ddfb84106d1e9ca286b
branch: master
author: Jakub Kul=C3=ADk <Kulikjak at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-09-05T12:10:01-07:00
summary:

bpo-41687: Fix sendfile implementation to work with Solaris (#22040)

files:
A Misc/NEWS.d/next/Library/2020-09-01-15-57-51.bpo-41687.m1b1KA.rst
M Lib/test/test_asyncio/test_sendfile.py
M Modules/posixmodule.c

diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/t=
est_sendfile.py
index a30d9b9b4d9a0..01c698653ec67 100644
--- a/Lib/test/test_asyncio/test_sendfile.py
+++ b/Lib/test/test_asyncio/test_sendfile.py
@@ -446,6 +446,12 @@ def test_sendfile_ssl_close_peer_after_receiving(self):
         self.assertEqual(srv_proto.data, self.DATA)
         self.assertEqual(self.file.tell(), len(self.DATA))
=20
+    # On Solaris, lowering SO_RCVBUF on a TCP connection after it has been
+    # established has no effect. Due to its age, this bug affects both Oracle
+    # Solaris as well as all other OpenSolaris forks (unless they fixed it
+    # themselves).
+    @unittest.skipIf(sys.platform.startswith('sunos'),
+                     "Doesn't work on Solaris")
     def test_sendfile_close_peer_in_the_middle_of_receiving(self):
         srv_proto, cli_proto =3D self.prepare_sendfile(close_after=3D1024)
         with self.assertRaises(ConnectionError):
diff --git a/Misc/NEWS.d/next/Library/2020-09-01-15-57-51.bpo-41687.m1b1KA.rs=
t b/Misc/NEWS.d/next/Library/2020-09-01-15-57-51.bpo-41687.m1b1KA.rst
new file mode 100644
index 0000000000000..284f500735701
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-09-01-15-57-51.bpo-41687.m1b1KA.rst
@@ -0,0 +1 @@
+Fix implementation of sendfile to be compatible with Solaris.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index a6a4b9f012f00..00ba7580302bb 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9518,6 +9518,25 @@ os_sendfile_impl(PyObject *module, int out_fd, int in_=
fd, PyObject *offobj,
     if (!Py_off_t_converter(offobj, &offset))
         return NULL;
=20
+#if defined(__sun) && defined(__SVR4)
+    // On Solaris, sendfile raises EINVAL rather than returning 0
+    // when the offset is equal or bigger than the in_fd size.
+    int res;
+    struct stat st;
+
+    do {
+        Py_BEGIN_ALLOW_THREADS
+        res =3D fstat(in_fd, &st);
+        Py_END_ALLOW_THREADS
+    } while (res !=3D 0 && errno =3D=3D EINTR && !(async_err =3D PyErr_Check=
Signals()));
+    if (ret < 0)
+        return (!async_err) ? posix_error() : NULL;
+
+    if (offset >=3D st.st_size) {
+        return Py_BuildValue("i", 0);
+    }
+#endif
+
     do {
         Py_BEGIN_ALLOW_THREADS
         ret =3D sendfile(out_fd, in_fd, &offset, count);



More information about the Python-checkins mailing list