
curl_multi_add_handle 함수는 하나의 멀티 스레드 요청에 대해 여러 개의 요청을 추가하는 함수입니다.
다음과 같이 여러 개의 요청을 동시에 처리할 수 있습니다.
#hostingforum.kr
c
curl_global_init(CURL_GLOBAL_DEFAULT);
curl_global_init(CURL_GLOBAL_NOTHING);
curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/1");
curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/2");
curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/3");
curl_multi_add_handle(mh, curl);
curl_multi_add_handle(mh, curl2);
curl_multi_add_handle(mh, curl3);
while ((rc = curl_multi_perform(mh, &active)); active > 0 || (res = curl_multi_info_read(mh, &status)) != CURLM_OK) {
if (res == CURLM_CALL_BACK) {
// 동작 중인 요청의 수
printf("동작 중인 요청의 수: %d", curl_multi_getactive(mh))
break;
}
if (res == CURLM_OK) {
if (status.curl == NULL) {
if (status.command == CURLM_OUTGOING.
printf("요청이 완료되었습니다. code: %d", status.data)
} else {
printf("요청이 실패했습니다. code: %d", status.data)
}
}
}
if (res == CURLM_OK) {
if (status.curl == NULL) {
if (status.code == CURLE_OK) {
printf("요청이 완료되었습니다. code: %d", status.data)
} else {
printf("요청이 실패했습니다. code: %d", status.data)
}
} else {
printf("요청이 완료되었습니다. code: %d", status.data)
}
}
}
2025-04-21 07:42