lib560.c (3231B)
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 * Simply download an HTTPS file! 30 * 31 * This test was added after the HTTPS-using-multi-interface with OpenSSL 32 * regression of 7.19.1 to hopefully prevent this embarrassing mistake from 33 * appearing again... Unfortunately the bug wasn't triggered by this test, 34 * which presumably is because the connect to a local server is too 35 * fast/different compared to the real/distant servers we saw the bug happen 36 * with. 37 */ 38 static CURLcode test_lib560(char *URL) 39 { 40 CURL *http_handle = NULL; 41 CURLM *multi_handle = NULL; 42 CURLcode res = CURLE_OK; 43 44 int still_running; /* keep number of running handles */ 45 46 start_test_timing(); 47 48 /* 49 ** curl_global_init called indirectly from curl_easy_init. 50 */ 51 52 easy_init(http_handle); 53 54 /* set options */ 55 easy_setopt(http_handle, CURLOPT_URL, URL); 56 easy_setopt(http_handle, CURLOPT_HEADER, 1L); 57 easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L); 58 easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L); 59 60 /* init a multi stack */ 61 multi_init(multi_handle); 62 63 /* add the individual transfers */ 64 multi_add_handle(multi_handle, http_handle); 65 66 /* we start some action by calling perform right away */ 67 multi_perform(multi_handle, &still_running); 68 69 abort_on_test_timeout(); 70 71 while(still_running) { 72 struct timeval timeout; 73 74 fd_set fdread; 75 fd_set fdwrite; 76 fd_set fdexcep; 77 int maxfd = -99; 78 79 FD_ZERO(&fdread); 80 FD_ZERO(&fdwrite); 81 FD_ZERO(&fdexcep); 82 83 /* set a suitable timeout to play around with */ 84 timeout.tv_sec = 1; 85 timeout.tv_usec = 0; 86 87 /* get file descriptors from the transfers */ 88 multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); 89 90 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 91 92 select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); 93 94 abort_on_test_timeout(); 95 96 /* timeout or readable/writable sockets */ 97 multi_perform(multi_handle, &still_running); 98 99 abort_on_test_timeout(); 100 } 101 102 test_cleanup: 103 104 /* undocumented cleanup sequence - type UA */ 105 106 curl_multi_cleanup(multi_handle); 107 curl_easy_cleanup(http_handle); 108 curl_global_cleanup(); 109 110 return res; 111 }