Created
May 28, 2019 12:27
-
-
Save TvdW/f4815f8080d9dc30daa5d74b1f878dae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "curl/curl.h" | |
int main(int argc, char** argv) | |
{ | |
CURLM *multi = curl_multi_init(); | |
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); | |
curl_multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, 4); | |
int j, all_done = 0; | |
for (j = 0; j < 100 && !all_done; j++) { | |
int i; | |
CURL *easies[10]; | |
for (i = 0; i < 10; i++) { | |
CURL *easy = curl_easy_init(); | |
easies[i] = easy; | |
if (i % 2 == 0) { | |
curl_easy_setopt(easy, CURLOPT_URL, "http://127.0.0.1:81"); | |
curl_easy_setopt(easy, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE); | |
} else { | |
curl_easy_setopt(easy, CURLOPT_URL, "http://127.0.0.1:80"); | |
} | |
curl_easy_setopt(easy, CURLOPT_VERBOSE, 1); | |
curl_easy_setopt(easy, CURLOPT_TIMEOUT_MS, 1000); | |
curl_multi_add_handle(multi, easy); | |
} | |
int running= 1; | |
while (running) { | |
int numfds; | |
curl_multi_perform(multi, &running); | |
curl_multi_wait(multi, NULL, 0, 1000, &numfds); | |
} | |
for (i = 0; i < 10; i++) { | |
long code; | |
curl_easy_getinfo(easies[i], CURLINFO_RESPONSE_CODE, &code); | |
if (code < 100) { | |
all_done = 1; | |
} | |
curl_multi_remove_handle(multi, easies[i]); | |
curl_easy_cleanup(easies[i]); | |
} | |
} | |
curl_multi_cleanup(multi); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment