lib1501.c 2.8 KB

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