time-keeping: keep timestamp in multi, always update

Always use curlx_now() when calling Curl_pgrs_now(data). Tests with the
"manual" updates to now proved differ more then 100ms in parallel testing.

Add `curlx_nowp()` to set current time into a struct curltime.
Add `curlx_ptimediff_ms() and friends, passing pointers.

Update documentation.

Closes #19998
This commit is contained in:
Stefan Eissing 2025-12-18 13:55:07 +01:00 committed by Daniel Stenberg
parent 308c347c8b
commit b4be1f271e
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
61 changed files with 471 additions and 502 deletions

View file

@ -514,7 +514,6 @@ CURLcode Curl_open(struct Curl_easy **curl)
#endif
Curl_netrc_init(&data->state.netrc);
Curl_init_userdefined(data);
Curl_pgrs_now_set(data); /* on easy handle create */
*curl = data;
return CURLE_OK;
@ -638,7 +637,7 @@ static bool conn_maxage(struct Curl_easy *data,
timediff_t age_ms;
if(data->set.conn_max_idle_ms) {
age_ms = curlx_timediff_ms(now, conn->lastused);
age_ms = curlx_ptimediff_ms(&now, &conn->lastused);
if(age_ms > data->set.conn_max_idle_ms) {
infof(data, "Too old connection (%" FMT_TIMEDIFF_T
" ms idle, max idle is %" FMT_TIMEDIFF_T " ms), disconnect it",
@ -648,7 +647,7 @@ static bool conn_maxage(struct Curl_easy *data,
}
if(data->set.conn_max_age_ms) {
age_ms = curlx_timediff_ms(now, conn->created);
age_ms = curlx_ptimediff_ms(&now, &conn->created);
if(age_ms > data->set.conn_max_age_ms) {
infof(data,
"Too old connection (created %" FMT_TIMEDIFF_T
@ -673,7 +672,7 @@ bool Curl_conn_seems_dead(struct connectdata *conn,
use */
bool dead;
if(conn_maxage(data, conn, data->progress.now)) {
if(conn_maxage(data, conn, *Curl_pgrs_now(data))) {
/* avoid check if already too old */
dead = TRUE;
}
@ -722,11 +721,11 @@ bool Curl_conn_seems_dead(struct connectdata *conn,
}
CURLcode Curl_conn_upkeep(struct Curl_easy *data,
struct connectdata *conn,
struct curltime *now)
struct connectdata *conn)
{
CURLcode result = CURLE_OK;
if(curlx_timediff_ms(*now, conn->keepalive) <= data->set.upkeep_interval_ms)
if(curlx_ptimediff_ms(Curl_pgrs_now(data), &conn->keepalive) <=
data->set.upkeep_interval_ms)
return result;
/* briefly attach for action */
@ -744,7 +743,7 @@ CURLcode Curl_conn_upkeep(struct Curl_easy *data,
}
Curl_detach_connection(data);
conn->keepalive = *now;
conn->keepalive = *Curl_pgrs_now(data);
return result;
}
@ -1341,7 +1340,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
conn->remote_port = -1; /* unknown at this point */
/* Store creation time to help future close decision making */
conn->created = data->progress.now;
conn->created = *Curl_pgrs_now(data);
/* Store current time to give a baseline to keepalive connection times. */
conn->keepalive = conn->created;
@ -3261,7 +3260,8 @@ static CURLcode resolve_server(struct Curl_easy *data,
else if(result == CURLE_OPERATION_TIMEDOUT) {
failf(data, "Failed to resolve %s '%s' with timeout after %"
FMT_TIMEDIFF_T " ms", peertype, ehost->dispname,
curlx_timediff_ms(data->progress.now, data->progress.t_startsingle));
curlx_ptimediff_ms(Curl_pgrs_now(data),
&data->progress.t_startsingle));
return CURLE_OPERATION_TIMEDOUT;
}
else if(result) {