#include "image_png.h"
static cvar_t curl_enabled = {CF_SHARED | CF_ARCHIVE, "curl_enabled","1", "whether libcurl may be used to GET files or POST data"};
-static cvar_t curl_maxdownloads = {CF_SHARED | CF_ARCHIVE, "curl_maxdownloads","1", "maximum number of concurrent HTTP/FTP downloads"};
-static cvar_t curl_maxspeed = {CF_SHARED | CF_ARCHIVE, "curl_maxspeed","300", "maximum download speed (KiB/s)"};
+static cvar_t curl_maxdownloads = {CF_SHARED | CF_ARCHIVE, "curl_maxdownloads","3", "maximum number of concurrent HTTP/FTP downloads"};
+static cvar_t curl_maxspeed = {CF_SHARED | CF_ARCHIVE, "curl_maxspeed","0", "maximum download speed (KiB/s)"};
static cvar_t curl_useragent = {CF_SHARED, "curl_useragent","1", "send the User-Agent string (note: turning this off may break stuff)"};
static cvar_t curl_useragent_append = {CF_SHARED, "curl_useragent_append","", "a string to append to the User-Agent string (useful for name and version number of your mod)"};
static CURLM * (*qcurl_multi_init) (void);
static CURLMcode (*qcurl_multi_perform) (CURLM *multi_handle, int *running_handles);
-static CURLMcode (*qcurl_multi_poll) (CURLM *multi_handle, void*, unsigned int extra_nfds, int timeout_ms, int *ret);
+static CURLMcode (*qcurl_multi_wait) (CURLM *multi_handle, void*, unsigned int extra_nfds, int timeout_ms, int *ret);
static CURLMcode (*qcurl_multi_add_handle) (CURLM *multi_handle, CURL *easy_handle);
static CURLMcode (*qcurl_multi_remove_handle) (CURLM *multi_handle, CURL *easy_handle);
static CURLMsg * (*qcurl_multi_info_read) (CURLM *multi_handle, int *msgs_in_queue);
{"curl_easy_getinfo", (void **) &qcurl_easy_getinfo},
{"curl_multi_init", (void **) &qcurl_multi_init},
{"curl_multi_perform", (void **) &qcurl_multi_perform},
- {"curl_multi_poll", (void **) &qcurl_multi_poll},
+ {"curl_multi_wait", (void **) &qcurl_multi_wait},
{"curl_multi_add_handle", (void **) &qcurl_multi_add_handle},
{"curl_multi_remove_handle",(void **) &qcurl_multi_remove_handle},
{"curl_multi_info_read", (void **) &qcurl_multi_info_read},
if(!curl_dll)
return;
if(cmd)
- strlcpy(command_when_done, cmd, sizeof(command_when_done));
+ dp_strlcpy(command_when_done, cmd, sizeof(command_when_done));
else
*command_when_done = 0;
}
if(!curl_dll)
return;
if(cmd)
- strlcpy(command_when_error, cmd, sizeof(command_when_error));
+ dp_strlcpy(command_when_error, cmd, sizeof(command_when_error));
else
*command_when_error = 0;
}
break;
}
if(content_type_)
- strlcpy(content_type, content_type_, sizeof(content_type));
+ dp_strlcpy(content_type, content_type_, sizeof(content_type));
else
*content_type = 0;
if(forthismap)
++numdownloads_added;
di = (downloadinfo *) Z_Malloc(sizeof(*di));
- strlcpy(di->filename, name, sizeof(di->filename));
- strlcpy(di->url, URL, sizeof(di->url));
+ dp_strlcpy(di->filename, name, sizeof(di->filename));
+ dp_strlcpy(di->url, URL, sizeof(di->url));
dpsnprintf(di->referer, sizeof(di->referer), "dp://%s/", cls.netcon ? cls.netcon->address : "notconnected.invalid");
di->forthismap = forthismap;
di->stream = NULL;
Sleeps until there's some transfer progress or a timeout is reached,
unfortunately the timeout is only in milliseconds.
This allows good throughput even at very low FPS.
+Less important on newer libcurl versions but still helps.
+
+Returns 0 immediately if there's no transfers to wait for,
+or > 0 if a transfer is ready or the timeout was reached.
====================
*/
-void Curl_Select(double *microseconds)
+int Curl_Select(int timeout_ms)
{
+ CURLMcode err;
+ int numfds;
+
if (List_Is_Empty(&downloads))
- return;
- if (qcurl_multi_poll(curlm, NULL, 0, *microseconds / 1000, NULL) == CURLM_OK)
- *microseconds = 0; // either we finished waiting or a transfer progressed
- else
- Con_Print("There's an emergency going on!\nIt's still going on!\nMaybe you need to upgrade libcurl?\n");
+ return 0;
+
+ err = qcurl_multi_wait(curlm, NULL, 0, timeout_ms, &numfds);
+ if (err == CURLM_OK)
+ return numfds;
+ Con_Printf("curl_multi_wait() failed, code %d\n", err);
+ return 0;
}
/*
if(developer.integer <= 0)
if(di->buffer)
continue;
- strlcpy(downinfo[i].filename, di->filename, sizeof(downinfo[i].filename));
+ dp_strlcpy(downinfo[i].filename, di->filename, sizeof(downinfo[i].filename));
if(di->curle)
{
downinfo[i].progress = Curl_GetDownloadAmount(di);
*urlend = 0;
if(matchpattern(filename, pattern, true))
{
- strlcpy(foundurl, url, sizeof(foundurl));
+ dp_strlcpy(foundurl, url, sizeof(foundurl));
Z_Free(buf);
return foundurl;
}
{
requirement *req = (requirement *) Z_Malloc(sizeof(*requirements));
req->next = requirements;
- strlcpy(req->filename, filename, sizeof(req->filename));
+ dp_strlcpy(req->filename, filename, sizeof(req->filename));
requirements = req;
}
if(packurl && *packurl && strcmp(packurl, "-"))
{
if(!foundone)
- strlcat(sendbuffer, "curl --clear_autodownload\n", sendbuffer_len);
+ dp_strlcat(sendbuffer, "curl --clear_autodownload\n", sendbuffer_len);
- strlcat(sendbuffer, "curl --pak --forthismap --as ", sendbuffer_len);
- strlcat(sendbuffer, thispack, sendbuffer_len);
+ dp_strlcat(sendbuffer, "curl --pak --forthismap --as ", sendbuffer_len);
+ dp_strlcat(sendbuffer, thispack, sendbuffer_len);
if(sv_curl_maxspeed.value > 0)
dpsnprintf(sendbuffer + strlen(sendbuffer), sendbuffer_len - strlen(sendbuffer), " --maxspeed=%.1f", sv_curl_maxspeed.value);
- strlcat(sendbuffer, " --for ", sendbuffer_len);
- strlcat(sendbuffer, filename, sendbuffer_len);
- strlcat(sendbuffer, " ", sendbuffer_len);
- strlcat(sendbuffer, packurl, sendbuffer_len);
- strlcat(sendbuffer, thispack, sendbuffer_len);
- strlcat(sendbuffer, "\n", sendbuffer_len);
+ dp_strlcat(sendbuffer, " --for ", sendbuffer_len);
+ dp_strlcat(sendbuffer, filename, sendbuffer_len);
+ dp_strlcat(sendbuffer, " ", sendbuffer_len);
+ dp_strlcat(sendbuffer, packurl, sendbuffer_len);
+ dp_strlcat(sendbuffer, thispack, sendbuffer_len);
+ dp_strlcat(sendbuffer, "\n", sendbuffer_len);
return true;
}
foundone = Curl_SendRequirement(com_token, foundone, sendbuffer, sizeof(sendbuffer)) || foundone;
if(foundone)
- strlcat(sendbuffer, "curl --finish_autodownload\n", sizeof(sendbuffer));
+ dp_strlcat(sendbuffer, "curl --finish_autodownload\n", sizeof(sendbuffer));
if(strlen(sendbuffer) + 1 < sizeof(sendbuffer))
SV_ClientCommands("%s", sendbuffer);