mirror of
https://github.com/moparisthebest/curl
synced 2024-12-23 16:48:49 -05:00
timeouts: change millisecond timeouts to timediff_t from time_t
For millisecond timers we like timediff_t better. Also, time_t can be unsigned so returning a negative value doesn't work then. Closes #5479
This commit is contained in:
parent
fc55c723c4
commit
842f73de58
@ -179,7 +179,7 @@ struct thread_sync_data {
|
||||
struct thread_data {
|
||||
curl_thread_t thread_hnd;
|
||||
unsigned int poll_interval;
|
||||
time_t interval_end;
|
||||
timediff_t interval_end;
|
||||
struct thread_sync_data tsd;
|
||||
};
|
||||
|
||||
@ -622,7 +622,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
|
||||
else {
|
||||
/* poll for name lookup done with exponential backoff up to 250ms */
|
||||
/* should be fine even if this converts to 32 bit */
|
||||
time_t elapsed = (time_t)Curl_timediff(Curl_now(),
|
||||
timediff_t elapsed = Curl_timediff(Curl_now(),
|
||||
data->progress.t_startsingle);
|
||||
if(elapsed < 0)
|
||||
elapsed = 0;
|
||||
@ -648,7 +648,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
|
||||
curl_socket_t *socks)
|
||||
{
|
||||
int ret_val = 0;
|
||||
time_t milli;
|
||||
timediff_t milli;
|
||||
timediff_t ms;
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct resdata *reslv = (struct resdata *)data->state.resolver;
|
||||
@ -672,7 +672,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
|
||||
if(ms < 3)
|
||||
milli = 0;
|
||||
else if(ms <= 50)
|
||||
milli = (time_t)ms/3;
|
||||
milli = ms/3;
|
||||
else if(ms <= 250)
|
||||
milli = 50;
|
||||
else
|
||||
|
@ -633,8 +633,8 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
|
||||
|
||||
while(!*ftpcode && !result) {
|
||||
/* check and reset timeout value every lap */
|
||||
time_t timeout = Curl_pp_state_timeout(pp, FALSE);
|
||||
time_t interval_ms;
|
||||
timediff_t timeout = Curl_pp_state_timeout(pp, FALSE);
|
||||
timediff_t interval_ms;
|
||||
|
||||
if(timeout <= 0) {
|
||||
failf(data, "FTP response timeout");
|
||||
@ -3252,7 +3252,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
|
||||
* data has been transferred. This happens when doing through NATs etc that
|
||||
* abandon old silent connections.
|
||||
*/
|
||||
long old_time = pp->response_time;
|
||||
timediff_t old_time = pp->response_time;
|
||||
|
||||
pp->response_time = 60*1000; /* give it only a minute for now */
|
||||
pp->response = Curl_now(); /* timeout relative now */
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -44,12 +44,12 @@
|
||||
|
||||
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
||||
triggered */
|
||||
time_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
|
||||
timediff_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
|
||||
{
|
||||
struct connectdata *conn = pp->conn;
|
||||
struct Curl_easy *data = conn->data;
|
||||
time_t timeout_ms; /* in milliseconds */
|
||||
long response_time = (data->set.server_response_timeout)?
|
||||
timediff_t timeout_ms; /* in milliseconds */
|
||||
timediff_t response_time = (data->set.server_response_timeout)?
|
||||
data->set.server_response_timeout: pp->response_time;
|
||||
|
||||
/* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine
|
||||
@ -60,12 +60,12 @@ time_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
|
||||
/* Without a requested timeout, we only wait 'response_time' seconds for the
|
||||
full response to arrive before we bail out */
|
||||
timeout_ms = response_time -
|
||||
(time_t)Curl_timediff(Curl_now(), pp->response); /* spent time */
|
||||
Curl_timediff(Curl_now(), pp->response); /* spent time */
|
||||
|
||||
if(data->set.timeout && !disconnecting) {
|
||||
/* if timeout is requested, find out how much remaining time we have */
|
||||
time_t timeout2_ms = data->set.timeout - /* timeout time */
|
||||
(time_t)Curl_timediff(Curl_now(), conn->now); /* spent time */
|
||||
timediff_t timeout2_ms = data->set.timeout - /* timeout time */
|
||||
Curl_timediff(Curl_now(), conn->now); /* spent time */
|
||||
|
||||
/* pick the lowest number */
|
||||
timeout_ms = CURLMIN(timeout_ms, timeout2_ms);
|
||||
@ -83,8 +83,8 @@ CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
|
||||
struct connectdata *conn = pp->conn;
|
||||
curl_socket_t sock = conn->sock[FIRSTSOCKET];
|
||||
int rc;
|
||||
time_t interval_ms;
|
||||
time_t timeout_ms = Curl_pp_state_timeout(pp, disconnecting);
|
||||
timediff_t interval_ms;
|
||||
timediff_t timeout_ms = Curl_pp_state_timeout(pp, disconnecting);
|
||||
struct Curl_easy *data = conn->data;
|
||||
CURLcode result = CURLE_OK;
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -60,9 +60,8 @@ struct pingpong {
|
||||
size_t sendsize; /* total size of the sendthis buffer */
|
||||
struct curltime response; /* set to Curl_now() when a command has been sent
|
||||
off, used to time-out response reading */
|
||||
long response_time; /* When no timeout is given, this is the amount of
|
||||
timediff_t response_time; /* When no timeout is given, this is the amount of
|
||||
milliseconds we await for a server response. */
|
||||
|
||||
struct connectdata *conn; /* points to the connectdata struct that this
|
||||
belongs to */
|
||||
|
||||
@ -89,7 +88,7 @@ void Curl_pp_init(struct pingpong *pp);
|
||||
|
||||
/* Returns timeout in ms. 0 or negative number means the timeout has already
|
||||
triggered */
|
||||
time_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting);
|
||||
timediff_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting);
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -282,9 +282,9 @@ timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
|
||||
* stay below 'limit'.
|
||||
*/
|
||||
if(size < CURL_OFF_T_MAX/1000)
|
||||
minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
|
||||
minimum = (timediff_t) (CURL_OFF_T_C(1000) * size / limit);
|
||||
else {
|
||||
minimum = (time_t) (size / limit);
|
||||
minimum = (timediff_t) (size / limit);
|
||||
if(minimum < TIMEDIFF_T_MAX/1000)
|
||||
minimum *= 1000;
|
||||
else
|
||||
|
@ -2969,7 +2969,7 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
|
||||
fd_write = sock;
|
||||
/* wait for the socket to become ready */
|
||||
(void)Curl_socket_check(fd_read, CURL_SOCKET_BAD, fd_write,
|
||||
left>1000?1000:(time_t)left);
|
||||
left>1000?1000:left);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -642,7 +642,7 @@ static CURLcode bearssl_connect_common(struct connectdata *conn,
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
time_t timeout_ms;
|
||||
timediff_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
|
@ -819,7 +819,7 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
|
||||
if(!result) {
|
||||
/* Compute the handshake timeout. Since GSKit granularity is 1 second,
|
||||
we round up the required value. */
|
||||
long timeout = Curl_timeleft(data, NULL, TRUE);
|
||||
timediff_t timeout = Curl_timeleft(data, NULL, TRUE);
|
||||
if(timeout < 0)
|
||||
result = CURLE_OPERATION_TIMEDOUT;
|
||||
else
|
||||
@ -932,7 +932,7 @@ static CURLcode gskit_connect_step2(struct connectdata *conn, int sockindex,
|
||||
/* Poll or wait for end of SSL asynchronous handshake. */
|
||||
|
||||
for(;;) {
|
||||
long timeout_ms = nonblocking? 0: Curl_timeleft(data, NULL, TRUE);
|
||||
timediff_t timeout_ms = nonblocking? 0: Curl_timeleft(data, NULL, TRUE);
|
||||
if(timeout_ms < 0)
|
||||
timeout_ms = 0;
|
||||
stmv.tv_sec = timeout_ms / 1000;
|
||||
|
@ -235,7 +235,7 @@ static CURLcode handshake(struct connectdata *conn,
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking?0:
|
||||
timeout_ms?(time_t)timeout_ms:1000);
|
||||
timeout_ms?timeout_ms:1000);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
|
@ -938,7 +938,7 @@ mbed_connect_common(struct connectdata *conn,
|
||||
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking ? 0 : (time_t)timeout_ms);
|
||||
nonblocking ? 0 : timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 2017 - 2018, Yiming Jing, <jingyiming@baidu.com>
|
||||
* Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -542,9 +542,8 @@ mesalink_connect_common(struct connectdata *conn, int sockindex,
|
||||
? sockfd
|
||||
: CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(
|
||||
readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking ? 0 : (time_t)timeout_ms);
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking ? 0 : timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
|
@ -3929,7 +3929,6 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
timediff_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
@ -3940,7 +3939,7 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
|
||||
|
||||
if(ssl_connect_1 == connssl->connecting_state) {
|
||||
/* Find out how much more time we're allowed */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
@ -3958,7 +3957,7 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
|
||||
/* check allowed time left */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
@ -3976,7 +3975,7 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
|
||||
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking?0:(time_t)timeout_ms);
|
||||
nonblocking?0:timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
|
@ -1514,7 +1514,7 @@ schannel_connect_common(struct connectdata *conn, int sockindex,
|
||||
connssl->connecting_state ? sockfd : CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking ? 0 : (time_t)timeout_ms);
|
||||
nonblocking ? 0 : timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL/TLS socket, errno: %d", SOCKERRNO);
|
||||
@ -1663,13 +1663,9 @@ schannel_send(struct connectdata *conn, int sockindex,
|
||||
|
||||
/* send entire message or fail */
|
||||
while(len > (size_t)written) {
|
||||
ssize_t this_write;
|
||||
timediff_t timeout_ms;
|
||||
ssize_t this_write = 0;
|
||||
int what;
|
||||
|
||||
this_write = 0;
|
||||
|
||||
timeout_ms = Curl_timeleft(conn->data, NULL, FALSE);
|
||||
timediff_t timeout_ms = Curl_timeleft(conn->data, NULL, FALSE);
|
||||
if(timeout_ms < 0) {
|
||||
/* we already got the timeout */
|
||||
failf(conn->data, "schannel: timed out sending data "
|
||||
@ -1678,7 +1674,7 @@ schannel_send(struct connectdata *conn, int sockindex,
|
||||
written = -1;
|
||||
break;
|
||||
}
|
||||
if(!timeout_ms)
|
||||
else if(!timeout_ms)
|
||||
timeout_ms = TIMEDIFF_T_MAX;
|
||||
what = SOCKET_WRITABLE(conn->sock[sockindex], timeout_ms);
|
||||
if(what < 0) {
|
||||
|
@ -2836,7 +2836,6 @@ sectransp_connect_common(struct connectdata *conn,
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
timediff_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
@ -2847,7 +2846,7 @@ sectransp_connect_common(struct connectdata *conn,
|
||||
|
||||
if(ssl_connect_1 == connssl->connecting_state) {
|
||||
/* Find out how much more time we're allowed */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
@ -2865,7 +2864,7 @@ sectransp_connect_common(struct connectdata *conn,
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
|
||||
/* check allowed time left */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
@ -2883,7 +2882,7 @@ sectransp_connect_common(struct connectdata *conn,
|
||||
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
|
||||
|
||||
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
|
||||
nonblocking?0:(time_t)timeout_ms);
|
||||
nonblocking ? 0 : timeout_ms);
|
||||
if(what < 0) {
|
||||
/* fatal error */
|
||||
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
|
||||
|
@ -944,7 +944,6 @@ wolfssl_connect_common(struct connectdata *conn,
|
||||
struct Curl_easy *data = conn->data;
|
||||
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
|
||||
curl_socket_t sockfd = conn->sock[sockindex];
|
||||
time_t timeout_ms;
|
||||
int what;
|
||||
|
||||
/* check if the connection has already been established */
|
||||
@ -955,7 +954,7 @@ wolfssl_connect_common(struct connectdata *conn,
|
||||
|
||||
if(ssl_connect_1 == connssl->connecting_state) {
|
||||
/* Find out how much more time we're allowed */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
@ -973,7 +972,7 @@ wolfssl_connect_common(struct connectdata *conn,
|
||||
ssl_connect_2_writing == connssl->connecting_state) {
|
||||
|
||||
/* check allowed time left */
|
||||
timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
const timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
|
||||
|
||||
if(timeout_ms < 0) {
|
||||
/* no need to continue if time already is up */
|
||||
|
Loading…
Reference in New Issue
Block a user