2006-10-25 11:20:44 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2002-12-13 14:40:25 +01:00
|
|
|
#include "test.h"
|
|
|
|
|
2007-02-09 02:11:14 +01:00
|
|
|
#include "testutil.h"
|
2008-09-20 06:26:55 +02:00
|
|
|
#include "memdebug.h"
|
2006-10-25 07:59:46 +02:00
|
|
|
|
2007-03-10 01:19:05 +01:00
|
|
|
#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
|
|
|
|
#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
|
2006-10-25 07:59:46 +02:00
|
|
|
|
2002-12-13 14:40:25 +01:00
|
|
|
/*
|
|
|
|
* Get a single URL without select().
|
|
|
|
*/
|
|
|
|
|
2004-02-05 13:34:17 +01:00
|
|
|
int test(char *URL)
|
2002-12-13 14:40:25 +01:00
|
|
|
{
|
|
|
|
CURL *c;
|
|
|
|
CURLM *m;
|
2006-10-25 07:59:46 +02:00
|
|
|
int res = 0;
|
2002-12-13 14:40:25 +01:00
|
|
|
int running=1;
|
2006-10-25 07:59:46 +02: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 14:40:25 +01:00
|
|
|
|
|
|
|
curl_easy_setopt(c, CURLOPT_URL, URL);
|
|
|
|
|
2006-10-25 07:59:46 +02: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;
|
2007-02-09 02:11:14 +01:00
|
|
|
mp_start = tutil_tvnow();
|
2006-10-25 07:59:46 +02:00
|
|
|
|
2002-12-13 14:40:25 +01:00
|
|
|
while (running) {
|
2006-10-25 07:59:46 +02:00
|
|
|
res = (int)curl_multi_perform(m, &running);
|
2007-02-09 02:11:14 +01:00
|
|
|
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
|
2006-10-25 07:59:46 +02:00
|
|
|
MULTI_PERFORM_HANG_TIMEOUT) {
|
|
|
|
mp_timedout = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-12-13 14:40:25 +01:00
|
|
|
if (running <= 0) {
|
|
|
|
fprintf(stderr, "nothing left running.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-10-25 07:59:46 +02: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 14:40:25 +01:00
|
|
|
curl_multi_remove_handle(m, c);
|
|
|
|
curl_easy_cleanup(c);
|
|
|
|
curl_multi_cleanup(m);
|
2006-10-25 07:59:46 +02:00
|
|
|
curl_global_cleanup();
|
2002-12-13 14:40:25 +01:00
|
|
|
|
2004-02-09 09:28:00 +01:00
|
|
|
return res;
|
2002-12-13 14:40:25 +01:00
|
|
|
}
|
|
|
|
|