url: remove duplicate call to Curl_conncache_remove_conn when pruning

- remove unnecessary prunedead struct from prune_dead_connections
- rename extract_if_dead to prune_if_dead for clarity

Closes #13710
This commit is contained in:
Nathan Moinvaziri 2024-05-19 12:33:21 -07:00 committed by Daniel Stenberg
parent c56071f41f
commit 6ea9388157
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -774,15 +774,15 @@ static bool conn_maxage(struct Curl_easy *data,
} }
/* /*
* This function checks if the given connection is dead and extracts it from * This function checks if the given connection is dead and prunes it from
* the connection cache if so. * the connection cache if so.
* *
* When this is called as a Curl_conncache_foreach() callback, the connection * When this is called as a Curl_conncache_foreach() callback, the connection
* cache lock is held! * cache lock is held!
* *
* Returns TRUE if the connection was dead and extracted. * Returns TRUE if the connection was dead and pruned.
*/ */
static bool extract_if_dead(struct connectdata *conn, static bool prune_if_dead(struct connectdata *conn,
struct Curl_easy *data) struct Curl_easy *data)
{ {
if(!CONN_INUSE(conn)) { if(!CONN_INUSE(conn)) {
@ -829,6 +829,7 @@ static bool extract_if_dead(struct connectdata *conn,
} }
if(dead) { if(dead) {
/* remove connection from cache */
infof(data, "Connection %" CURL_FORMAT_CURL_OFF_T " seems to be dead", infof(data, "Connection %" CURL_FORMAT_CURL_OFF_T " seems to be dead",
conn->connection_id); conn->connection_id);
Curl_conncache_remove_conn(data, conn, FALSE); Curl_conncache_remove_conn(data, conn, FALSE);
@ -838,22 +839,17 @@ static bool extract_if_dead(struct connectdata *conn,
return FALSE; return FALSE;
} }
struct prunedead {
struct Curl_easy *data;
struct connectdata *extracted;
};
/* /*
* Wrapper to use extract_if_dead() function in Curl_conncache_foreach() * Wrapper to use prune_if_dead() function in Curl_conncache_foreach()
* *
*/ */
static int call_extract_if_dead(struct Curl_easy *data, static int call_prune_if_dead(struct Curl_easy *data,
struct connectdata *conn, void *param) struct connectdata *conn, void *param)
{ {
struct prunedead *p = (struct prunedead *)param; struct connectdata **pruned = (struct connectdata **)param;
if(extract_if_dead(conn, data)) { if(prune_if_dead(conn, data)) {
/* stop the iteration here, pass back the connection that was extracted */ /* stop the iteration here, pass back the connection that was pruned */
p->extracted = conn; *pruned = conn;
return 1; return 1;
} }
return 0; /* continue iteration */ return 0; /* continue iteration */
@ -877,18 +873,15 @@ static void prune_dead_connections(struct Curl_easy *data)
CONNCACHE_UNLOCK(data); CONNCACHE_UNLOCK(data);
if(elapsed >= 1000L) { if(elapsed >= 1000L) {
struct prunedead prune; struct connectdata *pruned = NULL;
prune.data = data; while(Curl_conncache_foreach(data, data->state.conn_cache, &pruned,
prune.extracted = NULL; call_prune_if_dead)) {
while(Curl_conncache_foreach(data, data->state.conn_cache, &prune,
call_extract_if_dead)) {
/* unlocked */ /* unlocked */
/* remove connection from cache */ /* connection previously removed from cache in prune_if_dead() */
Curl_conncache_remove_conn(data, prune.extracted, TRUE);
/* disconnect it */ /* disconnect it */
Curl_disconnect(data, prune.extracted, TRUE); Curl_disconnect(data, pruned, TRUE);
} }
CONNCACHE_LOCK(data); CONNCACHE_LOCK(data);
data->state.conn_cache->last_cleanup = now; data->state.conn_cache->last_cleanup = now;
@ -1299,7 +1292,7 @@ ConnectionExists(struct Curl_easy *data,
/* When not multiplexed, we have a match here! */ /* When not multiplexed, we have a match here! */
infof(data, "Multiplexed connection found"); infof(data, "Multiplexed connection found");
} }
else if(extract_if_dead(check, data)) { else if(prune_if_dead(check, data)) {
/* disconnect it */ /* disconnect it */
Curl_disconnect(data, check, TRUE); Curl_disconnect(data, check, TRUE);
continue; continue;