]> err.no Git - mapper/commitdiff
Init curl_multi once and use it until deinit
authorKaj-Michael Lang <milang@tal.org>
Fri, 4 Apr 2008 12:54:08 +0000 (15:54 +0300)
committerKaj-Michael Lang <milang@tal.org>
Fri, 4 Apr 2008 12:54:08 +0000 (15:54 +0300)
src/map-download.c

index 44ded6c86e67157058c3c7c37f3c4df521c7d5d3..60913f5a4475b171079facec3060c5e0a772a330 100644 (file)
@@ -201,11 +201,6 @@ while (num_transfers < (4*4) && g_tree_nnodes(pui_tree)) {
                        curl_easy_setopt(curl_easy, CURLOPT_URL, pui->src_str);
                        curl_easy_setopt(curl_easy, CURLOPT_WRITEDATA, f);
                        g_hash_table_insert(pui_by_easy, curl_easy, pui);
-                       if (!_curl_multi) {
-                               /* Initialize CURL. */
-                               _curl_multi = curl_multi_init();
-                               /*curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
-                       }
                        curl_multi_add_handle(_curl_multi, curl_easy);
                        num_transfers++;
                } else {
@@ -237,9 +232,6 @@ if (!(num_transfers || g_tree_nnodes(pui_tree))) {
                while ((curr = g_queue_pop_tail(curl_easy_queue)))
                        curl_easy_cleanup(curr);
 
-               curl_multi_cleanup(_curl_multi);
-               _curl_multi = NULL;
-
                _curl_sid = 0;
                return FALSE;
        }
@@ -501,6 +493,8 @@ curl_easy_queue = g_queue_new();
 pui_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
 downloading_tree = g_tree_new_full((GCompareDataFunc)download_comparefunc, NULL, (GDestroyNotify) progress_update_info_free, NULL);
 pui_by_easy = g_hash_table_new(g_direct_hash, g_direct_equal);
+_curl_multi = curl_multi_init();
+/* curl_multi_setopt(_curl_multi, CURLMOPT_PIPELINING, 1); */
 }
 
 gboolean
@@ -532,8 +526,6 @@ if (_curl_multi) {
        g_debug("Stopping downloads");
        while ((curr = g_queue_pop_tail(curl_easy_queue)))
                curl_easy_cleanup(curr);
-       curl_multi_cleanup(_curl_multi);
-       _curl_multi = NULL;
        return TRUE;
 }
 g_debug("No downloads to stop");
@@ -566,6 +558,8 @@ if (_curl_multi) {
                g_hash_table_destroy(pui_by_easy);
        if (curl_easy_queue)
                g_queue_free(curl_easy_queue);
+       curl_multi_cleanup(_curl_multi);
+       _curl_multi = NULL;
 }
 
 if (_curl_sid) {