| 81 | |
| 82 | #define HTTP_MAX_CONCURRENCY 6 |
| 83 | static 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 | |
| 116 | EMSCRIPTEN_KEEPALIVE void Http_OnUpdateProgress(int reqID, int read, int total) { |
| 117 | int idx = RequestList_Find(&workingReqs, reqID); |
no test coverage detected