1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 * This code sets up multiple easy handles that transfer a single file from
24 * the same URL, in a serial manner after each other. Due to the connection
25 * sharing within the multi handle all transfers are performed on the same
26 * persistent connection.
28 * This source code is used for lib526, lib527 and lib532 with only #ifdefs
29 * controlling the small differences.
31 * - lib526 closes all easy handles after
32 * they all have transfered the file over the single connection
33 * - lib527 closes each easy handle after each single transfer.
34 * - lib532 uses only a single easy handle that is removed, reset and then
35 * re-added for each transfer
37 * Test case 526, 527 and 532 use FTP, while test 528 uses the lib526 tool but
49 #define TEST_HANG_TIMEOUT 60 * 1000
56 CURL *curl[NUM_HANDLES];
62 for(i=0; i < NUM_HANDLES; i++)
67 global_init(CURL_GLOBAL_ALL);
69 /* get NUM_HANDLES easy handles */
70 for(i=0; i < NUM_HANDLES; i++) {
73 easy_setopt(curl[i], CURLOPT_URL, URL);
75 easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
80 multi_add_handle(m, curl[current]);
82 fprintf(stderr, "Start at URL 0\n");
85 struct timeval interval;
92 multi_perform(m, &running);
94 abort_on_test_timeout();
98 /* NOTE: this code does not remove the handle from the multi handle
99 here, which would be the nice, sane and documented way of working.
100 This however tests that the API survives this abuse gracefully. */
101 curl_easy_cleanup(curl[current]);
102 curl[current] = NULL;
104 if(++current < NUM_HANDLES) {
105 fprintf(stderr, "Advancing to URL %d\n", current);
107 /* first remove the only handle we use */
108 curl_multi_remove_handle(m, curl[0]);
110 /* make us re-use the same handle all the time, and try resetting
111 the handle first too */
112 curl_easy_reset(curl[0]);
113 easy_setopt(curl[0], CURLOPT_URL, URL);
115 easy_setopt(curl[0], CURLOPT_VERBOSE, 1L);
118 multi_add_handle(m, curl[0]);
120 multi_add_handle(m, curl[current]);
132 multi_fdset(m, &rd, &wr, &exc, &maxfd);
134 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
136 select_test(maxfd+1, &rd, &wr, &exc, &interval);
138 abort_on_test_timeout();
145 /* test 526 and 528 */
146 /* proper cleanup sequence - type PB */
148 for(i=0; i < NUM_HANDLES; i++) {
149 curl_multi_remove_handle(m, curl[i]);
150 curl_easy_cleanup(curl[i]);
152 curl_multi_cleanup(m);
153 curl_global_cleanup();
155 #elif defined(LIB527)
159 /* Upon non-failure test flow the easy's have already been cleanup'ed. In
160 case there is a failure we arrive here with easy's that have not been
161 cleanup'ed yet, in this case we have to cleanup them or otherwise these
162 will be leaked, let's use undocumented cleanup sequence - type UB */
165 for(i=0; i < NUM_HANDLES; i++)
166 curl_easy_cleanup(curl[i]);
168 curl_multi_cleanup(m);
169 curl_global_cleanup();
171 #elif defined(LIB532)
174 /* undocumented cleanup sequence - type UB */
176 for(i=0; i < NUM_HANDLES; i++)
177 curl_easy_cleanup(curl[i]);
178 curl_multi_cleanup(m);
179 curl_global_cleanup();