1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib533.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
11 /* used for test case 533, 534 and 535 */
15 #include <sys/types.h>
21 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
22 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
32 struct timeval ml_start
;
33 struct timeval mp_start
;
34 char ml_timedout
= FALSE
;
35 char mp_timedout
= FALSE
;
37 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
38 fprintf(stderr
, "curl_global_init() failed\n");
39 return TEST_ERR_MAJOR_BAD
;
42 if ((curl
= curl_easy_init()) == NULL
) {
43 fprintf(stderr
, "curl_easy_init() failed\n");
44 curl_global_cleanup();
45 return TEST_ERR_MAJOR_BAD
;
48 curl_easy_setopt(curl
, CURLOPT_URL
, URL
);
49 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1);
50 curl_easy_setopt(curl
, CURLOPT_FAILONERROR
, 1);
52 if ((m
= curl_multi_init()) == NULL
) {
53 fprintf(stderr
, "curl_multi_init() failed\n");
54 curl_easy_cleanup(curl
);
55 curl_global_cleanup();
56 return TEST_ERR_MAJOR_BAD
;
59 if ((res
= (int)curl_multi_add_handle(m
, curl
)) != CURLM_OK
) {
60 fprintf(stderr
, "curl_multi_add_handle() failed, "
61 "with code %d\n", res
);
62 curl_multi_cleanup(m
);
63 curl_easy_cleanup(curl
);
64 curl_global_cleanup();
65 return TEST_ERR_MAJOR_BAD
;
69 ml_start
= tutil_tvnow();
71 fprintf(stderr
, "Start at URL 0\n");
76 struct timeval interval
;
81 if (tutil_tvdiff(tutil_tvnow(), ml_start
) >
82 MAIN_LOOP_HANG_TIMEOUT
) {
87 mp_start
= tutil_tvnow();
89 while (res
== CURLM_CALL_MULTI_PERFORM
) {
90 res
= (int)curl_multi_perform(m
, &running
);
91 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
92 MULTI_PERFORM_HANG_TIMEOUT
) {
98 fprintf(stderr
, "Advancing to URL 1\n");
99 /* remove the handle we use */
100 curl_multi_remove_handle(m
, curl
);
102 /* make us re-use the same handle all the time, and try resetting
103 the handle first too */
104 curl_easy_reset(curl
);
105 curl_easy_setopt(curl
, CURLOPT_URL
, libtest_arg2
);
106 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1);
107 curl_easy_setopt(curl
, CURLOPT_FAILONERROR
, 1);
110 res
= (int)curl_multi_add_handle(m
, curl
);
112 fprintf(stderr
, "add handle failed: %d.\n", res
);
118 done
= TRUE
; /* bail out */
122 if (mp_timedout
|| done
)
125 if (res
!= CURLM_OK
) {
126 fprintf(stderr
, "not okay???\n");
135 if (curl_multi_fdset(m
, &rd
, &wr
, &exc
, &max_fd
) != CURLM_OK
) {
136 fprintf(stderr
, "unexpected failured of fdset.\n");
141 if (select_test(max_fd
+1, &rd
, &wr
, &exc
, &interval
) == -1) {
142 fprintf(stderr
, "bad select??\n");
147 res
= CURLM_CALL_MULTI_PERFORM
;
150 if (ml_timedout
|| mp_timedout
) {
151 if (ml_timedout
) fprintf(stderr
, "ml_timedout\n");
152 if (mp_timedout
) fprintf(stderr
, "mp_timedout\n");
153 fprintf(stderr
, "ABORTING TEST, since it seems "
154 "that it would have run forever.\n");
155 res
= TEST_ERR_RUNS_FOREVER
;
158 curl_easy_cleanup(curl
);
159 curl_multi_cleanup(m
);
160 curl_global_cleanup();