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