From 78089ad6898f15bc6a716eb39e3f6087dfd9f553 Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Mon, 11 Jun 2018 16:17:14 +0200 Subject: Modify behavior of AbstractChunk::DownloadInternalConnection: don't loop waiting fot the download to be completed, wait curl signalization for proceeding. Change-Id: I07e1f1044435a8fbbe2a5b3fe4d70b42653e4b0f Signed-off-by: Mauro Sardara --- libdash/source/network/AbstractChunk.cpp | 35 ++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/libdash/source/network/AbstractChunk.cpp b/libdash/source/network/AbstractChunk.cpp index 81a3d57c..e626b689 100644 --- a/libdash/source/network/AbstractChunk.cpp +++ b/libdash/source/network/AbstractChunk.cpp @@ -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; -- cgit 1.2.3-korg