lib2404.c (3841B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 static CURLcode test_lib2404(char *URL) 29 { 30 CURLcode res = CURLE_OK; 31 CURL *curl[NUM_HANDLES] = {0}; 32 int running; 33 CURLM *m = NULL; 34 size_t i; 35 char target_url[256]; 36 char dnsentry[256]; 37 struct curl_slist *slist = NULL; 38 char *port = libtest_arg3; 39 char *address = libtest_arg2; 40 41 (void)URL; 42 43 curl_msnprintf(dnsentry, sizeof(dnsentry), "localhost:%s:%s", 44 port, address); 45 curl_mprintf("%s\n", dnsentry); 46 slist = curl_slist_append(slist, dnsentry); 47 if(!slist) { 48 curl_mfprintf(stderr, "curl_slist_append() failed\n"); 49 goto test_cleanup; 50 } 51 52 start_test_timing(); 53 54 global_init(CURL_GLOBAL_ALL); 55 56 multi_init(m); 57 58 multi_setopt(m, CURLMOPT_MAXCONNECTS, 1L); 59 60 /* get each easy handle */ 61 for(i = 0; i < CURL_ARRAYSIZE(curl); i++) { 62 /* get an easy handle */ 63 easy_init(curl[i]); 64 /* specify target */ 65 curl_msnprintf(target_url, sizeof(target_url), 66 "https://localhost:%s/path/2404%04i", 67 port, (int)i + 1); 68 target_url[sizeof(target_url) - 1] = '\0'; 69 easy_setopt(curl[i], CURLOPT_URL, target_url); 70 /* go http2 */ 71 easy_setopt(curl[i], CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); 72 /* no peer verify */ 73 easy_setopt(curl[i], CURLOPT_SSL_VERIFYPEER, 0L); 74 easy_setopt(curl[i], CURLOPT_SSL_VERIFYHOST, 0L); 75 /* wait for first connection established to see if we can share it */ 76 easy_setopt(curl[i], CURLOPT_PIPEWAIT, 1L); 77 /* go verbose */ 78 easy_setopt(curl[i], CURLOPT_VERBOSE, 1L); 79 /* include headers */ 80 easy_setopt(curl[i], CURLOPT_HEADER, 1L); 81 82 easy_setopt(curl[i], CURLOPT_RESOLVE, slist); 83 84 easy_setopt(curl[i], CURLOPT_STREAM_WEIGHT, (long)i + 128); 85 } 86 87 curl_mfprintf(stderr, "Start at URL 0\n"); 88 89 for(i = 0; i < CURL_ARRAYSIZE(curl); i++) { 90 /* add handle to multi */ 91 multi_add_handle(m, curl[i]); 92 93 for(;;) { 94 struct timeval interval; 95 fd_set rd, wr, exc; 96 int maxfd = -99; 97 98 interval.tv_sec = 1; 99 interval.tv_usec = 0; 100 101 multi_perform(m, &running); 102 103 abort_on_test_timeout(); 104 105 if(!running) 106 break; /* done */ 107 108 FD_ZERO(&rd); 109 FD_ZERO(&wr); 110 FD_ZERO(&exc); 111 112 multi_fdset(m, &rd, &wr, &exc, &maxfd); 113 114 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 115 116 select_test(maxfd + 1, &rd, &wr, &exc, &interval); 117 118 abort_on_test_timeout(); 119 } 120 curlx_wait_ms(1); /* to ensure different end times */ 121 } 122 123 test_cleanup: 124 125 /* proper cleanup sequence - type PB */ 126 127 for(i = 0; i < CURL_ARRAYSIZE(curl); i++) { 128 curl_multi_remove_handle(m, curl[i]); 129 curl_easy_cleanup(curl[i]); 130 } 131 132 curl_slist_free_all(slist); 133 134 curl_multi_cleanup(m); 135 curl_global_cleanup(); 136 137 return res; 138 }