struct cpool_reaper_ctx {
size_t checked;
size_t reaped;
+ struct curltime now;
};
static int cpool_reap_dead_cb(struct Curl_easy *data,
if(!terminate) {
reaper->checked++;
- terminate = Curl_conn_seems_dead(conn, data);
+ terminate = Curl_conn_seems_dead(conn, data, &reaper->now);
}
if(terminate) {
/* stop the iteration here, pass back the connection that was pruned */
void Curl_cpool_prune_dead(struct Curl_easy *data)
{
struct cpool *cpool = cpool_get_instance(data);
- struct cpool_reaper_ctx reaper;
timediff_t elapsed;
if(!cpool)
return;
- memset(&reaper, 0, sizeof(reaper));
CPOOL_LOCK(cpool, data);
elapsed = curlx_ptimediff_ms(Curl_pgrs_now(data), &cpool->last_cleanup);
if(elapsed >= 1000L) {
+ struct cpool_reaper_ctx reaper;
+
+ memset(&reaper, 0, sizeof(reaper));
+ reaper.now = *Curl_pgrs_now(data);
while(cpool_foreach(data, cpool, &reaper, cpool_reap_dead_cb))
;
cpool->last_cleanup = *Curl_pgrs_now(data);
* Return TRUE iff the given connection is considered dead.
*/
bool Curl_conn_seems_dead(struct connectdata *conn,
- struct Curl_easy *data)
+ struct Curl_easy *data,
+ const struct curltime *pnow)
{
DEBUGASSERT(!data->conn);
if(!CONN_INUSE(conn)) {
use */
bool dead;
- if(conn_maxage(data, conn, *Curl_pgrs_now(data))) {
+ if(conn_maxage(data, conn, *pnow)) {
/* avoid check if already too old */
dead = TRUE;
}
+ else if(curlx_ptimediff_ms(pnow, &conn->lastchecked) < 1000)
+ dead = FALSE;
else if(conn->scheme->run->connection_is_dead) {
/* The protocol has a special method for checking the state of the
connection. Use it to check if the connection is dead. */
Curl_attach_connection(data, conn);
dead = conn->scheme->run->connection_is_dead(data, conn);
Curl_detach_connection(data);
+ conn->lastchecked = *pnow;
}
else {
bool input_pending = FALSE;
dead = TRUE;
}
Curl_detach_connection(data);
+ conn->lastchecked = *pnow;
}
if(dead) {
struct connectdata *found;
struct Curl_easy *data;
struct connectdata *needle;
+ struct curltime now;
BIT(may_multiplex);
BIT(want_ntlm_http);
BIT(want_proxy_ntlm_http);
if(!url_match_multiplex_limits(conn, m))
return FALSE;
- if(!CONN_INUSE(conn) && Curl_conn_seems_dead(conn, m->data)) {
+ if(!CONN_INUSE(conn) && Curl_conn_seems_dead(conn, m->data, &m->now)) {
/* remove and disconnect. */
Curl_conn_terminate(m->data, conn, FALSE);
return FALSE;
memset(&match, 0, sizeof(match));
match.data = data;
match.needle = needle;
+ match.now = *Curl_pgrs_now(data);
match.may_multiplex = xfer_may_multiplex(data, needle);
#ifdef USE_NTLM
* Return TRUE iff the given connection is considered dead.
*/
bool Curl_conn_seems_dead(struct connectdata *conn,
- struct Curl_easy *data);
+ struct Curl_easy *data,
+ const struct curltime *pnow);
/**
* Perform upkeep operations on the connection.
char *options; /* options string, allocated */
struct curltime created; /* creation time */
struct curltime lastused; /* when returned to the connection pool as idle */
+ struct curltime lastchecked; /* when last checked alive status */
/* A connection can have one or two sockets and connection filters.
* The protocol using the 2nd one is FTP for CONTROL+DATA sockets */