1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
12 #include <sys/types.h>
17 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
18 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
21 * Source code in here hugely as reported in bug report 651460 by
22 * Christopher R. Palmer.
24 * Use multi interface to get HTTPS document over proxy, and provide
35 struct timeval ml_start;
36 struct timeval mp_start;
37 char ml_timedout = FALSE;
38 char mp_timedout = FALSE;
40 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
41 fprintf(stderr, "curl_global_init() failed\n");
42 return TEST_ERR_MAJOR_BAD;
45 if ((c = curl_easy_init()) == NULL) {
46 fprintf(stderr, "curl_easy_init() failed\n");
47 curl_global_cleanup();
48 return TEST_ERR_MAJOR_BAD;
51 test_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
52 test_setopt(c, CURLOPT_URL, URL);
53 test_setopt(c, CURLOPT_USERPWD, "test:ing");
54 test_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
55 test_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
56 test_setopt(c, CURLOPT_HEADER, 1L);
58 if ((m = curl_multi_init()) == NULL) {
59 fprintf(stderr, "curl_multi_init() failed\n");
61 curl_global_cleanup();
62 return TEST_ERR_MAJOR_BAD;
65 if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
66 fprintf(stderr, "curl_multi_add_handle() failed, "
67 "with code %d\n", res);
68 curl_multi_cleanup(m);
70 curl_global_cleanup();
71 return TEST_ERR_MAJOR_BAD;
75 ml_start = tutil_tvnow();
80 struct timeval interval;
85 if (tutil_tvdiff(tutil_tvnow(), ml_start) >
86 MAIN_LOOP_HANG_TIMEOUT) {
91 mp_start = tutil_tvnow();
93 while (res == CURLM_CALL_MULTI_PERFORM) {
94 res = (int)curl_multi_perform(m, &running);
95 if (tutil_tvdiff(tutil_tvnow(), mp_start) >
96 MULTI_PERFORM_HANG_TIMEOUT) {
105 if (mp_timedout || done)
108 if (res != CURLM_OK) {
109 fprintf(stderr, "not okay???\n");
118 if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
119 fprintf(stderr, "unexpected failured of fdset.\n");
124 if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
125 fprintf(stderr, "bad select??\n");
130 res = CURLM_CALL_MULTI_PERFORM;
133 if (ml_timedout || mp_timedout) {
134 if (ml_timedout) fprintf(stderr, "ml_timedout\n");
135 if (mp_timedout) fprintf(stderr, "mp_timedout\n");
136 fprintf(stderr, "ABORTING TEST, since it seems "
137 "that it would have run forever.\n");
138 res = TEST_ERR_RUNS_FOREVER;
144 curl_multi_remove_handle(m, c);
145 curl_multi_cleanup(m);
147 curl_easy_cleanup(c);
148 curl_global_cleanup();