1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib536.c,v 1.13 2008-05-22 21:49:53 danf Exp $
13 #include <sys/types.h>
19 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
20 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
22 static CURLMcode
perform(CURLM
* multi
)
26 fd_set fdread
, fdwrite
, fdexcep
;
27 struct timeval mp_start
;
28 char mp_timedout
= FALSE
;
31 mp_start
= tutil_tvnow();
34 code
= curl_multi_perform(multi
, &handles
);
35 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
36 MULTI_PERFORM_HANG_TIMEOUT
) {
46 case CURLM_CALL_MULTI_PERFORM
:
55 curl_multi_fdset(multi
, &fdread
, &fdwrite
, &fdexcep
, &maxfd
);
57 return (CURLMcode
) ~CURLM_OK
;
58 if (select(maxfd
+ 1, &fdread
, &fdwrite
, &fdexcep
, 0) == -1)
59 return (CURLMcode
) ~CURLM_OK
;
62 /* We only reach this point if (mp_timedout) */
63 if (mp_timedout
) fprintf(stderr
, "mp_timedout\n");
64 fprintf(stderr
, "ABORTING TEST, since it seems "
65 "that it would have run forever.\n");
66 return (CURLMcode
) ~CURLM_OK
;
75 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
76 fprintf(stderr
, "curl_global_init() failed\n");
77 return TEST_ERR_MAJOR_BAD
;
80 if ((multi
= curl_multi_init()) == NULL
) {
81 fprintf(stderr
, "curl_multi_init() failed\n");
82 curl_global_cleanup();
83 return TEST_ERR_MAJOR_BAD
;
86 if ((easy
= curl_easy_init()) == NULL
) {
87 fprintf(stderr
, "curl_easy_init() failed\n");
88 curl_multi_cleanup(multi
);
89 curl_global_cleanup();
90 return TEST_ERR_MAJOR_BAD
;
93 curl_multi_setopt(multi
, CURLMOPT_PIPELINING
, 1L);
95 curl_easy_setopt(easy
, CURLOPT_WRITEFUNCTION
, fwrite
);
96 curl_easy_setopt(easy
, CURLOPT_FAILONERROR
, 1L);
97 curl_easy_setopt(easy
, CURLOPT_URL
, URL
);
99 if (curl_multi_add_handle(multi
, easy
) != CURLM_OK
) {
100 printf("curl_multi_add_handle() failed\n");
101 res
= TEST_ERR_MAJOR_BAD
;
103 if (perform(multi
) != CURLM_OK
)
104 printf("retrieve 1 failed\n");
106 curl_multi_remove_handle(multi
, easy
);
108 curl_easy_reset(easy
);
110 curl_easy_setopt(easy
, CURLOPT_FAILONERROR
, 1L);
111 curl_easy_setopt(easy
, CURLOPT_URL
, libtest_arg2
);
113 if (curl_multi_add_handle(multi
, easy
) != CURLM_OK
) {
114 printf("curl_multi_add_handle() 2 failed\n");
115 res
= TEST_ERR_MAJOR_BAD
;
117 if (perform(multi
) != CURLM_OK
)
118 printf("retrieve 2 failed\n");
120 curl_multi_remove_handle(multi
, easy
);
122 curl_easy_cleanup(easy
);
123 curl_multi_cleanup(multi
);
124 curl_global_cleanup();
126 printf("Finished!\n");