Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-99813: Start usingSSL_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
a018beb
72e7f5e
cf24d78
e9ef747
646d328
76353c7
14832de
6b41d31
8ac6ff9
5cf9483
fc8e82f
7fc9b50
1ba04ae
365e0c0
8fbc955
21ea0ca
17d9685
a92ae7e
4e8b6d8
379d242
7de3dcb
bbe21c0
7323ec0
2dc6947
6e902ad
e435b9a
ac1b2b2
7d11a59
99e89d3
dc626c8
291a5b7
3193ba4
d870f92
94e522e
25bde6f
9a6a120
eaa0b2c
05a0c6c
6b4eed6
31ed52d
5a22e6b
ada3f30
3350854
3339673
ee573ad
6795f62
6a35ac6
9dffdbd
19d5746
ef3744e
e64f329
028067a
6e099fa
f363ec3
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Python now uses ``SSL_sendfile`` internally when it is possible (see | ||
:data:`~ssl.OP_ENABLE_KTLS`.) The function sends a file more efficiently | ||
illia-v marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
because it performs TLS encryption in the kernel to avoid additional context | ||
switches. Patch by Illia Volochii. |
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 | ||
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(uses); | ||
#else | ||
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(uses); | ||
#else | ||
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) { | ||
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()) { | ||
goto error; | ||
} | ||
if (has_timeout) { | ||
timeout = _PyDeadline_Get(deadline); | ||
illia-v marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
@@ -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) | ||
{ | ||
/* 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) { | ||
return PySSL_SetError(self, __FILE__, __LINE__); | ||
} | ||
if (PySSL_ChainExceptions(self) < 0) { | ||
return NULL; | ||
} | ||
return PyLong_FromSize_t(retval); | ||
error: | ||
Py_XDECREF(sock); | ||
(void)PySSL_ChainExceptions(self); | ||
return NULL; | ||
} | ||
#endif /* BIO_get_ktls_send */ | ||
Uh oh!
There was an error while loading.Please reload this page.