changeset 1316:b7e9339b0d82

use callback when offering download from Cache_process_queue
author corvid <corvid@lavabit.com>
date Thu, 17 Sep 2009 15:41:39 +0000
parents acb27c4ac38a
children a251eba3613b
files src/cache.c
diffstat 1 files changed, 23 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/cache.c	Thu Sep 17 08:15:20 2009 +0000
+++ b/src/cache.c	Thu Sep 17 15:41:39 2009 +0000
@@ -1030,6 +1030,23 @@
    return;
 }
 
+typedef struct {
+   BrowserWindow *bw;
+   DilloUrl *url;
+} Cache_savelink_t;
+
+/* Save link from behind a timeout so that Cache_process_queue() can
+ * get on with its work.
+ */
+static void Cache_savelink_cb(void *vdata)
+{
+   Cache_savelink_t *data = (Cache_savelink_t*) vdata;
+
+   a_UIcmd_save_link(data->bw, data->url);
+   a_Url_free(data->url);
+   dFree(data);
+}
+
 /*
  * Update cache clients for a single cache-entry
  * Tasks:
@@ -1183,10 +1200,13 @@
       a_Capi_conn_abort_by_url(url);
       entry = NULL;
       if (OfferDownload && Cache_download_enabled(url)) {
-         a_UIcmd_save_link(Client_bw, url);
+         Cache_savelink_t *data = dNew(Cache_savelink_t, 1);
+         data->bw = Client_bw;
+         data->url = url;
+         a_Timeout_add(0.0, Cache_savelink_cb, data);
+      } else {
+         a_Url_free(url);
       }
-      a_Url_free(url);
-
    } else if (entry->Auth && (entry->Flags & CA_GotData)) {
       Cache_auth_entry(entry, Client_bw);
    }