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 <fcntl.h> |
| 27 | |
| 28 | #include "testutil.h" |
| 29 | #include "warnless.h" |
| 30 | #include "memdebug.h" |
| 31 | |
| 32 | #define TEST_HANG_TIMEOUT 30 * 1000 |
| 33 | |
| 34 | /* 500 milliseconds allowed. An extreme number but lets be really conservative |
| 35 | to allow old and slow machines to run this test too */ |
| 36 | #define MAX_BLOCKED_TIME_MS 500 |
| 37 | |
| 38 | int test(char *URL) |
| 39 | { |
| 40 | CURL *handle = NULL; |
| 41 | CURLM *mhandle = NULL; |
| 42 | int res = 0; |
| 43 | int still_running = 0; |
| 44 | |
| 45 | start_test_timing(); |
| 46 | |
| 47 | global_init(CURL_GLOBAL_ALL); |
| 48 | |
| 49 | easy_init(handle); |
| 50 | |
| 51 | easy_setopt(handle, CURLOPT_URL, URL); |
| 52 | easy_setopt(handle, CURLOPT_VERBOSE, 1L); |
| 53 | |
| 54 | multi_init(mhandle); |
| 55 | |
| 56 | multi_add_handle(mhandle, handle); |
| 57 | |
| 58 | multi_perform(mhandle, &still_running); |
| 59 | |
| 60 | abort_on_test_timeout(); |
| 61 | |
| 62 | while(still_running) { |
| 63 | struct timeval timeout; |
| 64 | fd_set fdread; |
| 65 | fd_set fdwrite; |
| 66 | fd_set fdexcep; |
| 67 | int maxfd = -99; |
| 68 | struct timeval before; |
| 69 | struct timeval after; |
| 70 | long e; |
| 71 | |
| 72 | timeout.tv_sec = 0; |
| 73 | timeout.tv_usec = 100000L; /* 100 ms */ |
| 74 | |
| 75 | FD_ZERO(&fdread); |
| 76 | FD_ZERO(&fdwrite); |
| 77 | FD_ZERO(&fdexcep); |
| 78 | |
| 79 | multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd); |
| 80 | |
| 81 | /* At this point, maxfd is guaranteed to be greater or equal than -1. */ |
| 82 | |
| 83 | select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); |
| 84 | |
| 85 | abort_on_test_timeout(); |
| 86 | |
| 87 | fprintf(stderr, "ping\n"); |
| 88 | before = tutil_tvnow(); |
| 89 | |
| 90 | multi_perform(mhandle, &still_running); |
| 91 | |
| 92 | abort_on_test_timeout(); |
| 93 | |
| 94 | after = tutil_tvnow(); |
| 95 | e = tutil_tvdiff(after, before); |
| 96 | fprintf(stderr, "pong = %ld\n", e); |
| 97 | |
| 98 | if(e > MAX_BLOCKED_TIME_MS) { |
| 99 | res = 100; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | test_cleanup: |
| 105 | |
| 106 | /* undocumented cleanup sequence - type UA */ |
| 107 | |
| 108 | curl_multi_cleanup(mhandle); |
| 109 | curl_easy_cleanup(handle); |
| 110 | curl_global_cleanup(); |
| 111 | |
| 112 | return res; |
| 113 | } |