summaryrefslogtreecommitdiff
path: root/lib/conncache.h
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-12-02 14:27:00 +0100
committerDaniel Stenberg <daniel@haxx.se>2017-12-05 23:21:02 +0100
commit07cb27c98e92649e74a312faf976271fa7da609c (patch)
tree174c9985ca7e8623401117608e52b46afe2914c2 /lib/conncache.h
parent85f0133ea14f411b4dae9c6239c83a67ca7bca89 (diff)
downloadgnurl-07cb27c98e92649e74a312faf976271fa7da609c.tar.gz
gnurl-07cb27c98e92649e74a312faf976271fa7da609c.tar.bz2
gnurl-07cb27c98e92649e74a312faf976271fa7da609c.zip
conncache: fix several lock issues
If the lock is released before the dealings with the bundle is over, it may have changed by another thread in the mean time. Fixes #2132 Fixes #2151 Closes #2139
Diffstat (limited to 'lib/conncache.h')
-rw-r--r--lib/conncache.h26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/conncache.h b/lib/conncache.h
index 0d97a6cef..d8ad80f96 100644
--- a/lib/conncache.h
+++ b/lib/conncache.h
@@ -23,9 +23,15 @@
*
***************************************************************************/
+/*
+ * All accesses to struct fields and changing of data in the connection cache
+ * and connectbundles must be done with the conncache LOCKED. The cache might
+ * be shared.
+ */
+
struct conncache {
struct curl_hash hash;
- size_t num_connections;
+ size_t num_conn;
long next_connection_id;
struct curltime last_cleanup;
/* handle used for closing cached connections */
@@ -50,14 +56,17 @@ void Curl_conncache_destroy(struct conncache *connc);
/* return the correct bundle, to a host or a proxy */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
struct conncache *connc);
+void Curl_conncache_unlock(struct connectdata *conn);
+/* returns number of connections currently held in the connection cache */
+size_t Curl_conncache_size(struct Curl_easy *data);
+size_t Curl_conncache_bundle_size(struct connectdata *conn);
+bool Curl_conncache_return_conn(struct connectdata *conn);
CURLcode Curl_conncache_add_conn(struct conncache *connc,
struct connectdata *conn);
-
-void Curl_conncache_remove_conn(struct conncache *connc,
- struct connectdata *conn);
-
-void Curl_conncache_foreach(struct Curl_easy *data,
+void Curl_conncache_remove_conn(struct connectdata *conn,
+ bool lock);
+bool Curl_conncache_foreach(struct Curl_easy *data,
struct conncache *connc,
void *param,
int (*func)(struct connectdata *conn,
@@ -67,7 +76,10 @@ struct connectdata *
Curl_conncache_find_first_connection(struct conncache *connc);
struct connectdata *
-Curl_conncache_oldest_idle(struct Curl_easy *data);
+Curl_conncache_extract_bundle(struct Curl_easy *data,
+ struct connectbundle *bundle);
+struct connectdata *
+Curl_conncache_extract_oldest(struct Curl_easy *data);
void Curl_conncache_close_all_connections(struct conncache *connc);
void Curl_conncache_print(struct conncache *connc);