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