Modify behavior of AbstractChunk::DownloadInternalConnection: don't loop waiting... 90/12990/4
authorMauro Sardara <[email protected]>
Mon, 11 Jun 2018 14:17:14 +0000 (16:17 +0200)
committerMauro Sardara <[email protected]>
Mon, 11 Jun 2018 14:21:06 +0000 (14:21 +0000)
Change-Id: I07e1f1044435a8fbbe2a5b3fe4d70b42653e4b0f
Signed-off-by: Mauro Sardara <[email protected]>
libdash/source/network/AbstractChunk.cpp

index 81a3d57..e626b68 100644 (file)
@@ -155,12 +155,39 @@ void*   AbstractChunk::DownloadInternalConnection   (void *abstractchunk)
     AbstractChunk *chunk  = (AbstractChunk *) abstractchunk;
 
     //chunk->response = curl_easy_perform(chunk->curl);
-    int u =1;
+    int u = 1;
+    CURLMcode ret_code;
+    int repeats = 0;
 
-    while(chunk->stateManager.State() != REQUEST_ABORT && u)
+    do
     {
-       curl_multi_perform(chunk->curlm, &u);
-    }
+        int numfds;
+
+        ret_code = curl_multi_wait(chunk->curlm, NULL, 0, 1000, &numfds);
+
+        if (ret_code != CURLM_OK)
+        {
+            fprintf(stderr, "CURL Multi Wait failed!!!\n");
+            break;
+        }
+
+        if (numfds == 0)
+        {
+            repeats++;
+            if (repeats > 1)
+            {
+               usleep(100000);
+            }
+        }
+        else
+        {
+            repeats = 0;
+        }
+
+        ret_code = curl_multi_perform(chunk->curlm, &u);
+
+    } while(chunk->stateManager.State() != REQUEST_ABORT && u && ret_code == CURLM_OK);
+
     double speed;
     double size;
     double time;