aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Vrátil <dvratil@redhat.com>2012-04-26 17:54:42 +0800
committerDan Vrátil <dvratil@redhat.com>2012-04-26 17:54:42 +0800
commit3016ec7badccaaebd4b951ba0515c89a882ca537 (patch)
tree413d00df6b29d4a440a2504f0636979b24de42ea
parent3eecc1b71241ef475cf3d9c7bd86aa9e585c59a7 (diff)
downloadgsoc2013-evolution-3016ec7badccaaebd4b951ba0515c89a882ca537.tar.gz
gsoc2013-evolution-3016ec7badccaaebd4b951ba0515c89a882ca537.tar.zst
gsoc2013-evolution-3016ec7badccaaebd4b951ba0515c89a882ca537.zip
Bug #674340 - Evolution hangs on startup
-rw-r--r--mail/e-http-request.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/mail/e-http-request.c b/mail/e-http-request.c
index f56ba8fc43..ba8b1f5a13 100644
--- a/mail/e-http-request.c
+++ b/mail/e-http-request.c
@@ -26,6 +26,7 @@
#include <webkit/webkit.h>
#include <e-util/e-util.h>
+#include <libedataserver/e-flag.h>
#include <string.h>
@@ -48,6 +49,8 @@ struct _EHTTPRequestPrivate {
G_DEFINE_TYPE (EHTTPRequest, e_http_request, SOUP_TYPE_REQUEST)
struct http_request_async_data {
+ EFlag *flag;
+
GMainLoop *loop;
GCancellable *cancellable;
CamelDataCache *cache;
@@ -107,6 +110,7 @@ http_request_write_to_cache (GInputStream *stream,
g_object_unref (stream);
g_main_loop_quit (data->loop);
+ e_flag_set (data->flag);
}
static void
@@ -123,6 +127,7 @@ http_request_finished (SoupRequest *request,
/* If there is an error or the operation was canceled, do nothing */
if (error) {
g_main_loop_quit (data->loop);
+ e_flag_set (data->flag);
g_error_free (error);
return;
}
@@ -130,8 +135,8 @@ http_request_finished (SoupRequest *request,
if (!stream) {
g_warning("HTTP request failed: %s", error ? error->message: "Unknown error");
g_clear_error (&error);
-
g_main_loop_quit (data->loop);
+ e_flag_set (data->flag);
return;
}
@@ -139,8 +144,8 @@ http_request_finished (SoupRequest *request,
if (!SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
g_warning ("HTTP request failed: HTTP code %d", message->status_code);
g_object_unref (message);
-
g_main_loop_quit (data->loop);
+ e_flag_set (data->flag);
return;
}
@@ -151,6 +156,7 @@ http_request_finished (SoupRequest *request,
if (!data->cache_stream || g_cancellable_is_cancelled (data->cancellable)) {
g_main_loop_quit (data->loop);
+ e_flag_set (data->flag);
return;
}
@@ -188,6 +194,15 @@ copy_stream_to_stream (CamelStream *input,
}
static void
+quit_main_loop (GCancellable *cancellable,
+ GMainLoop *loop)
+{
+ if (g_main_loop_is_running (loop)) {
+ g_main_loop_quit (loop);
+ }
+}
+
+static void
handle_http_request (GSimpleAsyncResult *res,
GObject *object,
GCancellable *cancellable)
@@ -300,6 +315,7 @@ handle_http_request (GSimpleAsyncResult *res,
SoupSession *session;
GMainContext *context;
GError *error;
+ gulong id;
struct http_request_async_data data = { 0 };
@@ -313,6 +329,7 @@ handle_http_request (GSimpleAsyncResult *res,
http_request = soup_requester_request (requester, uri, NULL);
error = NULL;
+ data.flag = e_flag_new ();
data.loop = g_main_loop_new (context, TRUE);
data.cancellable = cancellable;
data.cache = cache;
@@ -336,11 +353,21 @@ handle_http_request (GSimpleAsyncResult *res,
soup_request_send_async (http_request, cancellable,
(GAsyncReadyCallback) http_request_finished, &data);
+ id = g_cancellable_connect (cancellable,
+ G_CALLBACK (quit_main_loop), data.loop, NULL);
+
/* Wait for the asynchronous HTTP GET to finish */
g_main_loop_run (data.loop);
d(printf (" '%s' fetched from internet and (hopefully) stored in"
" cache\n", uri));
+ g_cancellable_disconnect (cancellable, id);
+
+ /* Wait until all asynchronous operations are finished working
+ with the 'data' structure so that it's not free'd too early. */
+ e_flag_wait (data.flag);
+ e_flag_free (data.flag);
+
g_main_loop_unref (data.loop);
g_object_unref (session);