lib751.c (2329B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 /* 29 * Get a single URL without select(). 30 */ 31 32 static CURLcode test_lib751(char *URL) 33 { 34 CURL *easies[1000]; 35 CURLM *m; 36 CURLcode res = CURLE_FAILED_INIT; 37 CURLMcode mres; 38 int i; 39 40 (void)URL; 41 memset(easies, 0, sizeof(easies)); 42 43 curl_global_init(CURL_GLOBAL_DEFAULT); 44 m = curl_multi_init(); 45 if(!m) { 46 res = CURLE_OUT_OF_MEMORY; 47 goto test_cleanup; 48 } 49 50 for(i = 0; i < 1000; i++) { 51 CURL *e = curl_easy_init(); 52 if(!e) { 53 res = CURLE_OUT_OF_MEMORY; 54 goto test_cleanup; 55 } 56 easies[i] = e; 57 58 res = curl_easy_setopt(e, CURLOPT_URL, "https://www.example.com/"); 59 if(!res) 60 res = curl_easy_setopt(e, CURLOPT_VERBOSE, 1L); 61 if(res) 62 goto test_cleanup; 63 64 mres = curl_multi_add_handle(m, e); 65 if(mres != CURLM_OK) { 66 curl_mfprintf(stderr, "MULTI ERROR: %s\n", curl_multi_strerror(mres)); 67 res = CURLE_FAILED_INIT; 68 goto test_cleanup; 69 } 70 } 71 72 test_cleanup: 73 74 if(res) 75 curl_mfprintf(stderr, "ERROR: %s\n", curl_easy_strerror(res)); 76 77 for(i = 0; i < 1000; i++) { 78 if(easies[i]) { 79 curl_multi_add_handle(m, easies[i]); 80 curl_easy_cleanup(easies[i]); 81 easies[i] = NULL; 82 } 83 } 84 curl_multi_cleanup(m); 85 curl_global_cleanup(); 86 87 return res; 88 }