Skip to content

Instantly share code, notes, and snippets.

@falconindy
Created November 27, 2014 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falconindy/9e5c5de3f0a4e9a871a3 to your computer and use it in GitHub Desktop.
Save falconindy/9e5c5de3f0a4e9a871a3 to your computer and use it in GitHub Desktop.
Example to show resolver behavior
#include <curl/curl.h>
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
size_t discard_writes(void *p, size_t n, size_t s, void *u) {
(void) p; (void) u;
return s * n;
}
int main(void) {
const char *urls[] = {
"http://www.google.com/",
"http://www.google.com/",
"http://www.google.com/",
"http://www.google.com/",
};
CURLM *curlm;
CURL *curle[ARRAYSIZE(urls)];
int active;
curl_global_init(CURL_GLOBAL_ALL);
curlm = curl_multi_init();
for (size_t i = 0; i < ARRAYSIZE(urls); ++i) {
curle[i] = curl_easy_init();
curl_easy_setopt(curle[i], CURLOPT_URL, urls[i]);
curl_easy_setopt(curle[i], CURLOPT_WRITEFUNCTION, discard_writes);
curl_multi_add_handle(curlm, curle[i]);
}
do {
int n;
curl_multi_perform(curlm, &active);
curl_multi_wait(curlm, NULL, 0, 1000, &n);
while (curl_multi_info_read(curlm, &n));
} while (active > 0);
for (size_t i = 0; i < ARRAYSIZE(urls); ++i) {
curl_multi_remove_handle(curlm, curle[i]);
curl_easy_cleanup(curle[i]);
}
curl_multi_cleanup(curlm);
curl_global_cleanup();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment