Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a30a9f8

Browse files
committed
Add methods for checking whether kTLS is used
1 parent a36235d commit a30a9f8

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

Modules/_ssl.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,42 @@ PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout)
22882288
return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK;
22892289
}
22902290

2291+
/*[clinic input]
2292+
_ssl._SSLSocket.uses_ktls_for_write
2293+
2294+
Check if the Kernel TLS data-path is used for sending.
2295+
[clinic start generated code]*/
2296+
2297+
static PyObject *
2298+
_ssl__SSLSocket_uses_ktls_for_write_impl(PySSLSocket *self)
2299+
/*[clinic end generated code: output=a6c2a790ffd0587e input=156f67420e69b2f9]*/
2300+
{
2301+
#ifdef BIO_get_ktls_send
2302+
int uses = BIO_get_ktls_send(SSL_get_wbio(self->ssl));
2303+
return PyBool_FromLong((long)uses);
2304+
#else
2305+
return Py_False;
2306+
#endif
2307+
}
2308+
2309+
/*[clinic input]
2310+
_ssl._SSLSocket.uses_ktls_for_read
2311+
2312+
Check if the Kernel TLS data-path is used for receiving.
2313+
[clinic start generated code]*/
2314+
2315+
static PyObject *
2316+
_ssl__SSLSocket_uses_ktls_for_read_impl(PySSLSocket *self)
2317+
/*[clinic end generated code: output=140a75033c8316a6 input=0296846b94a57932]*/
2318+
{
2319+
#ifdef BIO_get_ktls_recv
2320+
int uses = BIO_get_ktls_recv(SSL_get_rbio(self->ssl));
2321+
return PyBool_FromLong((long)uses);
2322+
#else
2323+
return Py_False;
2324+
#endif
2325+
}
2326+
22912327
/*[clinic input]
22922328
_ssl._SSLSocket.write
22932329
b: Py_buffer
@@ -2904,6 +2940,8 @@ static PyGetSetDef ssl_getsetlist[] = {
29042940

29052941
static PyMethodDef PySSLMethods[] = {
29062942
_SSL__SSLSOCKET_DO_HANDSHAKE_METHODDEF
2943+
_SSL__SSLSOCKET_USES_KTLS_FOR_WRITE_METHODDEF
2944+
_SSL__SSLSOCKET_USES_KTLS_FOR_READ_METHODDEF
29072945
_SSL__SSLSOCKET_WRITE_METHODDEF
29082946
_SSL__SSLSOCKET_READ_METHODDEF
29092947
_SSL__SSLSOCKET_PENDING_METHODDEF

Modules/clinic/_ssl.c.h

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)