conncache: move the connection counter to the cache struct
authorLindley French <lindleyf@gmail.com>
Thu, 12 Jun 2014 18:36:41 +0000 (11:36 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 13 Jun 2014 13:05:24 +0000 (15:05 +0200)
The static connection counter caused a race condition. Moving the
connection id counter into conncache solves it, as well as simplifying
the related logic.

lib/conncache.c
lib/conncache.h
lib/url.c

index 3ee64157fd21b76245dc6384445f518917314c55..290638ea00f47ad1fdaa46aab8f27d17d53097b9 100644 (file)
@@ -149,6 +149,7 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
     return result;
   }
 
+  conn->connection_id = connc->next_connection_id++;
   connc->num_connections++;
 
   return CURLE_OK;
index f5e41f187b69a8b7d45546a77cf69c27e264d38f..691f061f945bf18720a418cc870e17eb78cf8e09 100644 (file)
@@ -25,6 +25,7 @@
 struct conncache {
   struct curl_hash *hash;
   size_t num_connections;
+  size_t next_connection_id;
 };
 
 struct conncache *Curl_conncache_init(int size);
index fba3bd3917dd2ba2d792128ae1440604a5154817..770b0cc95ea37fb3b2af9303928791e8256a0910 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3254,19 +3254,7 @@ ConnectionDone(struct SessionHandle *data, struct connectdata *conn)
 static CURLcode ConnectionStore(struct SessionHandle *data,
                                 struct connectdata *conn)
 {
-  static int connection_id_counter = 0;
-
-  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;
+  return Curl_conncache_add_conn(data->state.conn_cache, conn);
 }
 
 /* after a TCP connection to the proxy has been verified, this function does