2006-10-10 01:29:53 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2006-10-20 19:39:54 +04:00
|
|
|
#include "timeval.h"
|
|
|
|
|
2006-10-20 19:45:12 +04:00
|
|
|
#define MAIN_LOOP_HANG_TIMEOUT 30 * 1000
|
|
|
|
#define MULTI_PERFORM_HANG_TIMEOUT 20 * 1000
|
2006-10-20 19:39:54 +04:00
|
|
|
|
2006-10-10 01:29:53 +04:00
|
|
|
static CURLMcode perform(CURLM * multi);
|
|
|
|
|
|
|
|
static CURLMcode perform(CURLM * multi)
|
|
|
|
{
|
2006-10-20 02:49:33 +04:00
|
|
|
int handles, maxfd;
|
|
|
|
CURLMcode code;
|
|
|
|
fd_set fdread, fdwrite, fdexcep;
|
2006-10-20 19:39:54 +04:00
|
|
|
struct timeval mp_start;
|
|
|
|
char mp_timedout = FALSE;
|
2006-10-20 02:49:33 +04:00
|
|
|
|
2006-10-20 19:39:54 +04:00
|
|
|
mp_timedout = FALSE;
|
|
|
|
mp_start = curlx_tvnow();
|
|
|
|
|
|
|
|
for (;;) {
|
2006-10-20 02:49:33 +04:00
|
|
|
code = curl_multi_perform(multi, &handles);
|
2006-10-20 19:39:54 +04:00
|
|
|
if (curlx_tvdiff(curlx_tvnow(), mp_start) >
|
|
|
|
MULTI_PERFORM_HANG_TIMEOUT) {
|
|
|
|
mp_timedout = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-20 02: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 19:39:54 +04:00
|
|
|
/* We only reach this point if (mp_timedout) */
|
2006-10-21 14:54:41 +04:00
|
|
|
if (mp_timedout) fprintf(stderr, "mp_timedout\n");
|
2006-10-20 02:49:33 +04:00
|
|
|
fprintf(stderr, "ABORTING TEST, since it seems "
|
|
|
|
"that it would have run forever.\n");
|
|
|
|
return (CURLMcode) ~CURLM_OK;
|
2006-10-10 01:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
2006-10-20 02:49:33 +04:00
|
|
|
CURLM *multi = curl_multi_init();
|
|
|
|
CURL *easy = curl_easy_init();
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1);
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
|
|
|
|
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1);
|
|
|
|
curl_easy_setopt(easy, CURLOPT_URL, URL);
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_multi_add_handle(multi, easy);
|
|
|
|
if (perform(multi) != CURLM_OK)
|
|
|
|
printf("retrieve 1 failed\n");
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
curl_easy_reset(easy);
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_easy_setopt(easy, CURLOPT_FAILONERROR, 1);
|
|
|
|
curl_easy_setopt(easy, CURLOPT_URL, arg2);
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_multi_add_handle(multi, easy);
|
|
|
|
if (perform(multi) != CURLM_OK)
|
|
|
|
printf("retrieve 2 failed\n");
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
curl_easy_cleanup(easy);
|
|
|
|
curl_multi_cleanup(multi);
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
printf("Finished!\n");
|
2006-10-10 01:29:53 +04:00
|
|
|
|
2006-10-20 02:49:33 +04:00
|
|
|
return 0;
|
2006-10-10 01:29:53 +04:00
|
|
|
}
|