[libsoup/cache: 39/40] soup-cache: make reading the cached resources from disk async
- From: Xan Lopez <xan src gnome org>
- To: svn-commits-list gnome org
- Subject: [libsoup/cache: 39/40] soup-cache: make reading the cached resources from disk async
- Date: Mon, 27 Jul 2009 10:03:13 +0000 (UTC)
commit b0053ca3c17d1e9e4a1a04462489bc06052111c0
Author: Xan Lopez <xan gnome org>
Date: Mon Jul 27 12:53:54 2009 +0300
soup-cache: make reading the cached resources from disk async
libsoup/soup-cache.c | 46 ++++++++++++++++++++++++++++++++--------------
1 files changed, 32 insertions(+), 14 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index 8cc632a..83ebae2 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -609,12 +609,38 @@ soup_cache_has_response (SoupCache *cache, SoupSession *session, SoupMessage *ms
return TRUE;
}
+static void
+load_contents_ready_cb (GObject *source, GAsyncResult *result, SoupMessage *msg)
+{
+ GFile *file = (GFile*)source;
+ char *contents = NULL;
+ gsize length;
+ GError *error = NULL;
+
+ if (g_file_load_contents_finish (file, result, &contents, &length, NULL, &error)) {
+ SoupBuffer *buffer;
+
+ buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY, contents, length);
+ soup_message_body_append_buffer (msg->response_body, buffer);
+ g_signal_emit_by_name (msg, "got-chunk", buffer, NULL);
+ soup_buffer_free (buffer);
+ g_free (contents);
+
+ soup_message_got_body (msg);
+ soup_message_finished (msg);
+ } else {
+ /* FIXME: I suppose we should request the resource
+ again here? */
+ }
+
+ g_object_unref (file);
+}
+
void
soup_cache_send_response (SoupCache *cache, SoupSession *session, SoupMessage *msg)
{
char *key;
SoupCacheEntry *entry;
- SoupBuffer *buffer;
char *current_age;
key = soup_message_get_cache_key (msg);
@@ -639,21 +665,13 @@ soup_cache_send_response (SoupCache *cache, SoupSession *session, SoupMessage *m
/* Do not try to read anything if the length of the
resource is 0 */
if (entry->data->len) {
- char *data;
- gsize length;
-
- g_file_get_contents (entry->filename, &data, &length, NULL);
+ GFile *file;
- if (data && length) {
- buffer = soup_buffer_new (SOUP_MEMORY_TEMPORARY, data, length);
- soup_message_body_append_buffer (msg->response_body, buffer);
- g_signal_emit_by_name (msg, "got-chunk", buffer, NULL);
- soup_buffer_free (buffer);
- }
+ file = g_file_new_for_path (entry->filename);
+ g_file_load_contents_async (file, NULL,
+ (GAsyncReadyCallback)load_contents_ready_cb,
+ msg);
}
-
- soup_message_got_body (msg);
- soup_message_finished (msg);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]