summaryrefslogtreecommitdiff
path: root/lib/hash.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2012-12-06 12:12:04 +0100
committerDaniel Stenberg <daniel@haxx.se>2012-12-07 10:08:33 +0100
commitd021f2e8a0067fc769652f27afec9024c0d02b3d (patch)
tree563742088b9866a1b8aa42ee7aab4501d72623dd /lib/hash.c
parentca5f4e21357a0b4a55e7a2a0f71e632442723989 (diff)
downloadgnurl-d021f2e8a0067fc769652f27afec9024c0d02b3d.tar.gz
gnurl-d021f2e8a0067fc769652f27afec9024c0d02b3d.tar.bz2
gnurl-d021f2e8a0067fc769652f27afec9024c0d02b3d.zip
Introducing a new persistent connection caching system using "bundles".
A bundle is a list of all persistent connections to the same host. The connection cache consists of a hash of bundles, with the hostname as the key. The benefits may not be obvious, but they are two: 1) Faster search for connections to reuse, since the hash lookup only finds connections to the host in question. 2) It lays out the groundworks for an upcoming patch, which will introduce multiple HTTP pipelines. This patch also removes the awkward list of "closure handles", which were needed to send QUIT commands to the FTP server when closing a connection. Now we allocate a separate closure handle and use that one to close all connections. This has been tested in a live system for a few weeks, and of course passes the test suite.
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c77
1 files changed, 60 insertions, 17 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 4d85188fb..585285b03 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -322,34 +322,77 @@ size_t Curl_str_key_compare(void*k1, size_t key1_len, void*k2, size_t key2_len)
return 0;
}
+void Curl_hash_start_iterate(struct curl_hash *hash,
+ struct curl_hash_iterator *iter)
+{
+ iter->hash = hash;
+ iter->slot_index = 0;
+ iter->current_element = NULL;
+}
+
+struct curl_hash_element *
+Curl_hash_next_element(struct curl_hash_iterator *iter)
+{
+ int i;
+ struct curl_hash *h = iter->hash;
+
+ /* Get the next element in the current list, if any */
+ if(iter->current_element)
+ iter->current_element = iter->current_element->next;
+
+ /* If we have reached the end of the list, find the next one */
+ if(!iter->current_element) {
+ for(i = iter->slot_index;i < h->slots;i++) {
+ if(h->table[i]->head) {
+ iter->current_element = h->table[i]->head;
+ iter->slot_index = i+1;
+ break;
+ }
+ }
+ }
+
+ if(iter->current_element) {
+ struct curl_hash_element *he = iter->current_element->ptr;
+ return he;
+ }
+ else {
+ iter->current_element = NULL;
+ return NULL;
+ }
+}
+
#if 0 /* useful function for debugging hashes and their contents */
void Curl_hash_print(struct curl_hash *h,
void (*func)(void *))
{
- int i;
- struct curl_llist_element *le;
- struct curl_llist *list;
- struct curl_hash_element *he;
+ struct curl_hash_iterator iter;
+ struct curl_hash_element *he;
+ int last_index = -1;
+
if(!h)
return;
fprintf(stderr, "=Hash dump=\n");
- for(i = 0; i < h->slots; i++) {
- list = h->table[i];
- le = list->head; /* get first list entry */
- if(le) {
- fprintf(stderr, "index %d:", i);
- while(le) {
- he = le->ptr;
- if(func)
- func(he->ptr);
- else
- fprintf(stderr, " [%p]", he->ptr);
- le = le->next;
+ Curl_hash_start_iterate(h, &iter);
+
+ he = Curl_hash_next_element(&iter);
+ while(he) {
+ if(iter.slot_index != last_index) {
+ fprintf(stderr, "index %d:", iter.slot_index);
+ if(last_index >= 0) {
+ fprintf(stderr, "\n");
}
- fprintf(stderr, "\n");
+ last_index = iter.slot_index;
}
+
+ if(func)
+ func(he->ptr);
+ else
+ fprintf(stderr, " [%p]", he->ptr);
+
+ he = Curl_hash_next_element(&iter);
}
+ fprintf(stderr, "\n");
}
#endif