aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index accd0c4..abfa1dd 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -80,6 +80,7 @@ namespace dchat
texture->generateMipmap();
return { texture, ImageByUrlResult::Type::CACHED };
}
+ delete texture;
delete fileContent.data;
}
}
@@ -100,7 +101,6 @@ namespace dchat
{
while(true)
{
- imageDownloadMutex.lock();
for(vector<ImageDownloadInfo>::iterator it = imageDownloadProcesses.begin(); it != imageDownloadProcesses.end();)
{
int exitStatus;
@@ -114,7 +114,9 @@ namespace dchat
filepath /= urlHash.toString();
ImageByUrlResult imageByUrlResult = loadImageFromFile(filepath);
+ imageDownloadMutex.lock();
imageUrlCache[it->url] = imageByUrlResult;
+ imageDownloadMutex.unlock();
switch(imageByUrlResult.type)
{
case ImageByUrlResult::Type::CACHED:
@@ -130,11 +132,21 @@ namespace dchat
else
++it;
}
- imageDownloadMutex.unlock();
- while(imageDownloadProcesses.empty())
+ while(imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty())
this_thread::sleep_for(chrono::milliseconds(20));
+ if(!imageDownloadProcessesQueue.empty())
+ {
+ imageDownloadMutex.lock();
+ for(auto imageDownloadInfo : imageDownloadProcessesQueue)
+ {
+ imageDownloadProcesses.push_back(imageDownloadInfo);
+ }
+ imageDownloadProcessesQueue.clear();
+ imageDownloadMutex.unlock();
+ }
+
this_thread::sleep_for(chrono::milliseconds(20));
}
});
@@ -169,10 +181,10 @@ namespace dchat
Process::string_type cmd = "curl -L --silent -o '";
cmd += filepath.native();
cmd += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + url + "'";
- // certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file
+ // TODO: Use this instead of curl on windows: certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file
Process *process = new Process(cmd, "", nullptr, nullptr, false);
ImageDownloadInfo imageDownloadInfo { process, url };
- imageDownloadProcesses.emplace_back(imageDownloadInfo);
+ imageDownloadProcessesQueue.emplace_back(imageDownloadInfo);
return result;
}
}