2006-10-09 17:29:53 -04:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2007-02-08 20:11:14 -05:00
|
|
|
#include "testutil.h"
|
2006-10-20 11:39:54 -04:00
|
|
|
|
2007-03-09 19:19:05 -05:00
|
|
|
#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
|
|
|
|
#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
|
2006-10-20 11:39:54 -04:00
|
|
|
|
2006-10-09 17:29:53 -04:00
|
|
|
static CURLMcode perform(CURLM * multi)
|
|
|
|
{
|
2006-10-19 18:49:33 -04:00
|
|
|
int handles, maxfd;
|
|
|
|
CURLMcode code;
|
|
|
|
fd_set fdread, fdwrite, fdexcep;
|
2006-10-20 11:39:54 -04:00
|
|
|
struct timeval mp_start;
|
|
|
|
char mp_timedout = FALSE;
|
2006-10-19 18:49:33 -04:00
|
|
|
|
2006-10-20 11:39:54 -04:00
|
|
|
mp_timedout = FALSE;
|
2007-02-08 20:11:14 -05:00
|
|
|
mp_start = tutil_tvnow();
|
2006-10-20 11:39:54 -04:00
|
|
|
|
|
|
|
for (;;) {
|
2006-10-19 18:49:33 -04:00
|
|
|
code = curl_multi_perform(multi, &handles);
|
2007-02-08 20:11:14 -05:00
|
|
|
if (tutil_tvdiff(tutil_tvnow(), mp_start) >
|
2006-10-20 11:39:54 -04:00
|
|
|
MULTI_PERFORM_HANG_TIMEOUT) {
|
|
|
|
mp_timedout = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-19 18:49:33 -04:00
|
|
|
if (handles <= 0)
|
|
|
|
return CURLM_OK;
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case CURLM_OK:
|
|
|
|
break;
|
|
|
|
case CURLM_CALL_MULTI_PERFORM:
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
FD_ZERO(&fdread);
|
|
|
|
FD_ZERO(&fdwrite);
|
|
|
|
FD_ZERO(&fdexcep);
|
|
|
|
curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
|
|
|
|
if (maxfd < 0)
|
|
|
|
return (CURLMcode) ~CURLM_OK;
|
|
|
|
if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, 0) == -1)
|
|
|
|
return (CURLMcode) ~CURLM_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-20 11:39:54 -04:00
|
|
|
/* We only reach this point if (mp_timedout) */
|
2006-10-21 06:54:41 -04:00
|
|
|
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
|
2006-10-19 18:49:33 -04:00
|
|
|
fprintf(stderr, "ABORTING TEST, since it seems "
|
|
|
|
"that it would have run forever.\n");
|
|
|
|
return (CURLMcode) ~CURLM_OK;
|
2006-10-09 17:29:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2006-10-25 01:59:46 -04:00
|
|
|
CURLM *multi;
|
|
|
|
CURL *easy;
|
2007-05-02 02:02:13 -04:00
|
|
|
int res = 0;
|
2006-10-25 01:59:46 -04:00
|
|
|
|
|
|
|
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
|
|
|
fprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((multi = curl_multi_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_multi_init() failed\n");
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((easy = curl_easy_init()) == NULL) {
|
|
|
|
fprintf(stderr, "curl_easy_init() failed\n");
|
|
|
|
curl_multi_cleanup(multi);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return TEST_ERR_MAJOR_BAD;
|
|
|
|
}
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2008-05-22 17:49:52 -04:00
|
|
|
curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
|
2008-05-22 17:49:52 -04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_URL, URL);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
|
|
|
|
printf("curl_multi_add_handle() failed\n");
|
|
|
|
res = TEST_ERR_MAJOR_BAD;
|
|
|
|
} else {
|
|
|
|
if (perform(multi) != CURLM_OK)
|
|
|
|
printf("retrieve 1 failed\n");
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
}
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_reset(easy);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2008-05-22 17:49:52 -04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
|
2007-10-02 12:05:28 -04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_URL, libtest_arg2);
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
|
|
|
|
printf("curl_multi_add_handle() 2 failed\n");
|
|
|
|
res = TEST_ERR_MAJOR_BAD;
|
|
|
|
} else {
|
|
|
|
if (perform(multi) != CURLM_OK)
|
|
|
|
printf("retrieve 2 failed\n");
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
}
|
2006-10-19 18:49:33 -04:00
|
|
|
curl_easy_cleanup(easy);
|
|
|
|
curl_multi_cleanup(multi);
|
2006-10-25 01:59:46 -04:00
|
|
|
curl_global_cleanup();
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2006-10-19 18:49:33 -04:00
|
|
|
printf("Finished!\n");
|
2006-10-09 17:29:53 -04:00
|
|
|
|
2007-05-02 02:02:13 -04:00
|
|
|
return res;
|
2006-10-09 17:29:53 -04:00
|
|
|
}
|