lib533.c 2.8 KB

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