From 2629cc8ef2d52e3dc1ca1556ec5d0a97f3469bb5 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Mon, 18 Mar 2024 00:25:38 +0100 Subject: Multi shit --- internal/curl/curl.ha | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/curl/curl.ha') diff --git a/internal/curl/curl.ha b/internal/curl/curl.ha index 3eeb4c6..43fbc52 100644 --- a/internal/curl/curl.ha +++ b/internal/curl/curl.ha @@ -71,3 +71,24 @@ export fn get(url: const str, resp: *response) (void | curlerror) = { }; resp.status = rc; }; + +// Makes a HTTP request to the given url and fills resp with the body, HTTP +// status and body size. +export fn getmulti(url: const str, resp: *response) (void | curlerror) = { + let cm = ccurl::curl_multi_init(); + defer ccurl::curl_multi_cleanup(cm); + let c = ccurl::curl_easy_init(); + defer ccurl::curl_easy_cleanup(c); + + let c_url = c::fromstr(url); + defer free(c_url); + let res = ccurl::curl_easy_setopt(c, ccurl::CURLOPT_URL, c_url); + if (res != 0) { + return res: setopterr; + }; + ccurl::curl_multi_add_handle(cm, c); + defer ccurl::curl_multi_remove_handle(cm, c); + + let still_running = 0; + ccurl::curl_multi_perform(cm, &still_running); +}; -- cgit v1.2.3