/* 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);
}
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);
}
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 */
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
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);
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);
}
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);
}
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);
}