mirror of https://github.com/python/cpython
Issue #22117: Fix ssl to use _PyTime_t API on sock_timeout
I didn't notice that the ssl module uses private attributes of socket objects.
This commit is contained in:
parent
b28e91633a
commit
e245231fab
|
@ -534,7 +534,7 @@ newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock,
|
|||
/* If the socket is in non-blocking mode or timeout mode, set the BIO
|
||||
* to non-blocking mode (blocking is the default)
|
||||
*/
|
||||
if (sock && sock->sock_timeout >= 0.0) {
|
||||
if (sock && sock->sock_timeout >= 0) {
|
||||
BIO_set_nbio(SSL_get_rbio(self->ssl), 1);
|
||||
BIO_set_nbio(SSL_get_wbio(self->ssl), 1);
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ static PyObject *PySSL_SSLdo_handshake(PySSLSocket *self)
|
|||
Py_INCREF(sock);
|
||||
|
||||
/* just in case the blocking state of the socket has been changed */
|
||||
nonblocking = (sock->sock_timeout >= 0.0);
|
||||
nonblocking = (sock->sock_timeout >= 0);
|
||||
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
|
||||
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
|
||||
}
|
||||
|
@ -1616,9 +1616,9 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
|
|||
int rc;
|
||||
|
||||
/* Nothing to do unless we're in timeout mode (not non-blocking) */
|
||||
if ((s == NULL) || (s->sock_timeout == 0.0))
|
||||
if ((s == NULL) || (s->sock_timeout == 0))
|
||||
return SOCKET_IS_NONBLOCKING;
|
||||
else if (s->sock_timeout < 0.0)
|
||||
else if (s->sock_timeout < 0)
|
||||
return SOCKET_IS_BLOCKING;
|
||||
|
||||
/* Guard against closed socket */
|
||||
|
@ -1636,7 +1636,9 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
|
|||
pollfd.events = writing ? POLLOUT : POLLIN;
|
||||
|
||||
/* s->sock_timeout is in seconds, timeout in ms */
|
||||
timeout = (int)(s->sock_timeout * 1000 + 0.5);
|
||||
timeout = (int)_PyTime_AsMilliseconds(s->sock_timeout,
|
||||
_PyTime_ROUND_UP);
|
||||
|
||||
PySSL_BEGIN_ALLOW_THREADS
|
||||
rc = poll(&pollfd, 1, timeout);
|
||||
PySSL_END_ALLOW_THREADS
|
||||
|
@ -1649,9 +1651,10 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
|
|||
if (!_PyIsSelectable_fd(s->sock_fd))
|
||||
return SOCKET_TOO_LARGE_FOR_SELECT;
|
||||
|
||||
/* Construct the arguments to select */
|
||||
tv.tv_sec = (int)s->sock_timeout;
|
||||
tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
|
||||
/* conversion was already checked for overflow when
|
||||
the timeout was set */
|
||||
(void)_PyTime_AsTimeval(s->sock_timeout, &tv, _PyTime_ROUND_UP);
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(s->sock_fd, &fds);
|
||||
|
||||
|
@ -1704,7 +1707,7 @@ static PyObject *PySSL_SSLwrite(PySSLSocket *self, PyObject *args)
|
|||
|
||||
if (sock != NULL) {
|
||||
/* just in case the blocking state of the socket has been changed */
|
||||
nonblocking = (sock->sock_timeout >= 0.0);
|
||||
nonblocking = (sock->sock_timeout >= 0);
|
||||
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
|
||||
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
|
||||
}
|
||||
|
@ -1836,7 +1839,7 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
|
|||
|
||||
if (sock != NULL) {
|
||||
/* just in case the blocking state of the socket has been changed */
|
||||
nonblocking = (sock->sock_timeout >= 0.0);
|
||||
nonblocking = (sock->sock_timeout >= 0);
|
||||
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
|
||||
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
|
||||
}
|
||||
|
@ -1915,7 +1918,7 @@ static PyObject *PySSL_SSLshutdown(PySSLSocket *self)
|
|||
Py_INCREF(sock);
|
||||
|
||||
/* Just in case the blocking state of the socket has been changed */
|
||||
nonblocking = (sock->sock_timeout >= 0.0);
|
||||
nonblocking = (sock->sock_timeout >= 0);
|
||||
BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking);
|
||||
BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue