MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Http_StartNextDownload

Function Http_StartNextDownload

src/webclient/Http_Web.c:83–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82#define HTTP_MAX_CONCURRENCY 6
83static void Http_StartNextDownload(void) {
84 char urlBuffer[URL_MAX_SIZE]; cc_string url;
85 char urlStr[NATIVE_STR_LEN];
86 struct HttpRequest* req;
87 cc_result res;
88
89 // Avoid making too many requests at once
90 if (workingReqs.count >= HTTP_MAX_CONCURRENCY) return;
91 if (!queuedReqs.count) return;
92 String_InitArray(url, urlBuffer);
93
94 req = &queuedReqs.entries[0];
95 GetFinalUrl(req, &url);
96 Platform_Log1("Fetching %s", &url);
97
98 String_EncodeUtf8(urlStr, &url);
99 res = interop_DownloadAsync(urlStr, req->requestType, req->id);
100
101 if (res) {
102 // interop error code -> ClassiCube error code
103 if (res == 1) res = ERR_INVALID_DATA_URL;
104 req->result = res;
105
106 // Invalid URL so move onto next request
107 Http_FinishRequest(req);
108 RequestList_RemoveAt(&queuedReqs, 0);
109 Http_StartNextDownload();
110 } else {
111 RequestList_Append(&workingReqs, req, false);
112 RequestList_RemoveAt(&queuedReqs, 0);
113 }
114}
115
116EMSCRIPTEN_KEEPALIVE void Http_OnUpdateProgress(int reqID, int read, int total) {
117 int idx = RequestList_Find(&workingReqs, reqID);

Callers 2

Http_OnFinishedAsyncFunction · 0.85
HttpBackend_AddFunction · 0.85

Calls 6

GetFinalUrlFunction · 0.85
Platform_Log1Function · 0.85
String_EncodeUtf8Function · 0.85
Http_FinishRequestFunction · 0.85
RequestList_RemoveAtFunction · 0.85
RequestList_AppendFunction · 0.85

Tested by

no test coverage detected