From 3016ec7badccaaebd4b951ba0515c89a882ca537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20Vr=C3=A1til?= Date: Thu, 26 Apr 2012 11:54:42 +0200 Subject: Bug #674340 - Evolution hangs on startup --- mail/e-http-request.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'mail') 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 #include +#include #include @@ -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; } @@ -187,6 +193,15 @@ copy_stream_to_stream (CamelStream *input, return total_len; } +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, @@ -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); -- cgit v1.2.3