lib1542.c 2.4 KB

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