[ostree/wip/fetch-meta: 1/2] fetcher: Fix previous commit



commit 9c3a700d774b53105bae2b585d3710a3612cbdd7
Author: Colin Walters <walters verbum org>
Date:   Tue Sep 24 14:10:40 2013 -0400

    fetcher: Fix previous commit
    
    I was getting hangs in the test suite, and looking at the previous
    commit, we were calling the async completion functions out of the
    finalizer for the URI, which is weird.  I didn't analyze what's going
    wrong, but what we really should be doing is processing our internal
    queue after we've downloaded a file, and the request is about to be
    finalized.
    
    I suspect doing queue management from the finalizer created a circular
    reference type situation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708126

 src/libostree/ostree-fetcher.c |   38 ++++++++++++++------------------------
 1 files changed, 14 insertions(+), 24 deletions(-)
---
diff --git a/src/libostree/ostree-fetcher.c b/src/libostree/ostree-fetcher.c
index 3316dd9..84dee49 100644
--- a/src/libostree/ostree-fetcher.c
+++ b/src/libostree/ostree-fetcher.c
@@ -53,9 +53,6 @@ typedef struct {
   GSimpleAsyncResult *result;
 } OstreeFetcherPendingURI;
 
-static void ostree_fetcher_pending_uri_done (OstreeFetcher *self,
-                                             OstreeFetcherPendingURI *pending);
-
 static void
 pending_uri_free (OstreeFetcherPendingURI *pending)
 {
@@ -64,9 +61,6 @@ pending_uri_free (OstreeFetcherPendingURI *pending)
   if (pending->refcount > 0)
     return;
 
-  if (!pending->is_stream)
-    ostree_fetcher_pending_uri_done (pending->self, pending);
-
   soup_uri_free (pending->uri);
   g_clear_object (&pending->self);
   g_clear_object (&pending->out_tmpfile);
@@ -190,24 +184,6 @@ static void
 on_request_sent (GObject        *object, GAsyncResult   *result, gpointer        user_data);
 
 static void
-ostree_fetcher_pending_uri_done (OstreeFetcher *self,
-                                 OstreeFetcherPendingURI *pending)
-{
-  OstreeFetcherPendingURI *p;
-
-  g_assert (!pending->is_stream);
-
-  self->outstanding--;
-  p = g_queue_pop_head (&self->pending_queue);
-  if (p != NULL)
-    {
-      self->outstanding++;
-      soup_request_send_async (p->request, p->cancellable,
-                           on_request_sent, p);
-    }
-}
-
-static void
 ostree_fetcher_queue_pending_uri (OstreeFetcher *self,
                                   OstreeFetcherPendingURI *pending)
 {
@@ -233,6 +209,7 @@ on_splice_complete (GObject        *object,
                     gpointer        user_data) 
 {
   OstreeFetcherPendingURI *pending = user_data;
+  OstreeFetcherPendingURI *next;
   gs_unref_object GFileInfo *file_info = NULL;
   goffset filesize;
   GError *local_error = NULL;
@@ -244,6 +221,19 @@ on_splice_complete (GObject        *object,
   if (!file_info)
     goto out;
 
+  /* Now that we've finished downloading, continue with other queued
+   * requests.
+   */
+  pending->self->outstanding--;
+  next = g_queue_pop_head (&pending->self->pending_queue);
+  while (next != NULL && pending->self->outstanding < pending->self->max_outstanding)
+    {
+      pending->self->outstanding++;
+      soup_request_send_async (next->request, next->cancellable,
+                               on_request_sent, next);
+      next = g_queue_pop_head (&pending->self->pending_queue);
+    }
+
   filesize = g_file_info_get_size (file_info);
   if (filesize < pending->content_length)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]