1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

conncache: move the connection counter to the cache struct

The static connection counter caused a race condition. Moving the
connection id counter into conncache solves it, as well as simplifying
the related logic.
This commit is contained in:
Lindley French 2014-06-12 11:36:41 -07:00 committed by Daniel Stenberg
parent d5d98c1297
commit 964e43c5e2
3 changed files with 3 additions and 13 deletions

View File

@ -149,6 +149,7 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
return result; return result;
} }
conn->connection_id = connc->next_connection_id++;
connc->num_connections++; connc->num_connections++;
return CURLE_OK; return CURLE_OK;

View File

@ -25,6 +25,7 @@
struct conncache { struct conncache {
struct curl_hash *hash; struct curl_hash *hash;
size_t num_connections; size_t num_connections;
size_t next_connection_id;
}; };
struct conncache *Curl_conncache_init(int size); struct conncache *Curl_conncache_init(int size);

View File

@ -3254,19 +3254,7 @@ ConnectionDone(struct SessionHandle *data, struct connectdata *conn)
static CURLcode ConnectionStore(struct SessionHandle *data, static CURLcode ConnectionStore(struct SessionHandle *data,
struct connectdata *conn) struct connectdata *conn)
{ {
static int connection_id_counter = 0; return Curl_conncache_add_conn(data->state.conn_cache, conn);
CURLcode result;
/* Assign a number to the connection for easier tracking in the log
output */
conn->connection_id = connection_id_counter++;
result = Curl_conncache_add_conn(data->state.conn_cache, conn);
if(result != CURLE_OK)
conn->connection_id = -1;
return result;
} }
/* after a TCP connection to the proxy has been verified, this function does /* after a TCP connection to the proxy has been verified, this function does