lib1501.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <fcntl.h>
  24. #include "testutil.h"
  25. #include "warnless.h"
  26. #include "memdebug.h"
  27. #define TEST_HANG_TIMEOUT 30 * 1000
  28. /* 500 milliseconds allowed. An extreme number but lets be really conservative
  29. to allow old and slow machines to run this test too */
  30. #define MAX_BLOCKED_TIME_MS 500
  31. int test(char *URL)
  32. {
  33. CURL *handle = NULL;
  34. CURLM *mhandle = NULL;
  35. int res = 0;
  36. int still_running = 0;
  37. start_test_timing();
  38. global_init(CURL_GLOBAL_ALL);
  39. easy_init(handle);
  40. easy_setopt(handle, CURLOPT_URL, URL);
  41. easy_setopt(handle, CURLOPT_VERBOSE, 1L);
  42. multi_init(mhandle);
  43. multi_add_handle(mhandle, handle);
  44. multi_perform(mhandle, &still_running);
  45. abort_on_test_timeout();
  46. while(still_running) {
  47. struct timeval timeout;
  48. fd_set fdread;
  49. fd_set fdwrite;
  50. fd_set fdexcep;
  51. int maxfd = -99;
  52. struct timeval before;
  53. struct timeval after;
  54. long e;
  55. timeout.tv_sec = 0;
  56. timeout.tv_usec = 100000L; /* 100 ms */
  57. FD_ZERO(&fdread);
  58. FD_ZERO(&fdwrite);
  59. FD_ZERO(&fdexcep);
  60. multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
  61. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  62. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  63. abort_on_test_timeout();
  64. fprintf(stderr, "ping\n");
  65. before = tutil_tvnow();
  66. multi_perform(mhandle, &still_running);
  67. abort_on_test_timeout();
  68. after = tutil_tvnow();
  69. e = tutil_tvdiff(after, before);
  70. fprintf(stderr, "pong = %ld\n", e);
  71. if(e > MAX_BLOCKED_TIME_MS) {
  72. res = 100;
  73. break;
  74. }
  75. }
  76. test_cleanup:
  77. /* undocumented cleanup sequence - type UA */
  78. curl_multi_cleanup(mhandle);
  79. curl_easy_cleanup(handle);
  80. curl_global_cleanup();
  81. return res;
  82. }