#include "test.h"
int test(char *URL)
{
CURL *http_handle;
CURLM *multi_handle;
CURLMcode code;
int still_running;
http_handle = curl_easy_init();
if (!http_handle)
return TEST_ERR_MAJOR_BAD;
curl_easy_setopt(http_handle, CURLOPT_URL, URL);
curl_easy_setopt(http_handle, CURLOPT_HEADER, 1L);
curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
multi_handle = curl_multi_init();
if (!multi_handle) {
curl_easy_cleanup(http_handle);
return TEST_ERR_MAJOR_BAD;
}
curl_multi_add_handle(multi_handle, http_handle);
do {
code = curl_multi_perform(multi_handle, &still_running);
} while(code == CURLM_CALL_MULTI_PERFORM);
while(still_running) {
struct timeval timeout;
int rc;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc) {
case -1:
break;
case 0:
default:
do {
code = curl_multi_perform(multi_handle, &still_running);
} while(code == CURLM_CALL_MULTI_PERFORM);
break;
}
}
curl_multi_cleanup(multi_handle);
curl_easy_cleanup(http_handle);
return 0;
}