1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib504.c,v 1.27 2008-05-22 21:49:52 danf Exp $
13 #include <sys/types.h>
17 #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
18 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
21 * Source code in here hugely as reported in bug report 651464 by
22 * Christopher R. Palmer.
24 * Use multi interface to get document over proxy with bad port number.
25 * This caused the interface to "hang" in libcurl 7.10.2.
38 struct timeval ml_start
;
39 struct timeval mp_start
;
40 char ml_timedout
= FALSE
;
41 char mp_timedout
= FALSE
;
43 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
44 fprintf(stderr
, "curl_global_init() failed\n");
45 return TEST_ERR_MAJOR_BAD
;
48 if ((c
= curl_easy_init()) == NULL
) {
49 fprintf(stderr
, "curl_easy_init() failed\n");
50 curl_global_cleanup();
51 return TEST_ERR_MAJOR_BAD
;
54 /* the point here being that there must not run anything on the given
56 curl_easy_setopt(c
, CURLOPT_PROXY
, libtest_arg2
);
57 curl_easy_setopt(c
, CURLOPT_URL
, URL
);
58 curl_easy_setopt(c
, CURLOPT_VERBOSE
, 1L);
60 if ((m
= curl_multi_init()) == NULL
) {
61 fprintf(stderr
, "curl_multi_init() failed\n");
63 curl_global_cleanup();
64 return TEST_ERR_MAJOR_BAD
;
67 if ((res
= curl_multi_add_handle(m
, c
)) != CURLM_OK
) {
68 fprintf(stderr
, "curl_multi_add_handle() failed, "
69 "with code %d\n", res
);
70 curl_multi_cleanup(m
);
72 curl_global_cleanup();
73 return TEST_ERR_MAJOR_BAD
;
77 ml_start
= tutil_tvnow();
80 struct timeval interval
;
85 if (tutil_tvdiff(tutil_tvnow(), ml_start
) >
86 MAIN_LOOP_HANG_TIMEOUT
) {
91 mp_start
= tutil_tvnow();
93 fprintf(stderr
, "curl_multi_perform()\n");
95 res
= CURLM_CALL_MULTI_PERFORM
;
97 while (res
== CURLM_CALL_MULTI_PERFORM
) {
98 res
= curl_multi_perform(m
, &running
);
99 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
100 MULTI_PERFORM_HANG_TIMEOUT
) {
109 /* This is where this code is expected to reach */
111 CURLMsg
*msg
= curl_multi_info_read(m
, &numleft
);
112 fprintf(stderr
, "Expected: not running\n");
114 ret
= 100; /* this is where we should be */
116 ret
= 99; /* not correct */
119 fprintf(stderr
, "running == %d, res == %d\n", running
, res
);
121 if (res
!= CURLM_OK
) {
131 fprintf(stderr
, "curl_multi_fdset()\n");
132 if (curl_multi_fdset(m
, &rd
, &wr
, &exc
, &max_fd
) != CURLM_OK
) {
133 fprintf(stderr
, "unexpected failured of fdset.\n");
137 rc
= select_test(max_fd
+1, &rd
, &wr
, &exc
, &interval
);
138 fprintf(stderr
, "select returned %d\n", rc
);
141 if (ml_timedout
|| mp_timedout
) {
142 if (ml_timedout
) fprintf(stderr
, "ml_timedout\n");
143 if (mp_timedout
) fprintf(stderr
, "mp_timedout\n");
144 fprintf(stderr
, "ABORTING TEST, since it seems "
145 "that it would have run forever.\n");
146 ret
= TEST_ERR_RUNS_FOREVER
;
149 curl_multi_remove_handle(m
, c
);
150 curl_easy_cleanup(c
);
151 curl_multi_cleanup(m
);
152 curl_global_cleanup();