summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-06-24 23:22:00 +0000
committerJames Bursa <james@netsurf-browser.org>2003-06-24 23:22:00 +0000
commit9903df5654c13c69b37b6a6142551c6e6f209f80 (patch)
tree67d486e624b7ffd02a4183a5b8cc8f0d7ad8d4f9 /content
parentd60f3764554dc4a796b40b7ddc648254ce799497 (diff)
downloadnetsurf-9903df5654c13c69b37b6a6142551c6e6f209f80.tar.gz
netsurf-9903df5654c13c69b37b6a6142551c6e6f209f80.tar.bz2
[project @ 2003-06-24 23:22:00 by bursa]
Change cache to use current content sizes. svn path=/import/netsurf/; revision=183
Diffstat (limited to 'content')
-rw-r--r--content/cache.c98
-rw-r--r--content/content.c7
-rw-r--r--content/fetch.c16
3 files changed, 81 insertions, 40 deletions
diff --git a/content/cache.c b/content/cache.c
index aa4727eb3..cdb7cf881 100644
--- a/content/cache.c
+++ b/content/cache.c
@@ -1,5 +1,5 @@
/**
- * $Id: cache.c,v 1.4 2003/06/17 19:24:20 bursa Exp $
+ * $Id: cache.c,v 1.5 2003/06/24 23:22:00 bursa Exp $
*/
#include <assert.h>
@@ -27,21 +27,23 @@ void content_destroy(struct content *c);
* internal structures and declarations
*/
+static void cache_shrink(void);
+static unsigned long cache_size(void);
+
struct cache_entry {
struct content *content;
- time_t t;
struct cache_entry *next, *prev;
};
/* doubly-linked lists using a sentinel */
/* TODO: replace with a structure which can be searched faster */
-static struct cache_entry inuse_list_sentinel = {0, 0, &inuse_list_sentinel, &inuse_list_sentinel};
-static struct cache_entry unused_list_sentinel = {0, 0, &unused_list_sentinel, &unused_list_sentinel};
+/* unused list is ordered from most recently to least recently used */
+static struct cache_entry inuse_list_sentinel = {0, &inuse_list_sentinel, &inuse_list_sentinel};
+static struct cache_entry unused_list_sentinel = {0, &unused_list_sentinel, &unused_list_sentinel};
static struct cache_entry *inuse_list = &inuse_list_sentinel;
static struct cache_entry *unused_list = &unused_list_sentinel;
static unsigned long max_size = 1024*1024; /* TODO: make this configurable */
-static unsigned long current_size = 0;
/**
@@ -110,19 +112,7 @@ void cache_put(struct content * content)
struct cache_entry * e;
LOG(("content %p, url '%s', size %lu", content, content->url, content->size));
- /* TODO: contents will grow in size as they load */
- current_size += content->size;
- /* clear old data from the usused_list until the size drops below max_size */
- while (max_size < current_size && unused_list->next != unused_list) {
- e = unused_list->next;
- LOG(("size %lu, removing %p '%s'", current_size, e->content, e->content->url));
- /* TODO: move to disc cache */
- current_size -= e->content->size;
- content_destroy(e->content);
- unused_list->next = e->next;
- e->next->prev = e->prev;
- xfree(e);
- }
+ cache_shrink();
/* add the new content to the inuse_list */
e = xcalloc(1, sizeof(struct cache_entry));
@@ -146,32 +136,66 @@ void cache_freeable(struct content * content)
assert(e != 0);
LOG(("content %p, url '%s'", content, content->url));
- /* move to unused_list or destroy if insufficient space */
- e->t = time(0);
+ /* move to unused_list */
e->prev->next = e->next;
e->next->prev = e->prev;
- if (max_size < current_size) {
- LOG(("size %lu, removing", current_size));
- /* TODO: move to disc cache */
- current_size -= e->content->size;
- content_destroy(e->content);
- xfree(e);
- } else {
- LOG(("size %lu, moving to unused_list", current_size));
- e->prev = unused_list->prev;
- e->next = unused_list;
- unused_list->prev->next = e;
- unused_list->prev = e;
- }
+ e->prev = unused_list;
+ e->next = unused_list->next;
+ unused_list->next->prev = e;
+ unused_list->next = e;
}
+/**
+ * cache_destroy -- remove a content immediately
+ */
+
void cache_destroy(struct content * content)
{
struct cache_entry * e = content->cache;
e->prev->next = e->next;
e->next->prev = e->prev;
- current_size -= content->size;
+ xfree(e);
+}
+
+
+/**
+ * cache_shrink -- attempt to reduce cache size below max_size
+ */
+
+void cache_shrink(void)
+{
+ struct cache_entry * e;
+ unsigned long size = cache_size();
+
+ /* clear old data from the usused_list until the size drops below max_size */
+ while (max_size < size && unused_list->next != unused_list) {
+ e = unused_list->prev;
+ LOG(("size %lu, removing %p '%s'", size, e->content, e->content->url));
+ /* TODO: move to disc cache */
+ size -= e->content->size;
+ content_destroy(e->content);
+ unused_list->prev = e->prev;
+ e->prev->next = unused_list;
+ xfree(e);
+ }
+ LOG(("size %lu", size));
+}
+
+
+/**
+ * cache_size -- current size of the cache
+ */
+
+unsigned long cache_size(void)
+{
+ struct cache_entry * e;
+ unsigned long size = 0;
+ for (e = inuse_list->next; e != inuse_list; e = e->next)
+ size += e->content->size;
+ for (e = unused_list->next; e != unused_list; e = e->next)
+ size += e->content->size;
+ return size;
}
@@ -181,15 +205,15 @@ void cache_destroy(struct content * content)
void cache_dump(void) {
struct cache_entry * e;
- LOG(("size %lu", current_size));
+ LOG(("size %lu", cache_size()));
LOG(("inuse_list:"));
for (e = inuse_list->next; e != inuse_list; e = e->next)
LOG((" content %p, size %lu, url '%s'", e->content,
e->content->size, e->content->url));
LOG(("unused_list (time now %lu):", time(0)));
for (e = unused_list->next; e != unused_list; e = e->next)
- LOG((" content %p, size %lu, url '%s', t %lu", e->content,
- e->content->size, e->content->url, e->t));
+ LOG((" content %p, size %lu, url '%s'", e->content,
+ e->content->size, e->content->url));
LOG(("end"));
}
diff --git a/content/content.c b/content/content.c
index 65e730ee5..6520b6805 100644
--- a/content/content.c
+++ b/content/content.c
@@ -1,5 +1,8 @@
-/**
- * $Id: content.c,v 1.11 2003/06/17 19:24:20 bursa Exp $
+/*
+ * This file is part of NetSurf, http://netsurf.sourceforge.net/
+ * Licensed under the GNU General Public License,
+ * http://www.opensource.org/licenses/gpl-license
+ * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
*/
#include <assert.h>
diff --git a/content/fetch.c b/content/fetch.c
index 65a0de988..1e2f4686a 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -1,5 +1,5 @@
/**
- * $Id: fetch.c,v 1.10 2003/06/17 19:24:20 bursa Exp $
+ * $Id: fetch.c,v 1.11 2003/06/24 23:22:00 bursa Exp $
*
* This module handles fetching of data from any url.
*
@@ -21,6 +21,9 @@
#include "netsurf/utils/utils.h"
#include "netsurf/utils/log.h"
#include "netsurf/desktop/options.h"
+#ifdef riscos
+#include "netsurf/desktop/gui.h"
+#endif
struct fetch
{
@@ -42,6 +45,7 @@ struct fetch
};
static const char * const user_agent = "NetSurf";
+static char * ca_bundle;
static CURLM * curl_multi;
static struct fetch *fetch_list = 0;
@@ -64,6 +68,12 @@ void fetch_init(void)
curl_multi = curl_multi_init();
if (curl_multi == 0)
die("curl_multi_init failed");
+
+#ifdef riscos
+ ca_bundle = xcalloc(strlen(NETSURF_DIR) + 100, 1);
+ sprintf(ca_bundle, "%s.Resources.ca-bundle", NETSURF_DIR);
+ LOG(("ca_bundle '%s'", ca_bundle));
+#endif
}
@@ -170,6 +180,10 @@ struct fetch * fetch_start(char *url, char *referer,
code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, referer);
assert(code == CURLE_OK);
}
+#ifdef riscos
+ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_CAINFO, ca_bundle);
+ assert(code == CURLE_OK);
+#endif
/* custom request headers */
fetch->headers = 0;