1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib502.c,v 1.7 2007-03-10 00:19:05 yangtse Exp $
15 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
16 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
19 * Get a single URL without select().
28 struct timeval mp_start
;
29 char mp_timedout
= FALSE
;
31 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
32 fprintf(stderr
, "curl_global_init() failed\n");
33 return TEST_ERR_MAJOR_BAD
;
36 if ((c
= curl_easy_init()) == NULL
) {
37 fprintf(stderr
, "curl_easy_init() failed\n");
38 curl_global_cleanup();
39 return TEST_ERR_MAJOR_BAD
;
42 curl_easy_setopt(c
, CURLOPT_URL
, URL
);
44 if ((m
= curl_multi_init()) == NULL
) {
45 fprintf(stderr
, "curl_multi_init() failed\n");
47 curl_global_cleanup();
48 return TEST_ERR_MAJOR_BAD
;
51 if ((res
= (int)curl_multi_add_handle(m
, c
)) != CURLM_OK
) {
52 fprintf(stderr
, "curl_multi_add_handle() failed, "
53 "with code %d\n", res
);
54 curl_multi_cleanup(m
);
56 curl_global_cleanup();
57 return TEST_ERR_MAJOR_BAD
;
61 mp_start
= tutil_tvnow();
64 res
= (int)curl_multi_perform(m
, &running
);
65 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
66 MULTI_PERFORM_HANG_TIMEOUT
) {
71 fprintf(stderr
, "nothing left running.\n");
77 if (mp_timedout
) fprintf(stderr
, "mp_timedout\n");
78 fprintf(stderr
, "ABORTING TEST, since it seems "
79 "that it would have run forever.\n");
80 res
= TEST_ERR_RUNS_FOREVER
;
83 curl_multi_remove_handle(m
, c
);
85 curl_multi_cleanup(m
);
86 curl_global_cleanup();