lib1542.c 2.4 KB

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