2006-10-25 05:20:44 -04:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2002-12-13 08:40:25 -05:00
|
|
|
#include "test.h"
|
|
|
|
|
2006-10-25 01:59:46 -04:00
|
|
|
#include "timeval.h"
|
|
|
|
|
|
|
|
#define MULTI_PERFORM_HANG_TIMEOUT 30 * 1000
|
|
|
|
|
2002-12-13 08:40:25 -05:00
|
|
|
/*
|
|
|
|
* Get a single URL without select().
|
|
|
|
*/
|
|
|
|
|
2004-02-05 07:34:17 -05:00
|
|
|
int test(char *URL)
|
2002-12-13 08:40:25 -05:00
|
|
|
{
|
|
|
|
CURL *c;
|
|
|
|
CURLM *m;
|
2006-10-25 01:59:46 -04:00
|
|
|
int res = 0;
|
2002-12-13 08:40:25 -05:00
|
|
|
int running=1;
|
2006-10-25 01:59:46 -04:00
|
|
|
struct timeval mp_start;
|
|
|
|
char mp_timedout = FALSE;
|
|
|
|
|
|
|
|
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((c = curl_easy_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_easy_init() failed\n");
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
2002-12-13 08:40:25 -05:00
|
|
|
|
|
|
|
curl_easy_setopt(c, CURLOPT_URL, URL);
|
|
|
|
|
2006-10-25 01:59:46 -04:00
|
|
|
if ((m = curl_multi_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_multi_init() failed\n");
|
|
|
|
curl_easy_cleanup(c);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
|
|
|
|
fprintf(stderr, "curl_multi_add_handle() failed, "
|
|
|
|
"with code %d\n", res);
|
|
|
|
curl_multi_cleanup(m);
|
|
|
|
curl_easy_cleanup(c);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_timedout = FALSE;
|
|
|
|
mp_start = curlx_tvnow();
|
|
|
|
|
2002-12-13 08:40:25 -05:00
|
|
|
while (running) {
|
2006-10-25 01:59:46 -04:00
|
|
|
res = (int)curl_multi_perform(m, &running);
|
|
|
|
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
|
|
|
|
MULTI_PERFORM_HANG_TIMEOUT) {
|
|
|
|
mp_timedout = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-12-13 08:40:25 -05:00
|
|
|
if (running <= 0) {
|
|
|
|
fprintf(stderr, "nothing left running.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-25 01:59:46 -04:00
|
|
|
|
|
|
|
if (mp_timedout) {
|
|
|
|
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
|
|
|
|
fprintf(stderr, "ABORTING TEST, since it seems "
|
|
|
|
"that it would have run forever.\n");
|
|
|
|
res = TEST_ERR_RUNS_FOREVER;
|
|
|
|
}
|
|
|
|
|
2002-12-13 08:40:25 -05:00
|
|
|
curl_multi_remove_handle(m, c);
|
|
|
|
curl_easy_cleanup(c);
|
|
|
|
curl_multi_cleanup(m);
|
2006-10-25 01:59:46 -04:00
|
|
|
curl_global_cleanup();
|
2002-12-13 08:40:25 -05:00
|
|
|
|
2004-02-09 03:28:00 -05:00
|
|
|
return res;
|
2002-12-13 08:40:25 -05:00
|
|
|
}
|
|
|
|
|