lib575.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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. #include <fcntl.h>
  26. #include "testutil.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. /* 3x download!
  31. * 1. normal
  32. * 2. dup handle
  33. * 3. with multi interface
  34. */
  35. int test(char *URL)
  36. {
  37. CURL *handle = NULL;
  38. CURL *duphandle = NULL;
  39. CURLM *mhandle = NULL;
  40. int res = 0;
  41. int still_running = 0;
  42. start_test_timing();
  43. global_init(CURL_GLOBAL_ALL);
  44. easy_init(handle);
  45. easy_setopt(handle, CURLOPT_URL, URL);
  46. easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
  47. easy_setopt(handle, CURLOPT_VERBOSE, 1L);
  48. res = curl_easy_perform(handle);
  49. if(res)
  50. goto test_cleanup;
  51. res = curl_easy_perform(handle);
  52. if(res)
  53. goto test_cleanup;
  54. duphandle = curl_easy_duphandle(handle);
  55. if(!duphandle)
  56. goto test_cleanup;
  57. curl_easy_cleanup(handle);
  58. handle = duphandle;
  59. multi_init(mhandle);
  60. multi_add_handle(mhandle, handle);
  61. multi_perform(mhandle, &still_running);
  62. abort_on_test_timeout();
  63. while(still_running) {
  64. struct timeval timeout;
  65. fd_set fdread;
  66. fd_set fdwrite;
  67. fd_set fdexcep;
  68. int maxfd = -99;
  69. timeout.tv_sec = 0;
  70. timeout.tv_usec = 100000L; /* 100 ms */
  71. FD_ZERO(&fdread);
  72. FD_ZERO(&fdwrite);
  73. FD_ZERO(&fdexcep);
  74. multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
  75. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  76. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  77. abort_on_test_timeout();
  78. multi_perform(mhandle, &still_running);
  79. abort_on_test_timeout();
  80. }
  81. test_cleanup:
  82. /* undocumented cleanup sequence - type UA */
  83. curl_multi_cleanup(mhandle);
  84. curl_easy_cleanup(handle);
  85. curl_global_cleanup();
  86. return res;
  87. }