about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-05T12·39+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-05-05T12·39+0200
commit35d30d67ebcca90c3120eeaa7f38baee8805c670 (patch)
tree15020e1cae6ede7458d67ff7ef39d6f377690461 /src/libexpr
parentdeb8668a0eb6b51a791e48942e6c916a2fe1486c (diff)
Make downloads interruptable
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/download.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libexpr/download.cc b/src/libexpr/download.cc
index b23e3196706f..cb06b94e6d87 100644
--- a/src/libexpr/download.cc
+++ b/src/libexpr/download.cc
@@ -54,6 +54,11 @@ struct Curl
         return realSize;
     }
 
+    static int progressCallback(void * clientp, double dltotal, double dlnow, double ultotal, double ulnow)
+    {
+        return _isInterrupted;
+    }
+
     Curl()
     {
         requestHeaders = 0;
@@ -71,6 +76,9 @@ struct Curl
 
         curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, headerCallback);
         curl_easy_setopt(curl, CURLOPT_HEADERDATA, (void *) &curl);
+
+        curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
+        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
     }
 
     ~Curl()
@@ -98,6 +106,7 @@ struct Curl
         curl_easy_setopt(curl, CURLOPT_HTTPHEADER, requestHeaders);
 
         CURLcode res = curl_easy_perform(curl);
+        checkInterrupt();
         if (res == CURLE_WRITE_ERROR && etag == expectedETag) return false;
         if (res != CURLE_OK)
             throw DownloadError(format("unable to download ‘%1%’: %2% (%3%)")