bpo-41710: Add private _PyDeadline_Get() function by vstinner · Pull Request #28674 · python/cpython
timeout = GET_SOCKET_TIMEOUT(sock); has_timeout = (timeout > 0); if (has_timeout) deadline = _PyTime_GetMonotonicClock() + timeout; if (has_timeout) { deadline = _PyDeadline_Init(timeout); }
/* Actually negotiate SSL connection */ /* XXX If SSL_do_handshake() returns 0, it's also a failure. */
if (has_timeout) timeout = deadline - _PyTime_GetMonotonicClock(); timeout = _PyDeadline_Get(deadline);
if (err.ssl == SSL_ERROR_WANT_READ) { sockstate = PySSL_select(sock, 0, timeout);
timeout = GET_SOCKET_TIMEOUT(sock); has_timeout = (timeout > 0); if (has_timeout) deadline = _PyTime_GetMonotonicClock() + timeout; if (has_timeout) { deadline = _PyDeadline_Init(timeout); }
sockstate = PySSL_select(sock, 1, timeout); if (sockstate == SOCKET_HAS_TIMED_OUT) {
if (has_timeout) timeout = deadline - _PyTime_GetMonotonicClock(); if (has_timeout) { timeout = _PyDeadline_Get(deadline); }
if (err.ssl == SSL_ERROR_WANT_READ) { sockstate = PySSL_select(sock, 0, timeout);
do { PySSL_BEGIN_ALLOW_THREADS
if (has_timeout) timeout = deadline - _PyTime_GetMonotonicClock(); if (has_timeout) { timeout = _PyDeadline_Get(deadline); }
if (err.ssl == SSL_ERROR_WANT_READ) { sockstate = PySSL_select(sock, 0, timeout);
timeout = GET_SOCKET_TIMEOUT(sock); has_timeout = (timeout > 0); if (has_timeout) deadline = _PyTime_GetMonotonicClock() + timeout; if (has_timeout) { deadline = _PyDeadline_Init(timeout); }
while (1) { PySSL_BEGIN_ALLOW_THREADS
if (has_timeout) timeout = deadline - _PyTime_GetMonotonicClock(); if (has_timeout) { timeout = _PyDeadline_Get(deadline); }
/* Possibly retry shutdown until timeout or failure */ if (err.ssl == SSL_ERROR_WANT_READ)