[3.9] bpo-41687: Fix sendfile implementation to work with Solaris (GH-22040) (GH-22273)

(cherry picked from commit 8c0be6fd91)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
This commit is contained in:
Łukasz Langa 2020-09-16 13:52:26 +02:00 committed by GitHub
parent a4677068dd
commit 7e356f17e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -445,6 +445,12 @@ class SendfileMixin(SendfileBase):
self.assertEqual(srv_proto.data, self.DATA) self.assertEqual(srv_proto.data, self.DATA)
self.assertEqual(self.file.tell(), len(self.DATA)) self.assertEqual(self.file.tell(), len(self.DATA))
# 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): def test_sendfile_close_peer_in_the_middle_of_receiving(self):
srv_proto, cli_proto = self.prepare_sendfile(close_after=1024) srv_proto, cli_proto = self.prepare_sendfile(close_after=1024)
with self.assertRaises(ConnectionError): with self.assertRaises(ConnectionError):

View File

@ -0,0 +1 @@
Fix implementation of sendfile to be compatible with Solaris.

View File

@ -9453,6 +9453,25 @@ done:
if (!Py_off_t_converter(offobj, &offset)) if (!Py_off_t_converter(offobj, &offset))
return NULL; return NULL;
#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 = fstat(in_fd, &st);
Py_END_ALLOW_THREADS
} while (res != 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
if (ret < 0)
return (!async_err) ? posix_error() : NULL;
if (offset >= st.st_size) {
return Py_BuildValue("i", 0);
}
#endif
do { do {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
ret = sendfile(out_fd, in_fd, &offset, count); ret = sendfile(out_fd, in_fd, &offset, count);