-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-99813: Start using SSL_sendfile
when available
#99907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
a018beb
Add methods for checking whether kTLS is used
illia-v 72e7f5e
Start using `SSL_sendfile` when available
illia-v cf24d78
Try fixing warnings
illia-v e9ef747
Use unsigned `size_t` instead of `Py_ssize_t`
illia-v 646d328
Merge branch 'main' into SSL_sendfile
illia-v 76353c7
Merge branch 'main'
illia-v 14832de
Make `sendfile_impl` more similar to `write_impl`
illia-v 6b41d31
Modify `test_ssl` to test `SSL_sendfile` calls
illia-v 8ac6ff9
Modify documentation and add a news entry
illia-v 5cf9483
Fix a test
illia-v fc8e82f
Rename `uses_ktls_for_write` to `uses_ktls_for_send`
illia-v 7fc9b50
Merge branch 'main' into SSL_sendfile
illia-v 1ba04ae
Update `versionchanged`
illia-v 365e0c0
Update a test to get successful HTTP responses
illia-v 8fbc955
Add setting errors
illia-v 21ea0ca
Fix conditions
illia-v 17d9685
Add handling of `SSL_R_UNINITIALIZED`
illia-v a92ae7e
Merge branch 'main' into SSL_sendfile
illia-v 4e8b6d8
Modify `test_sendfile` to avoid the internet
illia-v 379d242
Refactor `test_sendfile` a bit
illia-v 7de3dcb
Merge branch 'main' into SSL_sendfile
illia-v bbe21c0
Merge branch 'main' into SSL_sendfile
illia-v 7323ec0
Try to fix new warnings
illia-v 2dc6947
Merge branch 'main' into SSL_sendfile
illia-v 6e902ad
Merge branch 'main' into SSL_sendfile
illia-v e435b9a
Apply a change from ea9a296fce2f786b4cf43c7924e5de01061f27ca
illia-v ac1b2b2
Merge branch 'main' into SSL_sendfile
illia-v 7d11a59
Merge branch 'main' into SSL_sendfile
illia-v 99e89d3
Merge branch 'main' into SSL_sendfile
illia-v dc626c8
Merge branch 'main' into SSL_sendfile
illia-v 291a5b7
Set `versionchanged` to next in docs
illia-v 3193ba4
Merge branch 'main' into SSL_sendfile
illia-v d870f92
Merge branch 'main' into SSL_sendfile
illia-v 94e522e
Apply some suggestions from code review
illia-v 25bde6f
Apply suggestions to Python code
illia-v 9a6a120
Improve style of `_ssl__SSLSocket_sendfile_impl`
illia-v eaa0b2c
Merge branch 'main' into SSL_sendfile
illia-v 05a0c6c
Drop `_sendfile_use_ssl_sendfile`
illia-v 6b4eed6
Merge remote-tracking branch 'python/main' into SSL_sendfile
illia-v 31ed52d
Apply suggestions from code review
illia-v 5a22e6b
Merge branch 'main' into SSL_sendfile
illia-v ada3f30
Improve kTLS checks for older OpenSSL
illia-v 3350854
Merge branch 'main' into SSL_sendfile
illia-v 3339673
Rename `uses_ktls_for_read` to `uses_ktls_for_recv`
illia-v ee573ad
Apply PEP 7
illia-v 6795f62
Use an alternative method of returning booleans
illia-v 6a35ac6
Mark new functions with `critical_section`
illia-v 9dffdbd
Merge two if blocks
illia-v 19d5746
Reword docs
illia-v ef3744e
Update the news entry
illia-v e64f329
Use `Py_RETURN_FALSE` again
illia-v 028067a
Merge remote-tracking branch 'python/main' into SSL_sendfile
illia-v 6e099fa
Merge branch 'main' into SSL_sendfile
illia-v f363ec3
Merge branch 'main' into SSL_sendfile
illia-v 7c071fd
Merge branch 'main' into SSL_sendfile
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Apply some suggestions from code review
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
Misc/NEWS.d/next/Library/2023-03-13-22-51-40.gh-issue-99813.40TV02.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Python now uses ``SSL_sendifle`` internally when it is possible (see | ||
Python now uses ``SSL_sendfile`` internally when it is possible (see | ||
:data:`~ssl.OP_ENABLE_KTLS`.) The function sends a file more efficiently | ||
because it performs TLS encryption in the kernel to avoid additional context | ||
switches. Patch by Illia Volochii. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,6 @@ | |
#endif | ||
|
||
|
||
|
||
#ifdef BIO_get_ktls_send | ||
#ifdef MS_WINDOWS | ||
typedef long long Py_off_t; | ||
|
@@ -90,9 +89,7 @@ Py_off_t_converter(PyObject *arg, void *addr) | |
#else | ||
*((Py_off_t *)addr) = PyLong_AsLong(arg); | ||
#endif | ||
if (PyErr_Occurred()) | ||
return 0; | ||
return 1; | ||
return PyErr_Occurred() ? 0 : 1; | ||
} | ||
|
||
/*[python input] | ||
|
@@ -2482,9 +2479,9 @@ _ssl__SSLSocket_uses_ktls_for_send_impl(PySSLSocket *self) | |
{ | ||
#ifdef BIO_get_ktls_send | ||
int uses = BIO_get_ktls_send(SSL_get_wbio(self->ssl)); | ||
return PyBool_FromLong((long)uses); | ||
return PyBool_FromLong(uses); | ||
#else | ||
return Py_False; | ||
Py_RETURN_FALSE; | ||
#endif | ||
} | ||
|
||
|
@@ -2500,9 +2497,9 @@ _ssl__SSLSocket_uses_ktls_for_read_impl(PySSLSocket *self) | |
{ | ||
#ifdef BIO_get_ktls_recv | ||
int uses = BIO_get_ktls_recv(SSL_get_rbio(self->ssl)); | ||
return PyBool_FromLong((long)uses); | ||
return PyBool_FromLong(uses); | ||
#else | ||
return Py_False; | ||
Py_RETURN_FALSE; | ||
#endif | ||
} | ||
|
||
|
@@ -2539,7 +2536,7 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |
int has_timeout; | ||
|
||
if (sock != NULL) { | ||
if (((PyObject*)sock) == Py_None) { | ||
if ((PyObject *)sock == Py_None) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a real issue, but thinking out loud for me and Bénédikt: does |
||
_setSSLError(get_state_sock(self), | ||
"Underlying socket connection gone", | ||
PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); | ||
|
@@ -2583,8 +2580,9 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |
PySSL_END_ALLOW_THREADS | ||
self->err = err; | ||
|
||
if (PyErr_CheckSignals()) | ||
if (PyErr_CheckSignals()) { | ||
goto error; | ||
} | ||
|
||
if (has_timeout) { | ||
timeout = _PyDeadline_Get(deadline); | ||
illia-v marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -2613,7 +2611,8 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |
err.ssl == SSL_ERROR_WANT_WRITE); | ||
|
||
if (err.ssl == SSL_ERROR_SSL | ||
&& ERR_GET_REASON(ERR_peek_error()) == SSL_R_UNINITIALIZED) { | ||
&& ERR_GET_REASON(ERR_peek_error()) == SSL_R_UNINITIALIZED) | ||
{ | ||
/* OpenSSL fails to return SSL_ERROR_SYSCALL if an error | ||
* happens in sendfile(), and returns SSL_ERROR_SSL with | ||
* SSL_R_UNINITIALIZED reason instead. */ | ||
|
@@ -2623,14 +2622,16 @@ _ssl__SSLSocket_sendfile_impl(PySSLSocket *self, int fd, Py_off_t offset, | |
goto error; | ||
} | ||
Py_XDECREF(sock); | ||
if (retval < 0) | ||
if (retval < 0) { | ||
return PySSL_SetError(self, __FILE__, __LINE__); | ||
if (PySSL_ChainExceptions(self) < 0) | ||
} | ||
if (PySSL_ChainExceptions(self) < 0) { | ||
return NULL; | ||
} | ||
return PyLong_FromSize_t(retval); | ||
error: | ||
Py_XDECREF(sock); | ||
PySSL_ChainExceptions(self); | ||
(void)PySSL_ChainExceptions(self); | ||
return NULL; | ||
} | ||
#endif /* BIO_get_ktls_send */ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.