Initial commit of visual studio 9 git build superproject.
[git-build-vc9.git] / curl / tests / libtest / lib502.c
blobcaed96da9535e738d752ade3b39d6c369f86b720
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib502.c,v 1.7 2007-03-10 00:19:05 yangtse Exp $
9 */
11 #include "test.h"
13 #include "testutil.h"
15 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
16 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
19 * Get a single URL without select().
22 int test(char *URL)
24 CURL *c;
25 CURLM *m;
26 int res = 0;
27 int running=1;
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");
46 curl_easy_cleanup(c);
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);
55 curl_easy_cleanup(c);
56 curl_global_cleanup();
57 return TEST_ERR_MAJOR_BAD;
60 mp_timedout = FALSE;
61 mp_start = tutil_tvnow();
63 while (running) {
64 res = (int)curl_multi_perform(m, &running);
65 if (tutil_tvdiff(tutil_tvnow(), mp_start) >
66 MULTI_PERFORM_HANG_TIMEOUT) {
67 mp_timedout = TRUE;
68 break;
70 if (running <= 0) {
71 fprintf(stderr, "nothing left running.\n");
72 break;
76 if (mp_timedout) {
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);
84 curl_easy_cleanup(c);
85 curl_multi_cleanup(m);
86 curl_global_cleanup();
88 return res;