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