mirror of
https://github.com/curl/curl.git
synced 2026-07-27 22:43:12 +03:00
lib: add CURLINFO_CONN_ID and CURLINFO_XFER_ID
- add an `id` long to Curl_easy, -1 on init - once added to a multi (or its own multi), it gets a non-negative number assigned by the connection cache - `id` is unique among all transfers using the same cache until reaching LONG_MAX where it will wrap around. So, not unique eternally. - CURLINFO_CONN_ID returns the connection id attached to data or, if none present, data->state.lastconnect_id - variables and type declared in tool for write out Closes #11185
This commit is contained in:
parent
fdda99c6ee
commit
e024d5665d
31 changed files with 252 additions and 94 deletions
48
lib/multi.c
48
lib/multi.c
|
|
@ -194,15 +194,10 @@ static void mstate(struct Curl_easy *data, CURLMstate state
|
|||
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
|
||||
if(data->mstate >= MSTATE_PENDING &&
|
||||
data->mstate < MSTATE_COMPLETED) {
|
||||
long connection_id = -5000;
|
||||
|
||||
if(data->conn)
|
||||
connection_id = data->conn->connection_id;
|
||||
|
||||
infof(data,
|
||||
"STATE: %s => %s handle %p; line %d (connection #%ld)",
|
||||
"STATE: %s => %s handle %p; line %d",
|
||||
multi_statename[oldstate], multi_statename[data->mstate],
|
||||
(void *)data, lineno, connection_id);
|
||||
(void *)data, lineno);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -464,6 +459,20 @@ struct Curl_multi *curl_multi_init(void)
|
|||
CURL_DNS_HASH_SIZE);
|
||||
}
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
static void multi_warn_debug(struct Curl_multi *multi, struct Curl_easy *data)
|
||||
{
|
||||
if(!multi->warned) {
|
||||
infof(data, "!!! WARNING !!!");
|
||||
infof(data, "This is a debug build of libcurl, "
|
||||
"do not use in production.");
|
||||
multi->warned = true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define multi_warn_debug(x,y) Curl_nop_stmt
|
||||
#endif
|
||||
|
||||
/* returns TRUE if the easy handle is supposed to be present in the main link
|
||||
list */
|
||||
static bool in_main_list(struct Curl_easy *data)
|
||||
|
|
@ -623,8 +632,14 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
|
|||
data->set.server_response_timeout;
|
||||
data->state.conn_cache->closure_handle->set.no_signal =
|
||||
data->set.no_signal;
|
||||
data->id = data->state.conn_cache->next_easy_id++;
|
||||
if(data->state.conn_cache->next_easy_id <= 0)
|
||||
data->state.conn_cache->next_easy_id = 0;
|
||||
CONNCACHE_UNLOCK(data);
|
||||
|
||||
multi_warn_debug(multi, data);
|
||||
infof(data, "processing: %s", data->state.url);
|
||||
|
||||
return CURLM_OK;
|
||||
}
|
||||
|
||||
|
|
@ -742,6 +757,7 @@ static CURLcode multi_done(struct Curl_easy *data,
|
|||
but currently we have no such detail knowledge.
|
||||
*/
|
||||
|
||||
data->state.recent_conn_id = conn->connection_id;
|
||||
if((data->set.reuse_forbid
|
||||
#if defined(USE_NTLM)
|
||||
&& !(conn->http_ntlm_state == NTLMSTATE_TYPE2 ||
|
||||
|
|
@ -753,7 +769,7 @@ static CURLcode multi_done(struct Curl_easy *data,
|
|||
#endif
|
||||
) || conn->bits.close
|
||||
|| (premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET))) {
|
||||
DEBUGF(infof(data, "multi_done, not re-using connection=%ld, forbid=%d"
|
||||
DEBUGF(infof(data, "multi_done, not re-using connection=%zd, forbid=%d"
|
||||
", close=%d, premature=%d, conn_multiplex=%d",
|
||||
conn->connection_id,
|
||||
data->set.reuse_forbid, conn->bits.close, premature,
|
||||
|
|
@ -774,15 +790,16 @@ static CURLcode multi_done(struct Curl_easy *data,
|
|||
conn->bits.conn_to_host ? conn->conn_to_host.dispname :
|
||||
conn->host.dispname;
|
||||
/* create string before returning the connection */
|
||||
long connection_id = conn->connection_id;
|
||||
curl_off_t connection_id = conn->connection_id;
|
||||
msnprintf(buffer, sizeof(buffer),
|
||||
"Connection #%ld to host %s left intact",
|
||||
"Connection #%zd to host %s left intact",
|
||||
connection_id, host);
|
||||
/* the connection is no longer in use by this transfer */
|
||||
CONNCACHE_UNLOCK(data);
|
||||
if(Curl_conncache_return_conn(data, conn)) {
|
||||
/* remember the most recently used connection */
|
||||
data->state.lastconnect_id = connection_id;
|
||||
data->state.recent_conn_id = connection_id;
|
||||
infof(data, "%s", buffer);
|
||||
}
|
||||
else
|
||||
|
|
@ -1895,14 +1912,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
|
|||
multistate(data, MSTATE_COMPLETED);
|
||||
}
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
if(!multi->warned) {
|
||||
infof(data, "!!! WARNING !!!");
|
||||
infof(data, "This is a debug build of libcurl, "
|
||||
"do not use in production.");
|
||||
multi->warned = true;
|
||||
}
|
||||
#endif
|
||||
multi_warn_debug(multi, data);
|
||||
|
||||
do {
|
||||
/* A "stream" here is a logical stream if the protocol can handle that
|
||||
|
|
@ -3690,7 +3700,7 @@ void Curl_expire_clear(struct Curl_easy *data)
|
|||
}
|
||||
|
||||
#ifdef DEBUGBUILD
|
||||
infof(data, "Expire cleared (transfer %p)", data);
|
||||
infof(data, "Expire cleared");
|
||||
#endif
|
||||
nowp->tv_sec = 0;
|
||||
nowp->tv_usec = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue