lib575.c 2.7 KB

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