lib573.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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 "testtrace.h"
  26. #include "testutil.h"
  27. #include "warnless.h"
  28. #include "memdebug.h"
  29. #define TEST_HANG_TIMEOUT 60 * 1000
  30. /*
  31. * Get a single URL without select().
  32. */
  33. int test(char *URL)
  34. {
  35. CURL *c = NULL;
  36. CURLM *m = NULL;
  37. int res = 0;
  38. int running = 1;
  39. double connect_time = 0.0;
  40. double dbl_epsilon;
  41. dbl_epsilon = 1.0;
  42. do {
  43. dbl_epsilon /= 2.0;
  44. } while((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0);
  45. start_test_timing();
  46. global_init(CURL_GLOBAL_ALL);
  47. easy_init(c);
  48. easy_setopt(c, CURLOPT_HEADER, 1L);
  49. easy_setopt(c, CURLOPT_URL, URL);
  50. libtest_debug_config.nohex = 1;
  51. libtest_debug_config.tracetime = 1;
  52. easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config);
  53. easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  54. easy_setopt(c, CURLOPT_VERBOSE, 1L);
  55. multi_init(m);
  56. multi_add_handle(m, c);
  57. while(running) {
  58. struct timeval timeout;
  59. fd_set fdread, fdwrite, fdexcep;
  60. int maxfd = -99;
  61. timeout.tv_sec = 0;
  62. timeout.tv_usec = 100000L; /* 100 ms */
  63. multi_perform(m, &running);
  64. abort_on_test_timeout();
  65. if(!running)
  66. break; /* done */
  67. FD_ZERO(&fdread);
  68. FD_ZERO(&fdwrite);
  69. FD_ZERO(&fdexcep);
  70. multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
  71. /* At this point, maxfd is guaranteed to be greater or equal than -1. */
  72. select_test(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
  73. abort_on_test_timeout();
  74. }
  75. curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
  76. if(connect_time < dbl_epsilon) {
  77. fprintf(stderr, "connect time %e is < epsilon %e\n",
  78. connect_time, dbl_epsilon);
  79. res = TEST_ERR_MAJOR_BAD;
  80. }
  81. test_cleanup:
  82. /* proper cleanup sequence - type PA */
  83. curl_multi_remove_handle(m, c);
  84. curl_multi_cleanup(m);
  85. curl_easy_cleanup(c);
  86. curl_global_cleanup();
  87. return res;
  88. }