master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Dmitry Karpov <dkarpov1970@gmail.com>
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 ***************************************************************************/
25/*
26 * The purpose of this test is to test behavior of curl_multi_waitfds
27 * function in different scenarios:
28 * empty multi handle (expected zero descriptors),
29 * HTTP1 amd HTTP2 (no multiplexing) two transfers (expected two descriptors),
30 * HTTP2 with multiplexing (expected one descriptors)
31 * Improper inputs to the API result in CURLM_BAD_FUNCTION_ARGUMENT.
32 * Sending an empty ufds, and size = 0 returns the number of fds needed.
33 * Sending a non-empty ufds, but smaller than the fds needed results in a
34 * CURLM_OUT_OF_MEMORY, and a number of fds that is >= to the number needed.
35 *
36 * It is also expected that all transfers run by multi-handle should complete
37 * successfully.
38 */
40#include "first.h"
42/* ---------------------------------------------------------------- */
44/* ---------------------------------------------------------------- */
46enum {
47 TEST_USE_HTTP1 = 0,
48 TEST_USE_HTTP2,
49 TEST_USE_HTTP2_MPLEX
50};
52static CURLcode set_easy(const char *URL, CURL *curl, long option)
53{
54 CURLcode result = CURLE_OK;
56 /* First set the URL that is about to receive our POST. */
57 easy_setopt(curl, CURLOPT_URL, URL);
59 /* get verbose debug output please */
60 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
62 switch(option) {
63 case TEST_USE_HTTP1:
64 /* go http1 */
65 easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
66 break;
68 case TEST_USE_HTTP2:
69 /* go http2 */
70 easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
71 break;
73 case TEST_USE_HTTP2_MPLEX:
74 /* go http2 with multiplexing */
75 easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
76 easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
77 break;
78 }
80 /* no peer verify */
81 easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
82 easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
84 /* include headers */
85 easy_setopt(curl, CURLOPT_HEADER, 1L);
87 /* empty write function */
88 easy_setopt(curl, CURLOPT_WRITEFUNCTION, tutil_throwaway_cb);
90test_cleanup:
91 return result;
92}
94static CURLcode test_run(const char *URL, long option,
95 unsigned int *max_fd_count)
96{
97 CURLMcode mresult = CURLM_OK;
98 CURLM *multi = NULL;
99 CURLM *multi1 = NULL;
101 CURL *curl1 = NULL;
102 CURL *curl2 = NULL;
104 unsigned int max_count = 0;
106 int still_running; /* keep number of running handles */
107 CURLMsg *msg; /* for picking up messages with the transfer status */
108 int msgs_left; /* how many messages are left */
110 CURLcode result = CURLE_OK;
112 struct curl_waitfd ufds[10];
113 struct curl_waitfd ufds1[10];
114 int numfds;
116 easy_init(curl1);
117 easy_init(curl2);
119 if(set_easy(URL, curl1, option) != CURLE_OK)
120 goto test_cleanup;
122 if(set_easy(URL, curl2, option) != CURLE_OK)
123 goto test_cleanup;
125 multi_init(multi);
126 multi_init(multi1);
128 if(option == TEST_USE_HTTP2_MPLEX)
129 multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
131 multi_add_handle(multi, curl1);
132 multi_add_handle(multi, curl2);
134 while(!mresult) {
135 /* get the count of file descriptors from the transfers */
136 unsigned int fd_count = 0;
137 unsigned int fd_count_chk = 0;
139 mresult = curl_multi_perform(multi, &still_running);
140 if(!still_running || mresult != CURLM_OK)
141 break;
143 /* verify improper inputs are treated correctly. */
144 mresult = curl_multi_waitfds(multi, NULL, 0, NULL);
146 if(mresult != CURLM_BAD_FUNCTION_ARGUMENT) {
147 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
148 "CURLM_BAD_FUNCTION_ARGUMENT.\n", mresult);
149 result = TEST_ERR_FAILURE;
150 break;
151 }
153 mresult = curl_multi_waitfds(multi, NULL, 1, NULL);
155 if(mresult != CURLM_BAD_FUNCTION_ARGUMENT) {
156 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
157 "CURLM_BAD_FUNCTION_ARGUMENT.\n", mresult);
158 result = TEST_ERR_FAILURE;
159 break;
160 }
162 mresult = curl_multi_waitfds(multi, NULL, 1, &fd_count);
164 if(mresult != CURLM_BAD_FUNCTION_ARGUMENT) {
165 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
166 "CURLM_BAD_FUNCTION_ARGUMENT.\n", mresult);
167 result = TEST_ERR_FAILURE;
168 break;
169 }
171 mresult = curl_multi_waitfds(multi, ufds, 10, &fd_count);
173 if(mresult != CURLM_OK) {
174 curl_mfprintf(stderr, "curl_multi_waitfds() failed, code %d.\n",
175 mresult);
176 result = TEST_ERR_FAILURE;
177 break;
178 }
180 if(!fd_count)
181 continue; /* no descriptors yet */
183 /* verify that sending nothing but the fd_count results in at least the
184 * same number of fds */
185 mresult = curl_multi_waitfds(multi, NULL, 0, &fd_count_chk);
187 if(mresult != CURLM_OK) {
188 curl_mfprintf(stderr, "curl_multi_waitfds() failed, code %d.\n",
189 mresult);
190 result = TEST_ERR_FAILURE;
191 break;
192 }
194 if(fd_count_chk < fd_count) {
195 curl_mfprintf(stderr,
196 "curl_multi_waitfds() should return at least the number "
197 "of fds needed (%u vs. %u)\n", fd_count_chk, fd_count);
198 result = TEST_ERR_FAILURE;
199 break;
200 }
202 /* checking case when we do not have enough space for waitfds */
203 mresult = curl_multi_waitfds(multi, ufds1, fd_count - 1, &fd_count_chk);
205 if(mresult != CURLM_OUT_OF_MEMORY) {
206 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
207 "CURLM_OUT_OF_MEMORY.\n", mresult);
208 result = TEST_ERR_FAILURE;
209 break;
210 }
212 if(fd_count_chk < fd_count) {
213 curl_mfprintf(stderr,
214 "curl_multi_waitfds() should return the amount of fds "
215 "needed if enough is not passed in (%u vs. %u).\n",
216 fd_count_chk, fd_count);
217 result = TEST_ERR_FAILURE;
218 break;
219 }
221 /* sending ufds with zero size, is valid */
222 mresult = curl_multi_waitfds(multi, ufds, 0, NULL);
224 if(mresult != CURLM_OUT_OF_MEMORY) {
225 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
226 "CURLM_OUT_OF_MEMORY.\n", mresult);
227 result = TEST_ERR_FAILURE;
228 break;
229 }
231 mresult = curl_multi_waitfds(multi, ufds, 0, &fd_count_chk);
233 if(mresult != CURLM_OUT_OF_MEMORY) {
234 curl_mfprintf(stderr, "curl_multi_waitfds() return code %d instead of "
235 "CURLM_OUT_OF_MEMORY.\n", mresult);
236 result = TEST_ERR_FAILURE;
237 break;
238 }
240 if(fd_count_chk < fd_count) {
241 curl_mfprintf(stderr,
242 "curl_multi_waitfds() should return the amount of fds "
243 "needed if enough is not passed in (%u vs. %u).\n",
244 fd_count_chk, fd_count);
245 result = TEST_ERR_FAILURE;
246 break;
247 }
249 if(fd_count > max_count)
250 max_count = fd_count;
252 /* Do polling on descriptors in ufds in Multi 1 */
253 mresult = curl_multi_poll(multi1, ufds, fd_count, 500, &numfds);
255 if(mresult != CURLM_OK) {
256 curl_mfprintf(stderr, "curl_multi_poll() failed, code %d.\n", mresult);
257 result = TEST_ERR_FAILURE;
258 break;
259 }
260 }
262 for(;;) {
263 msg = curl_multi_info_read(multi, &msgs_left);
264 if(!msg)
265 break;
266 if(msg->msg == CURLMSG_DONE) {
267 result = msg->data.result;
268 }
269 }
271 curl_multi_remove_handle(multi, curl1);
272 curl_multi_remove_handle(multi, curl2);
274test_cleanup:
275 curl_easy_cleanup(curl1);
276 curl_easy_cleanup(curl2);
278 curl_multi_cleanup(multi);
279 curl_multi_cleanup(multi1);
281 if(max_fd_count)
282 *max_fd_count = max_count;
284 return result;
285}
287static CURLcode test_run_check(const char *URL, long option,
288 unsigned int expected_fds)
289{
290 unsigned int fd_count = 0;
291 CURLcode result = test_run(URL, option, &fd_count);
292 if(result)
293 curl_mfprintf(stderr, "test failed with code: %d\n", (int)result);
294 else if(fd_count != expected_fds) {
295 curl_mfprintf(stderr,
296 "Max number of waitfds: %u not as expected: %u\n",
297 fd_count, expected_fds);
298 result = TEST_ERR_FAILURE;
299 }
300 return result;
301}
303static CURLcode empty_multi_test(void)
304{
305 CURLMcode mresult = CURLM_OK;
306 CURLM *multi = NULL;
307 CURL *curl = NULL;
309 struct curl_waitfd ufds[10];
311 CURLcode result = CURLE_OK;
312 unsigned int fd_count = 0;
314 multi_init(multi);
316 /* calling curl_multi_waitfds() on an empty multi handle. */
317 mresult = curl_multi_waitfds(multi, ufds, 10, &fd_count);
319 if(mresult != CURLM_OK) {
320 curl_mfprintf(stderr, "curl_multi_waitfds() failed, code %d.\n", mresult);
321 result = TEST_ERR_FAILURE;
322 goto test_cleanup;
323 }
324 else if(fd_count > 0) {
325 curl_mfprintf(stderr, "curl_multi_waitfds(), empty, returned non-zero "
326 "count of waitfds: %u.\n", fd_count);
327 result = TEST_ERR_FAILURE;
328 goto test_cleanup;
329 }
331 /* calling curl_multi_waitfds() on multi handle with added easy handle. */
332 easy_init(curl);
334 if(set_easy("http://example.com", curl, TEST_USE_HTTP1) != CURLE_OK)
335 goto test_cleanup;
337 multi_add_handle(multi, curl);
339 mresult = curl_multi_waitfds(multi, ufds, 10, &fd_count);
341 if(mresult != CURLM_OK) {
342 curl_mfprintf(stderr, "curl_multi_waitfds() failed, code %d.\n", mresult);
343 result = TEST_ERR_FAILURE;
344 goto test_cleanup;
345 }
346 else if(fd_count > 1) {
347 curl_mfprintf(stderr, "curl_multi_waitfds() returned > 1 count of "
348 "waitfds: %u.\n", fd_count);
349 result = TEST_ERR_FAILURE;
350 goto test_cleanup;
351 }
353 curl_multi_remove_handle(multi, curl);
355test_cleanup:
356 curl_easy_cleanup(curl);
357 curl_multi_cleanup(multi);
358 return result;
359}
361static unsigned int uses_threaded(void)
362{
363 curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
364 const char * const *n = ver->feature_names;
365 int i;
366 unsigned int uses = 0;
367 /* the 'asyn-rr' feature tells us libcurl uses the threaded resolver */
368 for(i = 0; n[i]; i++) {
369 if(!strcmp("asyn-rr", n[i]))
370 uses = 1;
371 }
372 /* if not using asyn-rr, check if doing asynch DNS without using c-ares */
373 if(!uses && (ver->features & CURL_VERSION_ASYNCHDNS) && !ver->ares)
374 uses = 1;
375 return uses;
376}
378static CURLcode test_lib2405(const char *URL)
379{
380 CURLcode result = CURLE_OK;
381 int uses_threaded_resolver;
383 global_init(CURL_GLOBAL_ALL);
385 uses_threaded_resolver = uses_threaded();
387 /* Testing curl_multi_waitfds on empty and not started handles */
388 result = empty_multi_test();
389 if(result != CURLE_OK)
390 goto test_cleanup;
392 if(testnum == 2405) {
393 /* HTTP1, one for each transfer + possible wakeup */
394 result = test_run_check(URL, TEST_USE_HTTP1, 2 + uses_threaded_resolver);
395 }
396#ifdef USE_HTTP2
397 else { /* 2407 */
398 /* HTTP2, one for each transfer + possible wakeup */
399 result = test_run_check(URL, TEST_USE_HTTP2, 2 + uses_threaded_resolver);
401 /* HTTP2 with multiplexing, expected one waitfds + possible wakeup */
402 if(!result)
403 result = test_run_check(URL, TEST_USE_HTTP2_MPLEX,
404 1 + uses_threaded_resolver);
405 }
406#endif
408test_cleanup:
409 curl_global_cleanup();
410 return result;
411}
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=18 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.2 KiB · hit19 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3285 git.response.cache=HIT git.response.duration_ms=19 git.fetch.wants=6d98183a83ba2628a0b36350072f95c28b7c3db1 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3285 git.pkt.payload.max=3264 git.sideband.band1.bytes=3263 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e334dd5d83f485
- Request
- 1b7d06e5…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format