1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
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 https://curl.se/docs/copyright.html.
13 *
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.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24 #include "test.h"
25
26 #include <fcntl.h>
27
28 #include "testutil.h"
29 #include "warnless.h"
30 #include "memdebug.h"
31
32 #define TEST_HANG_TIMEOUT 60 * 1000
33
34 /* 3x download!
35 * 1. normal
36 * 2. dup handle
37 * 3. with multi interface
38 */
39
test(char * URL)40 CURLcode test(char *URL)
41 {
42 CURL *handle = NULL;
43 CURL *duphandle = NULL;
44 CURLM *mhandle = NULL;
45 CURLcode res = CURLE_OK;
46 int still_running = 0;
47
48 start_test_timing();
49
50 global_init(CURL_GLOBAL_ALL);
51
52 easy_init(handle);
53
54 easy_setopt(handle, CURLOPT_URL, URL);
55 easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
56 easy_setopt(handle, CURLOPT_VERBOSE, 1L);
57
58 res = curl_easy_perform(handle);
59 if(res)
60 goto test_cleanup;
61
62 res = curl_easy_perform(handle);
63 if(res)
64 goto test_cleanup;
65
66 duphandle = curl_easy_duphandle(handle);
67 if(!duphandle)
68 goto test_cleanup;
69 curl_easy_cleanup(handle);
70 handle = duphandle;
71
72 multi_init(mhandle);
73
74 multi_add_handle(mhandle, handle);
75
76 multi_perform(mhandle, &still_running);
77
78 abort_on_test_timeout();
79
80 while(still_running) {
81 struct timeval timeout;
82 fd_set fdread;
83 fd_set fdwrite;
84 fd_set fdexcep;
85 int maxfd = -99;
86
87 timeout.tv_sec = 0;
88 timeout.tv_usec = 100000L; /* 100 ms */
89
90 FD_ZERO(&fdread);
91 FD_ZERO(&fdwrite);
92 FD_ZERO(&fdexcep);
93
94 multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
95
96 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
97
98 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
99
100 abort_on_test_timeout();
101
102 multi_perform(mhandle, &still_running);
103
104 abort_on_test_timeout();
105 }
106
107 test_cleanup:
108
109 /* undocumented cleanup sequence - type UA */
110
111 curl_multi_cleanup(mhandle);
112 curl_easy_cleanup(handle);
113 curl_global_cleanup();
114
115 return res;
116 }
117