diff options
| author | Julian Hurst <ark@mansus.space> | 2024-03-18 00:25:38 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2024-03-18 00:25:43 +0100 |
| commit | 2629cc8ef2d52e3dc1ca1556ec5d0a97f3469bb5 (patch) | |
| tree | 2ed3b4f92dfff3963cb0924059d691b748aa2263 | |
| parent | a5fd529e47ecbd4de465b46d943b34f88a500467 (diff) | |
| download | hacurl-multi.tar.gz | |
Multi shitmulti
| -rwxr-xr-x | hacurl | bin | 0 -> 797064 bytes | |||
| -rw-r--r-- | internal/curl/ccurl/ccurl.ha | 7 | ||||
| -rw-r--r-- | internal/curl/curl.ha | 21 |
3 files changed, 28 insertions, 0 deletions
| Binary files differ diff --git a/internal/curl/ccurl/ccurl.ha b/internal/curl/ccurl/ccurl.ha index 3e44d97..9c8b19d 100644 --- a/internal/curl/ccurl/ccurl.ha +++ b/internal/curl/ccurl/ccurl.ha @@ -1,6 +1,8 @@ use types::c; +export type CURLM = opaque; export type CURL = opaque; +export type CURLMcode = int; export type CURLcode = int; export type CURLINFO = int; @@ -11,6 +13,10 @@ export def CURLOPT_WRITEDATA = 10001; export def CURLINFO_LONG = 0x200000; export def CURLINFO_RESPONSE_CODE = CURLINFO_LONG + 2; +export @symbol("curl_multi_init") fn curl_multi_init() nullable *CURLM; +export @symbol("curl_multi_cleanup") fn curl_multi_cleanup(handle: nullable *CURLM) CURLMcode; +export @symbol("curl_multi_add_handle") fn curl_multi_add_handle(multi_handle: nullable *CURLM, easy_handle: nullable *CURL) CURLMcode; +export @symbol("curl_multi_remove_handle") fn curl_multi_remove_handle(multi_handle: nullable *CURLM, easy_handle: nullable *CURL) CURLMcode; export @symbol("curl_easy_init") fn curl_easy_init() nullable *CURL; export @symbol("curl_easy_cleanup") fn curl_easy_cleanup(handle: nullable *CURL) void; @@ -39,6 +45,7 @@ export @symbol("curl_easy_setopt") fn curl_easy_setopt_writedata( // parameter: (const *c::char | nullable opaque) //) CURLcode; +export @symbol("curl_multi_perform") fn curl_multi_perform(multi_handle: nullable *CURLM, running_handles: *int) CURLMcode; export @symbol("curl_easy_perform") fn curl_easy_perform(easy_handle: nullable *CURL) CURLcode; export @symbol("curl_easy_getinfo") fn curl_easy_getinfo( easy_handle: nullable *CURL, 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); +}; |
