Initial commit of visual studio 9 git build superproject.
[git-build-vc9.git] / curl / tests / libtest / lib504.c
blobc2cf038a26df24da94c3a150ee41b6edc611cc44
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib504.c,v 1.27 2008-05-22 21:49:52 danf Exp $
9 */
11 #include "test.h"
13 #include <sys/types.h>
15 #include "testutil.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.
27 int test(char *URL)
29 CURL *c;
30 int ret=0;
31 CURLM *m;
32 fd_set rd, wr, exc;
33 CURLMcode res;
34 char done = FALSE;
35 int running;
36 int max_fd;
37 int rc;
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
55 proxy port */
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");
62 curl_easy_cleanup(c);
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);
71 curl_easy_cleanup(c);
72 curl_global_cleanup();
73 return TEST_ERR_MAJOR_BAD;
76 ml_timedout = FALSE;
77 ml_start = tutil_tvnow();
79 while (!done) {
80 struct timeval interval;
82 interval.tv_sec = 1;
83 interval.tv_usec = 0;
85 if (tutil_tvdiff(tutil_tvnow(), ml_start) >
86 MAIN_LOOP_HANG_TIMEOUT) {
87 ml_timedout = TRUE;
88 break;
90 mp_timedout = FALSE;
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) {
101 mp_timedout = TRUE;
102 break;
105 if (mp_timedout)
106 break;
108 if(!running) {
109 /* This is where this code is expected to reach */
110 int numleft;
111 CURLMsg *msg = curl_multi_info_read(m, &numleft);
112 fprintf(stderr, "Expected: not running\n");
113 if(msg && !numleft)
114 ret = 100; /* this is where we should be */
115 else
116 ret = 99; /* not correct */
117 break;
119 fprintf(stderr, "running == %d, res == %d\n", running, res);
121 if (res != CURLM_OK) {
122 ret = 2;
123 break;
126 FD_ZERO(&rd);
127 FD_ZERO(&wr);
128 FD_ZERO(&exc);
129 max_fd = 0;
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");
134 ret = 3;
135 break;
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();
154 return ret;