lib533.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. /* used for test case 533, 534 and 535 */
  25. #include "test.h"
  26. #include <fcntl.h>
  27. #include "testutil.h"
  28. #include "warnless.h"
  29. #include "memdebug.h"
  30. #define TEST_HANG_TIMEOUT 60 * 1000
  31. int test(char *URL)
  32. {
  33. int res = 0;
  34. CURL *curl = NULL;
  35. int running;
  36. CURLM *m = NULL;
  37. int current = 0;
  38. start_test_timing();
  39. global_init(CURL_GLOBAL_ALL);
  40. easy_init(curl);
  41. easy_setopt(curl, CURLOPT_URL, URL);
  42. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  43. easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
  44. multi_init(m);
  45. multi_add_handle(m, curl);
  46. fprintf(stderr, "Start at URL 0\n");
  47. for(;;) {
  48. struct timeval interval;
  49. fd_set rd, wr, exc;
  50. int maxfd = -99;
  51. interval.tv_sec = 1;
  52. interval.tv_usec = 0;
  53. multi_perform(m, &running);
  54. abort_on_test_timeout();
  55. if(!running) {
  56. if(!current++) {
  57. fprintf(stderr, "Advancing to URL 1\n");
  58. /* remove the handle we use */
  59. curl_multi_remove_handle(m, curl);
  60. /* make us re-use the same handle all the time, and try resetting
  61. the handle first too */
  62. curl_easy_reset(curl);
  63. easy_setopt(curl, CURLOPT_URL, libtest_arg2);
  64. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  65. easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
  66. /* re-add it */
  67. multi_add_handle(m, curl);
  68. }
  69. else
  70. break; /* done */
  71. }
  72. FD_ZERO(&rd);
  73. FD_ZERO(&wr);
  74. FD_ZERO(&exc);
  75. multi_fdset(m, &rd, &wr, &exc, &maxfd);
  76. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  77. select_test(maxfd + 1, &rd, &wr, &exc, &interval);
  78. abort_on_test_timeout();
  79. }
  80. test_cleanup:
  81. /* undocumented cleanup sequence - type UB */
  82. curl_easy_cleanup(curl);
  83. curl_multi_cleanup(m);
  84. curl_global_cleanup();
  85. return res;
  86. }