| 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 | /* used for test case 533, 534 and 535 */ | 
|  | 25 |  | 
|  | 26 | #include "test.h" | 
|  | 27 |  | 
|  | 28 | #include <fcntl.h> | 
|  | 29 |  | 
|  | 30 | #include "testutil.h" | 
|  | 31 | #include "warnless.h" | 
|  | 32 | #include "memdebug.h" | 
|  | 33 |  | 
|  | 34 | #define TEST_HANG_TIMEOUT 60 * 1000 | 
|  | 35 |  | 
|  | 36 | int test(char *URL) | 
|  | 37 | { | 
|  | 38 | int res = 0; | 
|  | 39 | CURL *curl = NULL; | 
|  | 40 | int running; | 
|  | 41 | CURLM *m = NULL; | 
|  | 42 | int current = 0; | 
|  | 43 |  | 
|  | 44 | start_test_timing(); | 
|  | 45 |  | 
|  | 46 | global_init(CURL_GLOBAL_ALL); | 
|  | 47 |  | 
|  | 48 | easy_init(curl); | 
|  | 49 |  | 
|  | 50 | easy_setopt(curl, CURLOPT_URL, URL); | 
|  | 51 | easy_setopt(curl, CURLOPT_VERBOSE, 1L); | 
|  | 52 | easy_setopt(curl, CURLOPT_FAILONERROR, 1L); | 
|  | 53 |  | 
|  | 54 | multi_init(m); | 
|  | 55 |  | 
|  | 56 | multi_add_handle(m, curl); | 
|  | 57 |  | 
|  | 58 | fprintf(stderr, "Start at URL 0\n"); | 
|  | 59 |  | 
|  | 60 | for(;;) { | 
|  | 61 | struct timeval interval; | 
|  | 62 | fd_set rd, wr, exc; | 
|  | 63 | int maxfd = -99; | 
|  | 64 |  | 
|  | 65 | interval.tv_sec = 1; | 
|  | 66 | interval.tv_usec = 0; | 
|  | 67 |  | 
|  | 68 | multi_perform(m, &running); | 
|  | 69 |  | 
|  | 70 | abort_on_test_timeout(); | 
|  | 71 |  | 
|  | 72 | if(!running) { | 
|  | 73 | if(!current++) { | 
|  | 74 | fprintf(stderr, "Advancing to URL 1\n"); | 
|  | 75 | /* remove the handle we use */ | 
|  | 76 | curl_multi_remove_handle(m, curl); | 
|  | 77 |  | 
|  | 78 | /* make us re-use the same handle all the time, and try resetting | 
|  | 79 | the handle first too */ | 
|  | 80 | curl_easy_reset(curl); | 
|  | 81 | easy_setopt(curl, CURLOPT_URL, libtest_arg2); | 
|  | 82 | easy_setopt(curl, CURLOPT_VERBOSE, 1L); | 
|  | 83 | easy_setopt(curl, CURLOPT_FAILONERROR, 1L); | 
|  | 84 |  | 
|  | 85 | /* re-add it */ | 
|  | 86 | multi_add_handle(m, curl); | 
|  | 87 | } | 
|  | 88 | else | 
|  | 89 | break; /* done */ | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | FD_ZERO(&rd); | 
|  | 93 | FD_ZERO(&wr); | 
|  | 94 | FD_ZERO(&exc); | 
|  | 95 |  | 
|  | 96 | multi_fdset(m, &rd, &wr, &exc, &maxfd); | 
|  | 97 |  | 
|  | 98 | /* At this point, maxfd is guaranteed to be greater or equal than -1. */ | 
|  | 99 |  | 
|  | 100 | select_test(maxfd + 1, &rd, &wr, &exc, &interval); | 
|  | 101 |  | 
|  | 102 | abort_on_test_timeout(); | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | test_cleanup: | 
|  | 106 |  | 
|  | 107 | /* undocumented cleanup sequence - type UB */ | 
|  | 108 |  | 
|  | 109 | curl_easy_cleanup(curl); | 
|  | 110 | curl_multi_cleanup(m); | 
|  | 111 | curl_global_cleanup(); | 
|  | 112 |  | 
|  | 113 | return res; | 
|  | 114 | } |