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 | |
| 25 | /* |
| 26 | * Test CURLOPT_MAXLIFETIME_CONN: |
| 27 | * Send four requests, sleeping between the second and third and setting |
| 28 | * MAXLIFETIME_CONN between the third and fourth. The first three requests |
| 29 | * should use the same connection, and the fourth request should close the |
| 30 | * first connection and open a second. |
| 31 | */ |
| 32 | |
| 33 | #include "test.h" |
| 34 | #include "testutil.h" |
| 35 | #include "testtrace.h" |
| 36 | #include "warnless.h" |
| 37 | #include "memdebug.h" |
| 38 | |
| 39 | #if defined(WIN32) || defined(_WIN32) |
| 40 | #define sleep(sec) Sleep ((sec)*1000) |
| 41 | #endif |
| 42 | |
| 43 | int test(char *URL) |
| 44 | { |
| 45 | CURL *easy = NULL; |
| 46 | int res = 0; |
| 47 | |
| 48 | global_init(CURL_GLOBAL_ALL); |
| 49 | |
| 50 | res_easy_init(easy); |
| 51 | |
| 52 | easy_setopt(easy, CURLOPT_URL, URL); |
| 53 | |
| 54 | libtest_debug_config.nohex = 1; |
| 55 | libtest_debug_config.tracetime = 0; |
| 56 | easy_setopt(easy, CURLOPT_DEBUGDATA, &libtest_debug_config); |
| 57 | easy_setopt(easy, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); |
| 58 | easy_setopt(easy, CURLOPT_VERBOSE, 1L); |
| 59 | |
| 60 | res = curl_easy_perform(easy); |
| 61 | if(res) |
| 62 | goto test_cleanup; |
| 63 | |
| 64 | res = curl_easy_perform(easy); |
| 65 | if(res) |
| 66 | goto test_cleanup; |
| 67 | |
| 68 | /* CURLOPT_MAXLIFETIME_CONN is inclusive - the connection needs to be 2 |
| 69 | * seconds old */ |
| 70 | sleep(2); |
| 71 | |
| 72 | res = curl_easy_perform(easy); |
| 73 | if(res) |
| 74 | goto test_cleanup; |
| 75 | |
| 76 | easy_setopt(easy, CURLOPT_MAXLIFETIME_CONN, 1L); |
| 77 | |
| 78 | res = curl_easy_perform(easy); |
| 79 | if(res) |
| 80 | goto test_cleanup; |
| 81 | |
| 82 | test_cleanup: |
| 83 | |
| 84 | curl_easy_cleanup(easy); |
| 85 | curl_global_cleanup(); |
| 86 | |
| 87 | return (int)res; |
| 88 | } |