Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeouts: move ms timeouts to timediff_t from int
Now that all functions in select.[ch] take timediff_t instead
of the limited time_t or int, we can remove type conversions
and related preprocessor checks to silence compiler warnings.

Based upon curl#5262
Supersedes curl#5214, curl#5220 and curl#5221
Follow up to curl#5343 and curl#5479
Closes curl#5490
  • Loading branch information
mback2k committed May 31, 2020
1 parent 8346c90 commit c00807c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions lib/asyn-ares.c
Expand Up @@ -286,7 +286,7 @@ int Curl_resolver_getsock(struct connectdata *conn,
* return number of sockets it worked on
*/

static int waitperform(struct connectdata *conn, int timeout_ms)
static int waitperform(struct connectdata *conn, timediff_t timeout_ms)
{
struct Curl_easy *data = conn->data;
int nfds;
Expand Down Expand Up @@ -437,9 +437,13 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
while(!result) {
struct timeval *tvp, tv, store;
int itimeout;
int timeout_ms;
timediff_t timeout_ms;

itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;
#ifdef TIMEDIFF_T_MAX > INT_MAX
itimeout = (timeout > INT_MAX) ? INT_MAX : (int)timeout;
#else
itimeout = (int)timeout;
#endif

store.tv_sec = itimeout/1000;
store.tv_usec = (itimeout%1000)*1000;
Expand All @@ -450,7 +454,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
second is left, otherwise just use 1000ms to make sure the progress
callback gets called frequent enough */
if(!tvp->tv_sec)
timeout_ms = (int)(tvp->tv_usec/1000);
timeout_ms = (timediff_t)(tvp->tv_usec/1000);
else
timeout_ms = 1000;

Expand All @@ -470,7 +474,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
else if(timediff > timeout)
timeout = -1;
else
timeout -= (long)timediff;
timeout -= timediff;
now = now2; /* for next loop */
}
if(timeout < 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/easy.c
Expand Up @@ -510,7 +510,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
before = Curl_now();

/* wait for activity or timeout */
pollrc = Curl_poll(fds, numfds, (int)ev->ms);
pollrc = Curl_poll(fds, numfds, ev->ms);

after = Curl_now();

Expand Down
2 changes: 1 addition & 1 deletion lib/multi.c
Expand Up @@ -1255,7 +1255,7 @@ static CURLMcode Curl_multi_wait(struct Curl_multi *multi,
timeout */
else if((sleep_ms < 0) && extrawait)
sleep_ms = timeout_ms;
Curl_wait_ms((int)sleep_ms);
Curl_wait_ms(sleep_ms);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/socks.c
Expand Up @@ -69,7 +69,7 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
break;
}
if(!timeout_ms)
timeout_ms = TIME_T_MAX;
timeout_ms = TIMEDIFF_T_MAX;
if(SOCKET_READABLE(sockfd, timeout_ms) <= 0) {
result = ~CURLE_OK;
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/telnet.c
Expand Up @@ -1315,7 +1315,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
DWORD readfile_read;
int err;
#else
int interval_ms;
timediff_t interval_ms;
struct pollfd pfd[2];
int poll_cnt;
curl_off_t total_dl = 0;
Expand Down

0 comments on commit c00807c

Please sign in to comment.