FileDownloader now works in Emscripten
This commit is contained in:
parent
dc834f84f8
commit
f972fd5024
5 changed files with 79 additions and 27 deletions
|
|
@ -1,12 +1,15 @@
|
|||
#pragma once
|
||||
#ifndef __EMSCRIPTEN__
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <curl/curl.h>
|
||||
#else
|
||||
#include <emscripten/fetch.h>
|
||||
#endif
|
||||
|
||||
class FileDownloader {
|
||||
public:
|
||||
|
|
@ -24,28 +27,30 @@ class FileDownloader {
|
|||
static std::shared_ptr<DownloadData> download_data_from_url(std::string_view url);
|
||||
static void cleanup();
|
||||
private:
|
||||
static void add_new_handlers_to_multi();
|
||||
static void download_thread_update();
|
||||
|
||||
struct DownloadHandler {
|
||||
CURL* eHandle;
|
||||
#ifndef __EMSCRIPTEN__
|
||||
CURL* eHandle;
|
||||
#endif
|
||||
std::shared_ptr<DownloadData> data;
|
||||
};
|
||||
|
||||
static std::mutex newDownloadsMutex;
|
||||
static std::vector<DownloadHandler> newDownloads;
|
||||
static std::atomic<bool> shutdownThread;
|
||||
static CURLM* mHandle;
|
||||
static std::vector<DownloadHandler> currentDownloads;
|
||||
static std::unique_ptr<std::thread> downloadThread;
|
||||
|
||||
static void save_to_string(CURL* curl, std::string* str);
|
||||
static void disable_ssl_verification(CURL* curl);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static std::mutex newDownloadsMutex;
|
||||
static std::vector<DownloadHandler> newDownloads;
|
||||
static std::atomic<bool> shutdownThread;
|
||||
static CURLM* mHandle;
|
||||
static std::unique_ptr<std::thread> downloadThread;
|
||||
|
||||
static timeval get_timeout(CURLM* mCurl);
|
||||
static int wait_if_needed(CURLM* mCurl, timeval& timeout);
|
||||
|
||||
static size_t write_to_string(void* contents, size_t size, size_t nmemb, void* userp);
|
||||
static void save_to_string(CURL* curl, std::string* str);
|
||||
static void disable_ssl_verification(CURL* curl);
|
||||
static size_t write_to_string(void* contents, size_t size, size_t nmemb, void* userp);
|
||||
static void add_new_handlers_to_multi();
|
||||
static void download_thread_update();
|
||||
#else
|
||||
static void download_succeeded(emscripten_fetch_t *fetch);
|
||||
static void download_failed(emscripten_fetch_t *fetch);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue