1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib530.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
13 #ifdef HAVE_SYS_TYPES_H
14 #include <sys/types.h>
16 #ifdef HAVE_SYS_STAT_H
25 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
26 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
33 CURL
*curl
[NUM_HANDLES
];
38 struct timeval ml_start
;
39 struct timeval mp_start
;
40 char ml_timedout
= FALSE
;
41 char mp_timedout
= FALSE
;
44 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
45 fprintf(stderr
, "curl_global_init() failed\n");
46 return TEST_ERR_MAJOR_BAD
;
49 if ((m
= curl_multi_init()) == NULL
) {
50 fprintf(stderr
, "curl_multi_init() failed\n");
51 curl_global_cleanup();
52 return TEST_ERR_MAJOR_BAD
;
55 /* get NUM_HANDLES easy handles */
56 for(i
=0; i
< NUM_HANDLES
; i
++) {
57 curl
[i
] = curl_easy_init();
59 fprintf(stderr
, "curl_easy_init() failed "
60 "on handle #%d\n", i
);
61 for (j
=i
-1; j
>= 0; j
--) {
62 curl_multi_remove_handle(m
, curl
[j
]);
63 curl_easy_cleanup(curl
[j
]);
65 curl_multi_cleanup(m
);
66 curl_global_cleanup();
67 return TEST_ERR_MAJOR_BAD
+ i
;
69 sprintf(target_url
, "%s%04i", URL
, i
+ 1);
70 target_url
[sizeof(target_url
) - 1] = '\0';
71 curl_easy_setopt(curl
[i
], CURLOPT_URL
, target_url
);
74 curl_easy_setopt(curl
[i
], CURLOPT_VERBOSE
, 1L);
77 curl_easy_setopt(curl
[i
], CURLOPT_HEADER
, 1L);
79 /* add handle to multi */
80 if ((res
= (int)curl_multi_add_handle(m
, curl
[i
])) != CURLM_OK
) {
81 fprintf(stderr
, "curl_multi_add_handle() failed, "
82 "on handle #%d with code %d\n", i
, res
);
83 curl_easy_cleanup(curl
[i
]);
84 for (j
=i
-1; j
>= 0; j
--) {
85 curl_multi_remove_handle(m
, curl
[j
]);
86 curl_easy_cleanup(curl
[j
]);
88 curl_multi_cleanup(m
);
89 curl_global_cleanup();
90 return TEST_ERR_MAJOR_BAD
+ i
;
94 curl_multi_setopt(m
, CURLMOPT_PIPELINING
, 1L);
97 ml_start
= tutil_tvnow();
99 fprintf(stderr
, "Start at URL 0\n");
104 struct timeval interval
;
107 interval
.tv_usec
= 0;
109 if (tutil_tvdiff(tutil_tvnow(), ml_start
) >
110 MAIN_LOOP_HANG_TIMEOUT
) {
115 mp_start
= tutil_tvnow();
117 while (res
== CURLM_CALL_MULTI_PERFORM
) {
118 res
= (int)curl_multi_perform(m
, &running
);
119 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
120 MULTI_PERFORM_HANG_TIMEOUT
) {
125 done
= TRUE
; /* bail out */
129 if (mp_timedout
|| done
)
132 if (res
!= CURLM_OK
) {
133 fprintf(stderr
, "not okay???\n");
142 if (curl_multi_fdset(m
, &rd
, &wr
, &exc
, &max_fd
) != CURLM_OK
) {
143 fprintf(stderr
, "unexpected failured of fdset.\n");
148 if (select_test(max_fd
+1, &rd
, &wr
, &exc
, &interval
) == -1) {
149 fprintf(stderr
, "bad select??\n");
154 res
= CURLM_CALL_MULTI_PERFORM
;
157 if (ml_timedout
|| mp_timedout
) {
158 if (ml_timedout
) fprintf(stderr
, "ml_timedout\n");
159 if (mp_timedout
) fprintf(stderr
, "mp_timedout\n");
160 fprintf(stderr
, "ABORTING TEST, since it seems "
161 "that it would have run forever.\n");
162 res
= TEST_ERR_RUNS_FOREVER
;
165 /* cleanup NUM_HANDLES easy handles */
166 for(i
=0; i
< NUM_HANDLES
; i
++) {
167 curl_multi_remove_handle(m
, curl
[i
]);
168 curl_easy_cleanup(curl
[i
]);
171 curl_multi_cleanup(m
);
172 curl_global_cleanup();