2
0

lib502.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. /*
  28. * Get a single URL without select().
  29. */
  30. int test(char *URL)
  31. {
  32. CURL *c = NULL;
  33. CURLM *m = NULL;
  34. int res = 0;
  35. int running;
  36. start_test_timing();
  37. global_init(CURL_GLOBAL_ALL);
  38. easy_init(c);
  39. easy_setopt(c, CURLOPT_URL, URL);
  40. multi_init(m);
  41. multi_add_handle(m, c);
  42. for(;;) {
  43. struct timeval timeout;
  44. fd_set fdread, fdwrite, fdexcep;
  45. int maxfd = -99;
  46. timeout.tv_sec = 0;
  47. timeout.tv_usec = 100000L; /* 100 ms */
  48. multi_perform(m, &running);
  49. abort_on_test_timeout();
  50. if(!running)
  51. break; /* done */
  52. FD_ZERO(&fdread);
  53. FD_ZERO(&fdwrite);
  54. FD_ZERO(&fdexcep);
  55. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  56. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  57. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  58. abort_on_test_timeout();
  59. }
  60. test_cleanup:
  61. /* proper cleanup sequence - type PA */
  62. curl_multi_remove_handle(m, c);
  63. curl_multi_cleanup(m);
  64. curl_easy_cleanup(c);
  65. curl_global_cleanup();
  66. return res;
  67. }