• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) Linus Nielsen Feltzing <linus@haxx.se>
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 "testutil.h"
27 #include "warnless.h"
28 #include "memdebug.h"
29 
30 #define TEST_HANG_TIMEOUT 60 * 1000
31 
32 #define NUM_HANDLES 4
33 
test(char * URL)34 int test(char *URL)
35 {
36   int res = 0;
37   CURL *curl[NUM_HANDLES] = {0};
38   int running;
39   CURLM *m = NULL;
40   int i;
41   char target_url[256];
42   char dnsentry[256];
43   struct curl_slist *slist = NULL;
44   char *port = libtest_arg3;
45   char *address = libtest_arg2;
46 
47   (void)URL;
48 
49   msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s",
50             port, address);
51   printf("%s\n", dnsentry);
52   slist = curl_slist_append(slist, dnsentry);
53   if(!slist) {
54     fprintf(stderr, "curl_slist_append() failed\n");
55     goto test_cleanup;
56   }
57 
58   start_test_timing();
59 
60   global_init(CURL_GLOBAL_ALL);
61 
62   multi_init(m);
63 
64   multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L);
65 
66   /* get NUM_HANDLES easy handles */
67   for(i = 0; i < NUM_HANDLES; i++) {
68     /* get an easy handle */
69     easy_init(curl[i]);
70     /* specify target */
71     msnprintf(target_url, sizeof(target_url),
72               "https://localhost:%s/path/2502%04i",
73               port, i + 1);
74     target_url[sizeof(target_url) - 1] = '\0';
75     easy_setopt(curl[i], CURLOPT_URL, target_url);
76     /* go http2 */
77     easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3ONLY);
78     easy_setopt(curl[i], CURLOPT_CONNECTTIMEOUT_MS, (long)5000);
79     easy_setopt(curl[i], CURLOPT_CAINFO, "./certs/EdelCurlRoot-ca.cacert");
80     /* wait for first connection established to see if we can share it */
81     easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L);
82     /* go verbose */
83     easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
84     /* include headers */
85     easy_setopt(curl[i], CURLOPT_HEADER, 1L);
86 
87     easy_setopt(curl[i], CURLOPT_RESOLVE, slist);
88   }
89 
90   fprintf(stderr, "Start at URL 0\n");
91 
92   for(i = 0; i < NUM_HANDLES; i++) {
93     /* add handle to multi */
94     multi_add_handle(m, curl[i]);
95 
96     for(;;) {
97       struct timeval interval;
98       fd_set rd, wr, exc;
99       int maxfd = -99;
100 
101       interval.tv_sec = 1;
102       interval.tv_usec = 0;
103 
104       multi_perform(m, &running);
105 
106       abort_on_test_timeout();
107 
108       if(!running)
109         break; /* done */
110 
111       FD_ZERO(&rd);
112       FD_ZERO(&wr);
113       FD_ZERO(&exc);
114 
115       multi_fdset(m, &rd, &wr, &exc, &maxfd);
116 
117       /* At this point, maxfd is guaranteed to be greater or equal than -1. */
118 
119       select_test(maxfd + 1, &rd, &wr, &exc, &interval);
120 
121       abort_on_test_timeout();
122     }
123     wait_ms(1); /* to ensure different end times */
124   }
125 
126 test_cleanup:
127 
128   /* proper cleanup sequence - type PB */
129 
130   for(i = 0; i < NUM_HANDLES; i++) {
131     curl_multi_remove_handle(m, curl[i]);
132     curl_easy_cleanup(curl[i]);
133   }
134 
135   curl_slist_free_all(slist);
136 
137   curl_multi_cleanup(m);
138   curl_global_cleanup();
139 
140   return res;
141 }
142